1、点击button按钮,选中“属性”中的闪电标志,输入click的动作名字(假如命名为OnClick),

2、双击click处,在弹出的`Form1.cs`中输入以下第三行代码。得到如图结果。
```
private void OnClick(object sender, EventArgs e)
{
MessageBox.Show("确认提交", "应用程序", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
```

3、在app中,默认中 `Program.cs`中的`static void Main()`开始运行。所以如果要更换启动窗口,则可以在该位置更换其他窗口form的名字。

4、需要注意的是,上述动作被记录在`Form1.cs`文件中的
`private void InitializeComponent()`中,不要随意改动。
5、同一个窗体应用中要设置先启动哪一个?:
启动窗体
比如在EMS-windows-app这个应用中,有很多窗体,想先启动“审核登记”。这时候找到 EMS-windows-app 里面的 Program.cs,修改其中的代码, 改成“new 审核登记()”即可:
`Application.Run(new 审核登记( ) );`


# 设置窗体属性

#
5、form 窗体是一个对象,所以在编辑按钮时,需要创建对象。
# 窗体事件

## 父窗体、子窗体
也就是单击打开第二个窗体以后第二个窗体总在第一个窗体内显示
父窗体:`isMdiContainer` 属性为 true 即可。
子窗体:父窗体设置完成后,“属性”中无法直接设置子窗体,需要通过编写代码设置`MdiParent`属性。代码:
```
Form2 frm2 = new Form2();
frm2.Show(); //显示窗体
frm2.MdiParent = this; //注意不要写成midparent
```
## 平铺窗口:
```
layoutMdi( Mdilayout. )
```
arrangelcons =>
cascade =>
titlehorizontal => 水平平铺
titlevertical => 垂直平铺
## button 控件点击后生成新 txt 输入框:
```
private void button1_Click_1(object sender, EventArgs e)//用于点击时生成一个txt框
{
TextBox txt = new TextBox(); //创建对象txt
txt.Location = new Point(0, 0);//初始化坐标位置
this.Controls.Add(txt); // this.Controls指的是button这个控件,触发的事件是add新增
}
```
## TextBox 控件
只读文本、密码、多行

默认只能水平改变大小,这时候把multiline属性设置为 true(多行),即可垂直方向改变大小。
passwordChart属性中,可以将输入的密码显示成**星号。
可以直接拖动创建,也可以写代码:
```
private void button1\_Click(object sender, EventArgs e)
{
TextBox txt = new TextBox();
this.Controls.Add(txt); //this.control的意思是,这个 button 控件中添加。
}
```

## radioButton
单选。一般用 check 属性:

```
private void radioButton_admin_CheckedChanged(object sender, EventArgs e)
{
if(radioButton_admin.Checked)
{
MessageBox.Show ("以管理员身份登录");
}
}
```

## checkBox
复选

## Rich TextBox——超链接
> 如果要设置 richtextbox 控件的字体样式等,可以在 form 窗口的 load 中编写代码。

滚动条、字体属性、超链接、段落格式
### 1、设置字体样式
```
private void 审核意见richTextBox1_TextChanged(object sender, EventArgs e)
{
审核意见richTextBox1.SelectionFont = new Font("宋体", 15, FontStyle.Bold);
审核意见richTextBox1.SelectionColor = Color.Red;
}
```
### 2、设置超链接
在 richtextbox (这个名字是控件的名字)中输入以下代码:
```
richtextbox.Text = "http://www.baidu.com";
```
在转到属性-事件中,找到 LinkClicked,双击,再输入以下代码:
```
System.Diagnostics.Process.Start(e.LinkText); // 该命名空间是系统设置好的
```


## comboBox控件
dropdownStyle属性
selectedValueChanged事件

错误:
若输入`messageBox.Show(comboBox1. selectedItem)`;
参数1:无法从“object”转换为“string”。可直接改成:
`MessageBox.Show("岗位:" + comboBox1.SelectedItem);`
即可。
## listBox

listBox.items.add 属性
listBox.items.remove 属性
selectionMode: one \ multisimple \ multiextended ( 意思是用户可以用 shift 或 control 键盘来选中)
## GroupBox
分组
将“密码、登录、退出”等直接拖动到新建的“系统登录”框中,就变成一个组了。


## listview
列表试图空间。用于显示带图标的项的列表。类似 windows 资源管理器右边窗口的用户界面。

其中smallimagelist、largeimagelist、stageimagelist属性与imageList 组件——图片存储 一起搭配使用。

直接在items里面添加图片即可。
先设置group属性,然后双击 form 窗口,在 load 里面添加代码。

代码如下:将设置好的组件里面的元素进行分类。

## treeview控件
树形结构
### 新建元素

可直接在属性中设置,也可以在 form 窗口的 load 代码区输入:
新建对象
```
private void 审核登记_Load_1(object sender, EventArgs e)
{
TreeNode tr1 = treeView1.Nodes.Add("总工办");
}
```
删除的话,可以用 remove。
### 获取信息:
双击控件,在afterSelect 中输入
```
MessageBox.Show(e.Node.Text); //这里的 e 就是上一行的 e
```

> node其实就是属性中的 Nodes(如图1)。点击后进行Node相关设置,如图2。所以如果将代码中的 Node.Text 换成 Node.Tag,则会显示我们在 Tag 中填入的“备注”(如图3)。
>
>
>
>
>
### 添加图标:
imageList属性设置为 true。然后与imageList组件配合。
## Timer组件
计时器,时间间隔以interval属性定义,以毫秒为单位。

Enabled 与 start 和 stop 互相替换。enable 为 true,就等于 start。



## menustrip

菜单栏。如果要设置“文件”快捷菜单,在属性=>text => “文件(&F)”即可。

## toolstrip
工具栏。默认添加到 menustrip 下面。 可以显示图标和可以显示文字,右击,在 display 选项中进行设置。


## statusStrip
状态栏。

比如添加时间:在 form 窗体的 load 语句中,添加:
```
toolStripStatusLabel1.Text = dateTime.Now.ToString();
```

## 消息框 messagebox
可以通过提示来一步步设置。

## 打开对话框 控件
openFileDialog
指定打开位置:`openFileDialog.InitialDirectory = "C:\\";`
指定文件类型:`openFileDialog.Filter = "文本文件(*.txt)|*.txt|Word文件(*.doc)|*.doc"`
若要所有格式:`openFileDialog.Filter = "所有文件(*.*)|*.*"`


> 最后记得写上 openFile.Dialog.ShowDialog();
## 另存为对话框 控件
saveFileDialog
同上

## 浏览文件夹 控件
foldBrowserDialog

`textBox.Text = folderBrowserDialog1.SelectedPath;`
# 使用右击快捷键功能
添加contextMenustrip 控件,并在 datagridview 的属性中把contextmenustrip控件关联上。
- 帮助文档 microsoft helo viewer
- c#开发环境及visual studio安装注意事项
- c#程序基本结构-基本语法
- Q1: public static void main(String[] args) 是什么意思
- Q2: c#命名空间+Main方法
- Q3:注释+命名规则+代码规则
- Q4: c#语句 system => console
- Q5: 数据类型 .net
- Q5: 常用名字、变量、运算符
- Q6: 对话窗输入-属性
- Q7: 递归
- Q8:决策分支、条件判断语句 if 语句
- Q9:数组
- Q10:字符串
- Q11:对象、类、访问权限、静态动态函数
- Q12:方法及参数——继承于类
- Q13:构造函数
- Q14:继承——base 关键字
- Q15:多态、虚方法、接口
- Q16:创建窗体应用、控件
- Q17:Ado数据访问、连接 sqlserver 数据库
- Q18: 读取数据command + DataRead( )、DataSet + DateAdapter
- Q19: Entity Framwork、entity 与 ADO.net的区别
- Q20: 对话框、文件、文件夹
- Q21: 导入excel数据、更新到 dbo 数据库中
- Q26: 获取 excel 中每个 sheet 的表名
- Q22: 两个窗体之间数据+方法传递
- Q23: 数学对象
- Q24: c#网站编写
- Q25: visual studio2017如何查看帮助
- Q27: c# dictionary 字典对象
- Q28: 数组与dataTable互相转化