1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
| this.ShowInTaskbar = false; <h4>窗口置顶:</h4>
```csharp this.TopMost = true; <h4>更改窗体透明度:</h4>
```csharp this.Opacity = 0.5D;
注意该方法更改窗体透明度后窗体内的空间透明度也会随之改变。 <h4>更改窗口位置:</h4>
```csharp this.Location = new Point(X,Y);
(X,Y)是一个点,单独更改某一个参量也可以用this.Location.Height和this.Location.Weight。 <h4>更改字体/大小:</h4>
```csharp this.Font = new System.Drawing.Font("宋体", 15);```
<h4>更改窗口状态:</h4>
```csharp this.Visible = false; this.WindowState = FormWindowState.Minimized; this.WindowState = FormWindowState.Maximized; this.WindowState = FormWindowState.Normal; </code></pre>
<h1>控件类</h1>
<h2>①实体控件</h2>
<h4>label标签:</h4>
更改字体颜色:
<pre><code class="language-csharp line-numbers">this.label1.ForeColor = Color.FromArgb(211, 210, 199);
<strong>trackbar轨迹条:</strong>
获取,更改当前值:trackbar1.Value <h4><strong>combobox组合框:</strong></h4> <strong>添加组合</strong>:将鼠标移到组合框上单击,选择黑色箭头,选择编辑项<img class="alignnone size-full wp-image-433" src="http://47.94.231.166/wp-content/uploads/2018/08/devenv_2018-08-18_10-23-07.png" alt="" width="990" height="561" />
<strong>选择组合</strong>:添加选项后,编译器将自动生成目录(index),编程时,既可以根据选项值选择,也可以根据目录选择。
根据选项值选择:
```csharp switch (comboBox1.SelectedItem.ToString()) { case "深黑": clock1.label1.ForeColor = Color.FromArgb(1, 1, 1); break; case "纯白": clock1.label1.ForeColor = Color.FromArgb(255, 255, 255); break; case "柔和灰": clock1.label1.ForeColor = Color.FromArgb(211, 210, 199); break; case "荷兰白": clock1.label1.ForeColor = Color.FromArgb(226, 225, 185); break; case "日本靛蓝": clock1.label1.ForeColor = Color.FromArgb(42, 61, 69); break; case "深帝国蓝": clock1.label1.ForeColor = Color.FromArgb(5, 60, 94); break; case "简约蓝": clock1.label1.ForeColor = Color.FromArgb(31, 122, 140); break; case "赭石色": clock1.label1.ForeColor = Color.FromArgb(211, 139, 93); break; }```
按目录选择:
```csharp switch (comboBox1.SelectedIndex) { case 0: clock1.label1.ForeColor = Color.FromArgb(1, 1, 1); break; case 1: clock1.label1.ForeColor = Color.FromArgb(255, 255, 255);break; case 2: clock1.label1.ForeColor = Color.FromArgb(211, 210, 199); break; case 3: clock1.label1.ForeColor = Color.FromArgb(226, 225, 185); break; case 4: clock1.label1.ForeColor = Color.FromArgb(42, 61, 69); break; case 5: clock1.label1.ForeColor = Color.FromArgb(5, 60, 94); break; case 6: clock1.label1.ForeColor = Color.FromArgb(31, 122, 140); break; case 7: clock1.label1.ForeColor = Color.FromArgb(211, 139, 93); break; }``` <h2>②虚拟控件</h2> <h4>timer控件:</h4> timer控件可以按时间触发事件,以毫秒为单位(1s=1000ms)
<strong>建立:</strong>使用时,将工具箱里的timer控件拖入窗体即可,在下方就可以找到该控件,右击属性可以设置间隔时间。
<strong>触发:</strong>在动作_Tick中可直接设置间隔时间到时出发的动作
```csharp public void timer1_Tick(object sender, EventArgs e) { label1.Text = DateTime.Now.Hour + ":" + DateTime.Now.Minute + ":" + DateTime.Now.Second; }```
<strong>notifyIcon状态栏图标控件:</strong>
可以在状态栏创建应用图标,在单击时可出发动作。
<strong>建立:</strong>与timer一样直接拖入即可,但是notifyIcon一定要在属性中设置图标,否则不会再状态栏显示。
<strong>触发:</strong>可设置多种触发方式,如单击双击等,一般触发后代码为还原窗体大小+激活窗体
```csharp
private void notifyIcon1_MouseClick(object sender, MouseEventArgs e) { if (WindowState == FormWindowState.Minimized) { WindowState = FormWindowState.Normal; this.Activate(); } }
|