当前位置:网站首页>C#(二十七)之C#窗体应用
C#(二十七)之C#窗体应用
2022-07-06 03:39:00 【camellias_】
今天开始学习C#窗体。
(一):首先创建一个窗体应用程序
文件->新建->项目
(二):窗体中的按钮和标签(button/label)
点击工具箱,将其固定在屏幕上。
设置按钮及标签属性时,记得修改其NAME属性及Text属性
/**
* 事件的方法
*/
private void MyButton_Click(object sender, EventArgs e)
{
// 对话窗展示
MessageBox.Show("HELLO 我的第一个窗体");
}
/**
* 标签的方法
*/
private void label1_Click(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
// 这个对象的属性等于
answer_label.Text = "答:阴阳八卦,异性相吸";
}
(三):超链接标签(linklabel)
1:Linkcolor:超链接默认状态下的颜色。:
2:Activelinkcolor:超链接单击时候的颜色
3:Visitedlinkcolor:已访问过的超链接的颜色。
4:Linkbehavior:超链接下划线样式
5:事件:
/**
* 超链接事件
*/
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
// 设置点击后的链接颜色
oneLink.LinkVisited = true;
// 打开C盘(@是原样输出)
System.Diagnostics.Process.Start(@"C:/");
}
private void linkLabel1_LinkClicked_1(object sender, LinkLabelLinkClickedEventArgs e)
{
// 设置点击后的链接颜色
linkTwo.LinkVisited = true;
// 打开网页
System.Diagnostics.Process.Start("chrome","https://guanchao.site");
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void linkLabel1_LinkClicked_2(object sender, LinkLabelLinkClickedEventArgs e)
{
// 设置点击后的链接颜色
linkTwo.LinkVisited = true;
// 打开应用
System.Diagnostics.Process.Start("Notepad");
}
(四):文本框(textbox)
1:属性
multiline:控制文本是否可以跨行。
AcceptsReturn:多行编辑控件是否允许输入回车。
AcceptsTab:多行编辑控件是否允许输入Tab键。
ReadOnly:只读
ScrollBars:针对多行控件,是否显示滚动条。
TabIndex:确定次控件应用键盘上的Tab索引
PasswordChar:显示密码字符
AcceptsButton:按回车键等于按确定键(窗体事件)
2:事件
Textchange事件:相当于javascript中的Change事件。
3:方法
Clear:清楚文本框中所有内容
Copy:将选定的内容复制
Cut:将选中的内容剪切
Paste:用剪切的文本替换选中的文本
ResetText:将text属性重新设置为默认值
Redo:重复上一操作
Redo:撤销上一操作
private void but_Click(object sender, EventArgs e)
{
string ques_str = quesBox.Text;
string pass_str = passBox.Text;
if (ques_str == "gc" && pass_str == "123456")
{
MessageBox.Show("操作成功");
}
else {
MessageBox.Show("密码错误");
}
}
(四):单选按钮(RadioButton)
1:属性:
Checked:单选按钮是否已经选中。
C#中的单选按钮的NAME属性不需要相同
// 定义一个变量存储性别
public string sex;
// 选择男,给标签赋值
private void boy_radio_CheckedChanged(object sender, EventArgs e)
{
sex = "男";
}
// 选择女,给标签赋值
private void gr_radio_CheckedChanged(object sender, EventArgs e)
{
sex = "女";
}
// 点击确认按钮走的事件
private void button1_Click_1(object sender, EventArgs e)
{
if (boy_radio.Checked == false && gr_radio.Checked == false)
{
MessageBox.Show("请选择性别");
}
else {
MessageBox.Show("您的相别是:"+sex);
}
}
(五):复选框(CheckBox)
1:属性:
Checked:复选按钮是否已经选中。
CheckState:组件状态(三种状态);
复选框与单选框类似,这里不做举例,参考单选框。
(六):数字输入框(NumericUpDown)
1:属性
Increment:点击一次后边的加号所增长的数字
MiniMum:输入框最小值
MaxMum:输入框最大值
Value:默认值
2:事件
ValueChanged:默认事件(值改变)
public int num;
private void numericUpDown1_ValueChanged(object sender, EventArgs e)
{
num = Convert.ToInt32(numUpOne.Text);
Font ff = new Font("黑体", num);
label4.Font = ff;
}
private void num_button_Click(object sender, EventArgs e)
{
int nums = num + 1;
MessageBox.Show("您输入的数字是" + nums);
}
(七):群组框(GroupBox)
这个没有什么,就是一个分区作用。
把各部分功能分区放置。
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-iEh41uFh-1655864539618)(https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/8286432aab1e40a78f5d5d874df51090~tplv-k3u1fbpfcp-zoom-1.image#pic_center)]
有好的建议,请在下方输入你的评论
欢迎访问个人博客
https://guanchao.site
欢迎访问小程序:
边栏推荐
- Record the process of reverse task manager
- Teach you to build your own simple BP neural network with pytoch (take iris data set as an example)
- MPLS experiment
- Schnuka: visual positioning system working principle of visual positioning system
- 1. New project
- Overview of super-resolution reconstruction of remote sensing images
- Lua uses require to load the shared library successfully, but the return is Boolean (always true)
- [Qt5] QT QWidget immediately appears and disappears
- MADDPG的pythorch实现——(1)OpenAI MADDPG环境配置
- [optimization model] Monte Carlo method of optimization calculation
猜你喜欢
Exness foreign exchange: the governor of the Bank of Canada said that the interest rate hike would be more moderate, and the United States and Canada fell slightly to maintain range volatility
An article will give you a comprehensive understanding of the internal and external components of "computer"
2.1 rtthread pin设备详解
Tidb ecological tools (backup, migration, import / export) collation
[slam] orb-slam3 parsing - track () (3)
Blue style mall website footer code
Four logs of MySQL server layer
Schnuka: 3D vision detection application industry machine vision 3D detection
Python implementation of maddpg - (1) openai maddpg environment configuration
2.2 STM32 GPIO操作
随机推荐
Svg drag point crop image JS effect
2. GPIO related operations
【Rust 笔记】18-宏
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
Tomb. Weekly update of Finance (February 7 - February 13)
Schnuka: what is visual positioning system and how to position it
Quartz misfire missed and compensated execution
Multi project programming minimalist use case
Differential GPS RTK thousand search
BUAA magpie nesting
Explore pointers and pointer types in depth
Brush questions in summer -day3
Edcircles: a real time circle detector with a false detection control translation
Teach you to build your own simple BP neural network with pytoch (take iris data set as an example)
mysql从一个连续时间段的表中读取缺少数据
多项目编程极简用例
Flask learning and project practice 8: introduction and use of cookies and sessions
Suggestions for new engineer team members
教你用Pytorch搭建一个自己的简单的BP神经网络( 以iris数据集为例 )
SAP ALV颜色代码对应颜色(整理)