看看代码先
1
public
partial
class
Demo3 : Form
2 {
3 private System.ComponentModel.IContainer components = null ;
4 protected override void Dispose ( bool disposing)
5 {
6 if (disposing && (components != null ))
7 {
8 components.Dispose ();
9 }
10 base .Dispose (disposing);
11 }
12 private void InitializeComponent ()
13 {
14 this .SuspendLayout ();
15 this .AutoScaleDimensions = new System.Drawing.SizeF (7F, 12F);
16 this .AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
17 this .BackColor = System.Drawing.Color.SkyBlue;
18 this .BackgroundImage = global ::CustomControl.Properties.Resources.test01;
19 this .ClientSize = new System.Drawing.Size ( 583 , 500 );
20 this .Font = new System.Drawing.Font ( " 宋体 " , 9F, ((System.Drawing.FontStyle)(((System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic)
21 | System.Drawing.FontStyle.Underline))), System.Drawing.GraphicsUnit.Point, (( byte )( 134 )));
22 this .ForeColor = System.Drawing.Color.Red;
23 this .FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
24 this .Name = " Demo3 " ;
25 this .Opacity = 0.8 ;
26 this .Text = " Demo3 " ;
27 this .MouseUp += new System.Windows.Forms.MouseEventHandler ( this .Demo3_MouseUp);
28 this .MouseDown += new System.Windows.Forms.MouseEventHandler ( this .Demo3_MouseDown);
29 this .MouseMove += new System.Windows.Forms.MouseEventHandler ( this .Demo3_MouseMove);
30 this .ResumeLayout ( false );
31
32 }
33
34
35 public Demo3 ()
36 {
37 InitializeComponent ();
38 this .Height = 500 ;
39 this .Width = 500 ;
40 this .Region = new Region (GetRoundRectPath( 0 , 0 , this .Width / 4 , this .Width));
41 }
42
43 /// <summary>
44 /// 得到一个环形路径
45 /// </summary>
46 /// <param name="x"> 外圆外切正方形的左上角位置top </param>
47 /// <param name="y"> 外圆外切正方形的左上角位置left </param>
48 /// <param name="outDiameter"> 外圆直径 </param>
49 /// <param name="inDiameter"> 内圆直径 </param>
50 /// <returns></returns>
51 public GraphicsPath GetRoundRectPath ( float x, float y, int outDiameter, int inDiameter)
52 {
53 if (outDiameter < inDiameter)
54 {
55 outDiameter = outDiameter ^ inDiameter;
56 inDiameter = outDiameter ^ inDiameter;
57 outDiameter = outDiameter ^ inDiameter;
58 // A=A+B;B=A-B;A=A-B; // 交换方法1
59 // A=A^B;B=A^B;A=A^B; // 交换方法2
60 }
61
62 // 添加一个圆
63 GraphicsPath path1 = new GraphicsPath ();
64
65 path1.AddEllipse (x, y, outDiameter, outDiameter);
66
67 GraphicsPath path2 = new GraphicsPath ();
68 path2.AddEllipse (x + (outDiameter - inDiameter) / 2 , x + (outDiameter - inDiameter) / 2 , inDiameter, inDiameter);
69
70 path1.AddPath (path2, true );
71
72 path1.AddString ( " 无码高清版 " , new FontFamily ( " Arial " ), ( int )FontStyle.Bold, 26 , new Point ( 170 , 100 ), StringFormat.GenericDefault);
73 path1.AddString ( " GGYY影视公司 " , new FontFamily ( " Arial " ), ( int )FontStyle.Underline, 26 , new Point ( 160 , 400 ), StringFormat.GenericDefault);
74
75 return path1;
76 }
77 // 记录鼠标指针的坐标
78 private Point mouseOffset;
79 // 记录鼠标按键是否按下
80 private bool isMouseDown = false ;
81
82 private void Demo3_MouseDown ( object sender, MouseEventArgs e)
83 {
84 int xOffset;
85 int yOffset;
86 if (e.Button == MouseButtons.Left)
87 {
88 if ( this .FormBorderStyle == System.Windows.Forms.FormBorderStyle.None)
89 {
90 xOffset = - e.X ;
91 yOffset = - e.Y;
92 }
93 else
94 {
95 xOffset = - e.X - SystemInformation.FrameBorderSize.Width;
96 yOffset = - e.Y - SystemInformation.CaptionHeight - SystemInformation.FrameBorderSize.Height;
97 }
98 mouseOffset = new Point (xOffset, yOffset);
99 isMouseDown = true ;
100 }
101 }
102
103 private void Demo3_MouseMove ( object sender, MouseEventArgs e)
104 {
105 if (isMouseDown)
106 {
107 Point mousePos = Control.MousePosition;
108 mousePos.Offset (mouseOffset.X, mouseOffset.Y);
109 Location = mousePos;
110 }
111 }
112
113 private void Demo3_MouseUp ( object sender, MouseEventArgs e)
114 {
115 // 修改鼠标状态isMouseDown的值, 确保只有鼠标左键按下并移动时,才移动窗体
116 if (e.Button == MouseButtons.Left)
117 {
118 isMouseDown = false ;
119 }
120 }
121
122 }
2 {
3 private System.ComponentModel.IContainer components = null ;
4 protected override void Dispose ( bool disposing)
5 {
6 if (disposing && (components != null ))
7 {
8 components.Dispose ();
9 }
10 base .Dispose (disposing);
11 }
12 private void InitializeComponent ()
13 {
14 this .SuspendLayout ();
15 this .AutoScaleDimensions = new System.Drawing.SizeF (7F, 12F);
16 this .AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
17 this .BackColor = System.Drawing.Color.SkyBlue;
18 this .BackgroundImage = global ::CustomControl.Properties.Resources.test01;
19 this .ClientSize = new System.Drawing.Size ( 583 , 500 );
20 this .Font = new System.Drawing.Font ( " 宋体 " , 9F, ((System.Drawing.FontStyle)(((System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic)
21 | System.Drawing.FontStyle.Underline))), System.Drawing.GraphicsUnit.Point, (( byte )( 134 )));
22 this .ForeColor = System.Drawing.Color.Red;
23 this .FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
24 this .Name = " Demo3 " ;
25 this .Opacity = 0.8 ;
26 this .Text = " Demo3 " ;
27 this .MouseUp += new System.Windows.Forms.MouseEventHandler ( this .Demo3_MouseUp);
28 this .MouseDown += new System.Windows.Forms.MouseEventHandler ( this .Demo3_MouseDown);
29 this .MouseMove += new System.Windows.Forms.MouseEventHandler ( this .Demo3_MouseMove);
30 this .ResumeLayout ( false );
31
32 }
33
34
35 public Demo3 ()
36 {
37 InitializeComponent ();
38 this .Height = 500 ;
39 this .Width = 500 ;
40 this .Region = new Region (GetRoundRectPath( 0 , 0 , this .Width / 4 , this .Width));
41 }
42
43 /// <summary>
44 /// 得到一个环形路径
45 /// </summary>
46 /// <param name="x"> 外圆外切正方形的左上角位置top </param>
47 /// <param name="y"> 外圆外切正方形的左上角位置left </param>
48 /// <param name="outDiameter"> 外圆直径 </param>
49 /// <param name="inDiameter"> 内圆直径 </param>
50 /// <returns></returns>
51 public GraphicsPath GetRoundRectPath ( float x, float y, int outDiameter, int inDiameter)
52 {
53 if (outDiameter < inDiameter)
54 {
55 outDiameter = outDiameter ^ inDiameter;
56 inDiameter = outDiameter ^ inDiameter;
57 outDiameter = outDiameter ^ inDiameter;
58 // A=A+B;B=A-B;A=A-B; // 交换方法1
59 // A=A^B;B=A^B;A=A^B; // 交换方法2
60 }
61
62 // 添加一个圆
63 GraphicsPath path1 = new GraphicsPath ();
64
65 path1.AddEllipse (x, y, outDiameter, outDiameter);
66
67 GraphicsPath path2 = new GraphicsPath ();
68 path2.AddEllipse (x + (outDiameter - inDiameter) / 2 , x + (outDiameter - inDiameter) / 2 , inDiameter, inDiameter);
69
70 path1.AddPath (path2, true );
71
72 path1.AddString ( " 无码高清版 " , new FontFamily ( " Arial " ), ( int )FontStyle.Bold, 26 , new Point ( 170 , 100 ), StringFormat.GenericDefault);
73 path1.AddString ( " GGYY影视公司 " , new FontFamily ( " Arial " ), ( int )FontStyle.Underline, 26 , new Point ( 160 , 400 ), StringFormat.GenericDefault);
74
75 return path1;
76 }
77 // 记录鼠标指针的坐标
78 private Point mouseOffset;
79 // 记录鼠标按键是否按下
80 private bool isMouseDown = false ;
81
82 private void Demo3_MouseDown ( object sender, MouseEventArgs e)
83 {
84 int xOffset;
85 int yOffset;
86 if (e.Button == MouseButtons.Left)
87 {
88 if ( this .FormBorderStyle == System.Windows.Forms.FormBorderStyle.None)
89 {
90 xOffset = - e.X ;
91 yOffset = - e.Y;
92 }
93 else
94 {
95 xOffset = - e.X - SystemInformation.FrameBorderSize.Width;
96 yOffset = - e.Y - SystemInformation.CaptionHeight - SystemInformation.FrameBorderSize.Height;
97 }
98 mouseOffset = new Point (xOffset, yOffset);
99 isMouseDown = true ;
100 }
101 }
102
103 private void Demo3_MouseMove ( object sender, MouseEventArgs e)
104 {
105 if (isMouseDown)
106 {
107 Point mousePos = Control.MousePosition;
108 mousePos.Offset (mouseOffset.X, mouseOffset.Y);
109 Location = mousePos;
110 }
111 }
112
113 private void Demo3_MouseUp ( object sender, MouseEventArgs e)
114 {
115 // 修改鼠标状态isMouseDown的值, 确保只有鼠标左键按下并移动时,才移动窗体
116 if (e.Button == MouseButtons.Left)
117 {
118 isMouseDown = false ;
119 }
120 }
121
122 }