控件操作小结
1.控件的拖动:
以System.Windows.Forms.Panel控件为例:
声明变量:
Point mouse_offset;
MouseDown事件:
MouseMove事件:
2.控件的隐藏:
(1)关闭按钮(用System.Windows.Forms.Panel控件做按钮,通过panel3,panel7的MouseClick事件来关闭panel1):
由MouseEnter,MouseLeave和MouseClick三个事件完成:
(2)动态隐藏:
以System.Windows.Forms.Panel控件为例:
声明变量:
Point mouse_offset;
MouseDown事件:
1 private void panel1_MouseDown(object sender, MouseEventArgs e)
2 {
3 mouse_offset = new Point(-e.X, -e.Y);
4 }
5
2 {
3 mouse_offset = new Point(-e.X, -e.Y);
4 }
5
MouseMove事件:
1 private void panel1_MouseMove(object sender, MouseEventArgs e)
2 {
3 ((Control)sender).Cursor = Cursors.Arrow;
4 if (e.Button == MouseButtons.Left)
5 {
6 Point mousePos = Control.MousePosition;
7 mousePos.Offset(mouse_offset.X, mouse_offset.Y);
8 ((Control)sender).Location = ((Control)sender).Parent.PointToClient(mousePos);
9 }
10 }
2 {
3 ((Control)sender).Cursor = Cursors.Arrow;
4 if (e.Button == MouseButtons.Left)
5 {
6 Point mousePos = Control.MousePosition;
7 mousePos.Offset(mouse_offset.X, mouse_offset.Y);
8 ((Control)sender).Location = ((Control)sender).Parent.PointToClient(mousePos);
9 }
10 }
2.控件的隐藏:
(1)关闭按钮(用System.Windows.Forms.Panel控件做按钮,通过panel3,panel7的MouseClick事件来关闭panel1):
由MouseEnter,MouseLeave和MouseClick三个事件完成:
1 private void panel3_MouseEnter(object sender, EventArgs e)
2 {
3 this.panel3.BackgroundImage = Image.FromFile("delete1.jpg");
4 }
5
6 private void panel3_MouseLeave(object sender, EventArgs e)
7 {
8 this.panel3.BackgroundImage = Image.FromFile("delete.jpg");
9 }
10
11 private void panel3_MouseClick(object sender, MouseEventArgs e)
12 {
13 this.panel1.Hide();
14 this.panel7.BackgroundImage = Image.FromFile("cameracontroldown.jpg");
15 }
2 {
3 this.panel3.BackgroundImage = Image.FromFile("delete1.jpg");
4 }
5
6 private void panel3_MouseLeave(object sender, EventArgs e)
7 {
8 this.panel3.BackgroundImage = Image.FromFile("delete.jpg");
9 }
10
11 private void panel3_MouseClick(object sender, MouseEventArgs e)
12 {
13 this.panel1.Hide();
14 this.panel7.BackgroundImage = Image.FromFile("cameracontroldown.jpg");
15 }
1 private void panel7_MouseClick(object sender, MouseEventArgs e)
2 {
3 if (this.panel1.Visible == true)
4 {
5 this.panel1.Hide();
6 this.panel7.BackgroundImage = Image.FromFile("cameracontroldown.jpg");
7 }
8 else
9 {
10 this.panel1.Show();
11 this.panel7.BackgroundImage = Image.FromFile("cameracontrolup.jpg");
12 }
13 }
14
2 {
3 if (this.panel1.Visible == true)
4 {
5 this.panel1.Hide();
6 this.panel7.BackgroundImage = Image.FromFile("cameracontroldown.jpg");
7 }
8 else
9 {
10 this.panel1.Show();
11 this.panel7.BackgroundImage = Image.FromFile("cameracontrolup.jpg");
12 }
13 }
14
(2)动态隐藏:
1 private void treemaphide()
2 {
3
4 while (this.TempPoint.Y < treehight)
5 {
6 System.Threading.Thread.Sleep(10);
7 TempPoint.Y = this.controlPanel.Location.Y + 80;
8 TempPoint.X = this.controlPanel.Location.X;
9 this.controlPanel.Location = TempPoint;
10
11 TempPoint1 = this.panel2.Location;
12 TempPoint1.Y = TempPoint1.Y +80;
13 this.panel2.Location = TempPoint1;
14
15
16 }
17 this.controlPanel.Hide();
18 this.panel2.Hide();
19 }
20
21 private void treemapshow()
22 {
23 this.controlPanel.Show();
24 this.panel2.Show();
25 while (this.TempPoint.Y > 58+80)
26 {
27 System.Threading.Thread.Sleep(10);
28 TempPoint.Y = this.controlPanel.Location.Y - 80;
29 TempPoint.X = this.controlPanel.Location.X;
30 this.controlPanel.Location = TempPoint;
31
32 TempPoint1 = this.panel2.Location;
33 TempPoint1.Y = TempPoint1.Y - 80;
34 this.panel2.Location = TempPoint1;
35
36 }
37 this.TempPoint.Y = 58;
38 this.controlPanel.Location = this.TempPoint;
39 this.TempPoint1.Y = 42;
40 this.panel2.Location = this.TempPoint1;
41 }
2 {
3
4 while (this.TempPoint.Y < treehight)
5 {
6 System.Threading.Thread.Sleep(10);
7 TempPoint.Y = this.controlPanel.Location.Y + 80;
8 TempPoint.X = this.controlPanel.Location.X;
9 this.controlPanel.Location = TempPoint;
10
11 TempPoint1 = this.panel2.Location;
12 TempPoint1.Y = TempPoint1.Y +80;
13 this.panel2.Location = TempPoint1;
14
15
16 }
17 this.controlPanel.Hide();
18 this.panel2.Hide();
19 }
20
21 private void treemapshow()
22 {
23 this.controlPanel.Show();
24 this.panel2.Show();
25 while (this.TempPoint.Y > 58+80)
26 {
27 System.Threading.Thread.Sleep(10);
28 TempPoint.Y = this.controlPanel.Location.Y - 80;
29 TempPoint.X = this.controlPanel.Location.X;
30 this.controlPanel.Location = TempPoint;
31
32 TempPoint1 = this.panel2.Location;
33 TempPoint1.Y = TempPoint1.Y - 80;
34 this.panel2.Location = TempPoint1;
35
36 }
37 this.TempPoint.Y = 58;
38 this.controlPanel.Location = this.TempPoint;
39 this.TempPoint1.Y = 42;
40 this.panel2.Location = this.TempPoint1;
41 }
1 private void panel6_MouseClick(object sender, MouseEventArgs e)
2 {
3
4 if (this.controlPanel.Visible == true)
5 {
6
7 treemaphide();
8 this.panel6.BackgroundImage = Image.FromFile("stationtreedown.jpg");
9
10 }
11 else
12 {
13
14 treemapshow();
15 this.panel6.BackgroundImage = Image.FromFile("stationtreeup.jpg");
16
17 }
18 }
2 {
3
4 if (this.controlPanel.Visible == true)
5 {
6
7 treemaphide();
8 this.panel6.BackgroundImage = Image.FromFile("stationtreedown.jpg");
9
10 }
11 else
12 {
13
14 treemapshow();
15 this.panel6.BackgroundImage = Image.FromFile("stationtreeup.jpg");
16
17 }
18 }
浙公网安备 33010602011771号