WinForm磁性窗体的设计

 

FrmClass.cs

View Code
  1 using System;
2 using System.Collections.Generic;
3 using System.Text;
4 using System.Windows.Forms;//添加控件及窗体的命名空间
5 using System.Drawing;//添加Point的命名空间
6 using System.Collections;//为ArrayList添加命名空间
7
8 namespace MagnetismForm
9 {
10 class FrmClass
11 {
12 #region 磁性窗体-公共变量
13 //记录窗体的隐藏与显示
14 public static bool Example_ListShow = false;
15 public static bool Example_LibrettoShow = false;
16 public static bool Example_ScreenShow = false;
17
18 //记录鼠标的当前位置
19 public static Point CPoint; //添加命名空间using System.Drawing;
20 public static Point FrmPoint;
21 public static int Example_FSpace = 10;//设置窗体间的距离
22
23 //Frm_Play窗体的位置及大小
24 public static int Example_Play_Top = 0;
25 public static int Example_Play_Left = 0;
26 public static int Example_Play_Width = 0;
27 public static int Example_Play_Height = 0;
28 public static bool Example_Assistant_AdhereTo = false;//辅助窗体是否磁性在一起
29
30 //Frm_ListBos窗体的位置及大小
31 public static int Example_List_Top = 0;
32 public static int Example_List_Left = 0;
33 public static int Example_List_Width = 0;
34 public static int Example_List_Height = 0;
35 public static bool Example_List_AdhereTo = false;//辅助窗体是否与主窗体磁性在一起
36
37 //Frm_Libretto窗体的位置及大小
38 public static int Example_Libretto_Top = 0;
39 public static int Example_Libretto_Left = 0;
40 public static int Example_Libretto_Width = 0;
41 public static int Example_Libretto_Height = 0;
42 public static bool Example_Libretto_AdhereTo = false;//辅助窗体是否与主窗体磁性在一起
43
44 //窗体之间的距离差
45 public static int Example_List_space_Top = 0;
46 public static int Example_List_space_Left = 0;
47 public static int Example_Libretto_space_Top = 0;
48 public static int Example_Libretto_space_Left = 0;
49 #endregion
50
51 #region 检测各窗体是否连接在一起
52 /// <summary>
53 /// 检测各窗体是否连接在一起
54 /// </summary>
55 public void FrmBackCheck()
56 {
57 bool Tem_Magnetism = false;
58 //Frm_ListBos与主窗体
59 Tem_Magnetism = false;
60 if ((Example_Play_Top - Example_List_Top) == 0)
61 Tem_Magnetism = true;
62 if ((Example_Play_Left - Example_List_Left) == 0)
63 Tem_Magnetism = true;
64 if ((Example_Play_Left - Example_List_Left - Example_List_Width) == 0)
65 Tem_Magnetism = true;
66 if ((Example_Play_Left - Example_List_Left + Example_List_Width) == 0)
67 Tem_Magnetism = true;
68 if ((Example_Play_Top - Example_List_Top - Example_List_Height) == 0)
69 Tem_Magnetism = true;
70 if ((Example_Play_Top - Example_List_Top + Example_List_Height) == 0)
71 Tem_Magnetism = true;
72 if (Tem_Magnetism)
73 Example_List_AdhereTo = true;
74
75 //Frm_Libretto与主窗体
76 Tem_Magnetism = false;
77 if ((Example_Play_Top - Example_Libretto_Top) == 0)
78 Tem_Magnetism = true;
79 if ((Example_Play_Left - Example_Libretto_Left) == 0)
80 Tem_Magnetism = true;
81 if ((Example_Play_Left - Example_Libretto_Left - Example_Libretto_Width) == 0)
82 Tem_Magnetism = true;
83 if ((Example_Play_Left - Example_Libretto_Left + Example_Libretto_Width) == 0)
84 Tem_Magnetism = true;
85 if ((Example_Play_Top - Example_Libretto_Top - Example_Libretto_Height) == 0)
86 Tem_Magnetism = true;
87 if ((Example_Play_Top - Example_Libretto_Top + Example_Libretto_Height) == 0)
88 Tem_Magnetism = true;
89 if (Tem_Magnetism)
90 Example_Libretto_AdhereTo = true;
91
92 //两个辅窗体
93 Tem_Magnetism = false;
94 if ((Example_List_Top - Example_Libretto_Top) == 0)
95 Tem_Magnetism = true;
96 if ((Example_List_Left - Example_Libretto_Left) == 0)
97 Tem_Magnetism = true;
98 if ((Example_List_Left - Example_Libretto_Left - Example_Libretto_Width) == 0)
99 Tem_Magnetism = true;
100 if ((Example_List_Left - Example_Libretto_Left + Example_Libretto_Width) == 0)
101 Tem_Magnetism = true;
102 if ((Example_List_Top - Example_Libretto_Top - Example_Libretto_Height) == 0)
103 Tem_Magnetism = true;
104 if ((Example_List_Top - Example_Libretto_Top + Example_Libretto_Height) == 0)
105 Tem_Magnetism = true;
106 if (Tem_Magnetism)
107 Example_Assistant_AdhereTo = true;
108 }
109 #endregion
110
111 #region 利用窗体上的控件移动窗体
112 /// <summary>
113 /// 利用控件移动窗体
114 /// </summary>
115 /// <param Frm="Form">窗体</param>
116 /// <param e="MouseEventArgs">控件的移动事件</param>
117 public void FrmMove(Form Frm, MouseEventArgs e) //Form或MouseEventArgs添加命名空间using System.Windows.Forms;
118 {
119 if (e.Button == MouseButtons.Left)
120 {
121 Point myPosittion = Control.MousePosition;//获取当前鼠标的屏幕坐标
122 myPosittion.Offset(CPoint.X, CPoint.Y);//重载当前鼠标的位置
123 Frm.DesktopLocation = myPosittion;//设置当前窗体在屏幕上的位置
124 }
125 }
126 #endregion
127
128 #region 计算窗体之间的距离差
129 /// <summary>
130 /// 计算窗体之间的距离差
131 /// </summary>
132 /// <param Frm="Form">窗体</param>
133 /// <param Follow="Form">跟随窗体</param>
134 public void FrmDistanceJob(Form Frm, Form Follow)
135 {
136 switch (Follow.Name)
137 {
138 case "Frm_ListBox":
139 {
140 Example_List_space_Top = Follow.Top - Frm.Top;
141 Example_List_space_Left = Follow.Left - Frm.Left;
142 break;
143 }
144 case "Frm_Libretto":
145 {
146 Example_Libretto_space_Top = Follow.Top - Frm.Top;
147 Example_Libretto_space_Left = Follow.Left - Frm.Left;
148 break;
149 }
150 }
151 }
152 #endregion
153
154 #region 磁性窗体的移动
155 /// <summary>
156 /// 磁性窗体的移动
157 /// </summary>
158 /// <param Frm="Form">窗体</param>
159 /// <param e="MouseEventArgs">控件的移动事件</param>
160 /// <param Follow="Form">跟随窗体</param>
161 public void ManyFrmMove(Form Frm, MouseEventArgs e, Form Follow) //Form或MouseEventArgs添加命名空间using System.Windows.Forms;
162 {
163 if (e.Button == MouseButtons.Left)
164 {
165 int Tem_Left = 0;
166 int Tem_Top = 0;
167 Point myPosittion = Control.MousePosition;//获取当前鼠标的屏幕坐标
168 switch (Follow.Name)
169 {
170 case "Frm_ListBox":
171 {
172 Tem_Top = Example_List_space_Top - FrmPoint.Y;
173 Tem_Left = Example_List_space_Left - FrmPoint.X;
174 break;
175 }
176 case "Frm_Libretto":
177 {
178 Tem_Top = Example_Libretto_space_Top - FrmPoint.Y;
179 Tem_Left = Example_Libretto_space_Left - FrmPoint.X;
180 break;
181 }
182 }
183 myPosittion.Offset(Tem_Left, Tem_Top);
184 Follow.DesktopLocation = myPosittion;
185 }
186 }
187 #endregion
188
189 #region 对窗体的位置进行初始化
190 /// <summary>
191 /// 对窗体的位置进行初始化
192 /// </summary>
193 /// <param Frm="Form">窗体</param>
194 public void FrmInitialize(Form Frm)
195 {
196 switch (Frm.Name)
197 {
198 case "Frm_Play":
199 {
200 Example_Play_Top = Frm.Top;
201 Example_Play_Left = Frm.Left;
202 Example_Play_Width = Frm.Width;
203 Example_Play_Height = Frm.Height;
204 break;
205 }
206 case "Frm_ListBox":
207 {
208 Example_List_Top = Frm.Top;
209 Example_List_Left = Frm.Left;
210 Example_List_Width = Frm.Width;
211 Example_List_Height = Frm.Height;
212 break;
213 }
214 case "Frm_Libretto":
215 {
216 Example_Libretto_Top = Frm.Top;
217 Example_Libretto_Left = Frm.Left;
218 Example_Libretto_Width = Frm.Width;
219 Example_Libretto_Height = Frm.Height;
220 break;
221 }
222 }
223
224 }
225 #endregion
226
227 #region 存储各窗体的当前信息
228 /// <summary>
229 /// 存储各窗体的当前信息
230 /// </summary>
231 /// <param Frm="Form">窗体</param>
232 /// <param e="MouseEventArgs">控件的移动事件</param>
233 public void FrmPlace(Form Frm)
234 {
235 FrmInitialize(Frm);
236 FrmMagnetism(Frm);
237 }
238 #endregion
239
240 #region 窗体的磁性设置
241 /// <summary>
242 /// 窗体的磁性设置
243 /// </summary>
244 /// <param Frm="Form">窗体</param>
245 public void FrmMagnetism(Form Frm)
246 {
247 if (Frm.Name != "Frm_Play")
248 {
249 FrmMagnetismCount(Frm, Example_Play_Top, Example_Play_Left, Example_Play_Width, Example_Play_Height, "Frm_Play");
250 }
251 if (Frm.Name != "Frm_ListBos")
252 {
253 FrmMagnetismCount(Frm, Example_List_Top, Example_List_Left, Example_List_Width, Example_List_Height, "Frm_ListBos");
254 }
255 if (Frm.Name != "Frm_Libratto")
256 {
257 FrmMagnetismCount(Frm, Example_Libretto_Top, Example_Libretto_Left, Example_Libretto_Width, Example_Libretto_Height, "Frm_Libratto");
258 }
259 FrmInitialize(Frm);
260 }
261 #endregion
262
263 #region 磁性窗体的计算
264 /// <summary>
265 /// 磁性窗体的计算
266 /// </summary>
267 /// <param Frm="Form">窗体</param>
268 /// <param e="MouseEventArgs">控件的移动事件</param>
269 public void FrmMagnetismCount(Form Frm, int top, int left, int width, int height, string Mforms)
270 {
271 bool Tem_Magnetism = false;//判断是否有磁性发生
272 string Tem_MainForm = "";//临时记录主窗体
273 string Tem_AssistForm = "";//临时记录辅窗体
274
275 //上面进行磁性窗体
276 if ((Frm.Top + Frm.Height - top) <= Example_FSpace && (Frm.Top + Frm.Height - top) >= -Example_FSpace)
277 {
278 //当一个主窗体不包含辅窗体时
279 if ((Frm.Left >= left && Frm.Left <= (left + width)) || ((Frm.Left + Frm.Width) >= left && (Frm.Left + Frm.Width) <= (left + width)))
280 {
281 Frm.Top = top - Frm.Height;
282 if ((Frm.Left - left) <= Example_FSpace && (Frm.Left - left) >= -Example_FSpace)
283 Frm.Left = left;
284 Tem_Magnetism = true;
285 }
286 //当一个主窗体包含辅窗体时
287 if (Frm.Left <= left && (Frm.Left + Frm.Width) >= (left + width))
288 {
289 Frm.Top = top - Frm.Height;
290 if ((Frm.Left - left) <= Example_FSpace && (Frm.Left - left) >= -Example_FSpace)
291 Frm.Left = left;
292 Tem_Magnetism = true;
293 }
294
295 }
296
297 //下面进行磁性窗体
298 if ((Frm.Top - (top + height)) <= Example_FSpace && (Frm.Top - (top + height)) >= -Example_FSpace)
299 {
300 //当一个主窗体不包含辅窗体时
301 if ((Frm.Left >= left && Frm.Left <= (left + width)) || ((Frm.Left + Frm.Width) >= left && (Frm.Left + Frm.Width) <= (left + width)))
302 {
303 Frm.Top = top + height;
304 if ((Frm.Left - left) <= Example_FSpace && (Frm.Left - left) >= -Example_FSpace)
305 Frm.Left = left;
306 Tem_Magnetism = true;
307 }
308 //当一个主窗体包含辅窗体时
309 if (Frm.Left <= left && (Frm.Left + Frm.Width) >= (left + width))
310 {
311 Frm.Top = top + height;
312 if ((Frm.Left - left) <= Example_FSpace && (Frm.Left - left) >= -Example_FSpace)
313 Frm.Left = left;
314 Tem_Magnetism = true;
315 }
316 }
317
318 //左面进行磁性窗体
319 if ((Frm.Left + Frm.Width - left) <= Example_FSpace && (Frm.Left + Frm.Width - left) >= -Example_FSpace)
320 {
321 //当一个主窗体不包含辅窗体时
322 if ((Frm.Top > top && Frm.Top <= (top + height)) || ((Frm.Top + Frm.Height) >= top && (Frm.Top + Frm.Height) <= (top + height)))
323 {
324 Frm.Left = left - Frm.Width;
325 if ((Frm.Top - top) <= Example_FSpace && (Frm.Top - top) >= -Example_FSpace)
326 Frm.Top = top;
327 Tem_Magnetism = true;
328 }
329 //当一个主窗体包含辅窗体时
330 if (Frm.Top <= top && (Frm.Top + Frm.Height) >= (top + height))
331 {
332 Frm.Left = left - Frm.Width;
333 if ((Frm.Top - top) <= Example_FSpace && (Frm.Top - top) >= -Example_FSpace)
334 Frm.Top = top;
335 Tem_Magnetism = true;
336 }
337 }
338
339 //右面进行磁性窗体
340 if ((Frm.Left - (left + width)) <= Example_FSpace && (Frm.Left - (left + width)) >= -Example_FSpace)
341 {
342 //当一个主窗体不包含辅窗体时
343 if ((Frm.Top > top && Frm.Top <= (top + height)) || ((Frm.Top + Frm.Height) >= top && (Frm.Top + Frm.Height) <= (top + height)))
344 {
345 Frm.Left = left + width;
346 if ((Frm.Top - top) <= Example_FSpace && (Frm.Top - top) >= -Example_FSpace)
347 Frm.Top = top;
348 Tem_Magnetism = true;
349 }
350 //当一个主窗体包含辅窗体时
351 if (Frm.Top <= top && (Frm.Top + Frm.Height) >= (top + height))
352 {
353 Frm.Left = left + width;
354 if ((Frm.Top - top) <= Example_FSpace && (Frm.Top - top) >= -Example_FSpace)
355 Frm.Top = top;
356 Tem_Magnetism = true;
357 }
358 }
359 if (Frm.Name == "Frm_Play")
360 Tem_MainForm = "Frm_Play";
361 else
362 Tem_AssistForm = Frm.Name;
363 if (Mforms == "Frm_Play")
364 Tem_MainForm = "Frm_Play";
365 else
366 Tem_AssistForm = Mforms;
367 if (Tem_MainForm == "")
368 {
369 Example_Assistant_AdhereTo = Tem_Magnetism;
370 }
371 else
372 {
373 switch (Tem_AssistForm)
374 {
375 case "Frm_ListBos":
376 Example_List_AdhereTo = Tem_Magnetism;
377 break;
378 case "Frm_Libratto":
379 Example_Libretto_AdhereTo = Tem_Magnetism;
380 break;
381 }
382 }
383 }
384 #endregion
385
386 #region 恢复窗体的初始大小
387 /// <summary>
388 /// 恢复窗体的初始大小(当松开鼠标时,如果窗体的大小小于300*200,恢复初始状态)
389 /// </summary>
390 /// <param Frm="Form">窗体</param>
391 public void FrmScreen_FormerlySize(Form Frm, int PWidth, int PHeight)
392 {
393 if (Frm.Width < PWidth || Frm.Height < PHeight)
394 {
395 Frm.Width = PWidth;
396 Frm.Height = PHeight;
397 //Example_Size = false;
398 }
399 }
400 #endregion
401
402 }
403 }

Frm_Play.cs

View Code
  1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Drawing;
6 using System.Linq;
7 using System.Text;
8 using System.Windows.Forms;
9
10 namespace MagnetismForm
11 {
12 public partial class Frm_Play : Form
13 {
14 public Frm_Play()
15 {
16 InitializeComponent();
17 }
18
19 #region 公共变量
20 FrmClass Cla_FrmClass = new FrmClass();
21 public static Form F_List = new Form();
22 public static Form F_Libretto = new Form();
23 public static Form F_Screen = new Form();
24 #endregion
25
26 private void Frm_Play_Load(object sender, EventArgs e)
27 {
28 //窗体位置的初始化
29 Cla_FrmClass.FrmInitialize(this);
30 }
31
32 private void panel_Title_MouseDown(object sender, MouseEventArgs e)
33 {
34
35 int Tem_Y = 0;
36 if (e.Button == MouseButtons.Left)//按下的是否为鼠标左键
37 {
38 Cla_FrmClass.FrmBackCheck();//检测各窗体是否连在一起
39 Tem_Y = e.Y;
40 FrmClass.FrmPoint = new Point(e.X, Tem_Y);//获取鼠标在窗体上的位置,用于磁性窗体
41 FrmClass.CPoint = new Point(-e.X, -Tem_Y);//获取鼠标在屏幕上的位置,用于窗体的移动
42 if (FrmClass.Example_List_AdhereTo)//如果与frm_ListBox窗体相连接
43 {
44 Cla_FrmClass.FrmDistanceJob(this, F_List);//计算窗体的距离差
45 if (FrmClass.Example_Assistant_AdhereTo)//两个辅窗体是否连接在一起
46 {
47 Cla_FrmClass.FrmDistanceJob(this, F_Libretto);//计算窗体的距离差
48 }
49 }
50 if (FrmClass.Example_Libretto_AdhereTo)//如果与frm_Libretto窗体相连接
51 {
52 Cla_FrmClass.FrmDistanceJob(this, F_Libretto);//计算窗体的距离差
53 if (FrmClass.Example_Assistant_AdhereTo)//两个辅窗体是否连接在一起
54 {
55 Cla_FrmClass.FrmDistanceJob(this, F_List);//计算窗体的距离差
56 }
57 }
58 }
59
60 }
61
62 private void panel_Title_MouseMove(object sender, MouseEventArgs e)
63 {
64 if (e.Button == MouseButtons.Left)//按下的是否为鼠标左键
65 {
66
67 Cla_FrmClass.FrmMove(this, e);//利用控件移动窗体
68 if (FrmClass.Example_List_AdhereTo)//如果frm_ListBox窗体与主窗体连接
69 {
70
71 Cla_FrmClass.ManyFrmMove(this, e, F_List);//磁性窗体的移动
72 Cla_FrmClass.FrmInitialize(F_List);//对frm_ListBox窗体的位置进行初始化
73 if (FrmClass.Example_Assistant_AdhereTo)//如果两个子窗体连接在一起
74 {
75 Cla_FrmClass.ManyFrmMove(this, e, F_Libretto);
76 Cla_FrmClass.FrmInitialize(F_Libretto);
77 }
78 }
79
80 if (FrmClass.Example_Libretto_AdhereTo)//如果frm_Libretto窗体与主窗体连接
81 {
82 Cla_FrmClass.ManyFrmMove(this, e, F_Libretto);
83 Cla_FrmClass.FrmInitialize(F_Libretto);
84 if (FrmClass.Example_Assistant_AdhereTo)
85 {
86 Cla_FrmClass.ManyFrmMove(this, e, F_List);
87 Cla_FrmClass.FrmInitialize(F_List);
88 }
89 }
90 Cla_FrmClass.FrmInitialize(this);
91 }
92 }
93
94 private void panel_Title_MouseUp(object sender, MouseEventArgs e)
95 {
96 Cla_FrmClass.FrmPlace(this);
97 }
98
99 private void Frm_Play_Shown(object sender, EventArgs e)
100 {
101 //显示列表窗体
102 F_List = new Frm_ListBox();
103 F_List.ShowInTaskbar = false;
104 FrmClass.Example_ListShow = true;
105 F_List.Show();
106 //显示歌词窗体
107 F_Libretto = new Frm_Libretto();
108 F_Libretto.ShowInTaskbar = false;
109 FrmClass.Example_LibrettoShow = true;
110 F_Libretto.Show();
111 F_Libretto.Left = this.Left + this.Width;
112 F_Libretto.Top = this.Top;
113 //各窗体位置的初始化
114 Cla_FrmClass.FrmInitialize(F_List);
115 Cla_FrmClass.FrmInitialize(F_Libretto);
116 }
117
118 private void panel_Close_Click(object sender, EventArgs e)
119 {
120 F_List.Close();
121 F_List.Dispose();
122 F_Libretto.Close();
123 F_Libretto.Dispose();
124 F_Screen.Close();
125 F_Screen.Dispose();
126 this.Close();
127 }
128
129 private void panel_Title_Click(object sender, EventArgs e)
130 {
131 F_List.Focus();
132 F_Libretto.Focus();
133 this.Focus();
134
135 }
136
137 }
138 }

Frm_Play.designer.cs

View Code
 1 namespace MagnetismForm
2 {
3 partial class Frm_Play
4 {
5 /// <summary>
6 /// 必需的设计器变量。
7 /// </summary>
8 private System.ComponentModel.IContainer components = null;
9
10 /// <summary>
11 /// 清理所有正在使用的资源。
12 /// </summary>
13 /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
14 protected override void Dispose(bool disposing)
15 {
16 if (disposing && (components != null))
17 {
18 components.Dispose();
19 }
20 base.Dispose(disposing);
21 }
22
23 #region Windows 窗体设计器生成的代码
24
25 /// <summary>
26 /// 设计器支持所需的方法 - 不要
27 /// 使用代码编辑器修改此方法的内容。
28 /// </summary>
29 private void InitializeComponent()
30 {
31 this.panel_Title = new System.Windows.Forms.Panel();
32 this.panel_Close = new System.Windows.Forms.Panel();
33 this.pictureBox1 = new System.Windows.Forms.PictureBox();
34 this.panel_Title.SuspendLayout();
35 ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
36 this.SuspendLayout();
37 //
38 // panel_Title
39 //
40 this.panel_Title.BackColor = System.Drawing.Color.MediumBlue;
41 this.panel_Title.BackgroundImage = global::MagnetismForm.Properties.Resources._1;
42 this.panel_Title.Controls.Add(this.panel_Close);
43 this.panel_Title.Dock = System.Windows.Forms.DockStyle.Top;
44 this.panel_Title.Location = new System.Drawing.Point(0, 0);
45 this.panel_Title.Name = "panel_Title";
46 this.panel_Title.Size = new System.Drawing.Size(290, 31);
47 this.panel_Title.TabIndex = 0;
48 this.panel_Title.MouseMove += new System.Windows.Forms.MouseEventHandler(this.panel_Title_MouseMove);
49 this.panel_Title.Click += new System.EventHandler(this.panel_Title_Click);
50 this.panel_Title.MouseDown += new System.Windows.Forms.MouseEventHandler(this.panel_Title_MouseDown);
51 this.panel_Title.MouseUp += new System.Windows.Forms.MouseEventHandler(this.panel_Title_MouseUp);
52 //
53 // panel_Close
54 //
55 this.panel_Close.BackColor = System.Drawing.Color.Red;
56 this.panel_Close.BackgroundImage = global::MagnetismForm.Properties.Resources.Close;
57 this.panel_Close.Location = new System.Drawing.Point(270, 5);
58 this.panel_Close.Name = "panel_Close";
59 this.panel_Close.Size = new System.Drawing.Size(18, 18);
60 this.panel_Close.TabIndex = 0;
61 this.panel_Close.Click += new System.EventHandler(this.panel_Close_Click);
62 //
63 // pictureBox1
64 //
65 this.pictureBox1.Image = global::MagnetismForm.Properties.Resources._4;
66 this.pictureBox1.Location = new System.Drawing.Point(0, 31);
67 this.pictureBox1.Name = "pictureBox1";
68 this.pictureBox1.Size = new System.Drawing.Size(290, 89);
69 this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
70 this.pictureBox1.TabIndex = 1;
71 this.pictureBox1.TabStop = false;
72 //
73 // Frm_Play
74 //
75 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
76 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
77 this.ClientSize = new System.Drawing.Size(290, 120);
78 this.Controls.Add(this.pictureBox1);
79 this.Controls.Add(this.panel_Title);
80 this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
81 this.Name = "Frm_Play";
82 this.Text = "主窗体";
83 this.Load += new System.EventHandler(this.Frm_Play_Load);
84 this.Shown += new System.EventHandler(this.Frm_Play_Shown);
85 this.panel_Title.ResumeLayout(false);
86 ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
87 this.ResumeLayout(false);
88
89 }
90
91 #endregion
92
93 private System.Windows.Forms.Panel panel_Title;
94 private System.Windows.Forms.Panel panel_Close;
95 private System.Windows.Forms.PictureBox pictureBox1;
96 }
97 }

Frm_ListBox.cs

View Code
 1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Drawing;
6 using System.Linq;
7 using System.Text;
8 using System.Windows.Forms;
9
10 namespace MagnetismForm
11 {
12 public partial class Frm_ListBox : Form
13 {
14 public Frm_ListBox()
15 {
16 InitializeComponent();
17 }
18
19 #region 公共变量
20 FrmClass Cla_FrmClass = new FrmClass();
21 #endregion
22
23 private void Frm_ListBox_Load(object sender, EventArgs e)
24 {
25 this.Left = FrmClass.Example_Play_Left;
26 this.Top = FrmClass.Example_Play_Top + FrmClass.Example_Play_Height;
27 Cla_FrmClass.FrmInitialize(this);
28 }
29
30 private void panel_Title_MouseDown(object sender, MouseEventArgs e)
31 {
32 FrmClass.CPoint = new Point(-e.X, -e.Y);
33 }
34
35 private void panel_Title_MouseMove(object sender, MouseEventArgs e)
36 {
37 FrmClass.Example_Assistant_AdhereTo = false;
38 FrmClass.Example_List_AdhereTo = false;
39 Cla_FrmClass.FrmMove(this, e);
40 }
41
42 private void panel_Title_MouseUp(object sender, MouseEventArgs e)
43 {
44 Cla_FrmClass.FrmPlace(this);
45 }
46 }
47 }

Frm_ListBox.designer.cs

View Code
 1 namespace MagnetismForm
2 {
3 partial class Frm_ListBox
4 {
5 /// <summary>
6 /// Required designer variable.
7 /// </summary>
8 private System.ComponentModel.IContainer components = null;
9
10 /// <summary>
11 /// Clean up any resources being used.
12 /// </summary>
13 /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
14 protected override void Dispose(bool disposing)
15 {
16 if (disposing && (components != null))
17 {
18 components.Dispose();
19 }
20 base.Dispose(disposing);
21 }
22
23 #region Windows Form Designer generated code
24
25 /// <summary>
26 /// Required method for Designer support - do not modify
27 /// the contents of this method with the code editor.
28 /// </summary>
29 private void InitializeComponent()
30 {
31 this.pictureBox1 = new System.Windows.Forms.PictureBox();
32 this.panel_Title = new System.Windows.Forms.Panel();
33 ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
34 this.SuspendLayout();
35 //
36 // pictureBox1
37 //
38 this.pictureBox1.Image = global::MagnetismForm.Properties.Resources._4;
39 this.pictureBox1.Location = new System.Drawing.Point(0, 31);
40 this.pictureBox1.Name = "pictureBox1";
41 this.pictureBox1.Size = new System.Drawing.Size(290, 89);
42 this.pictureBox1.TabIndex = 1;
43 this.pictureBox1.TabStop = false;
44 //
45 // panel_Title
46 //
47 this.panel_Title.BackColor = System.Drawing.Color.MediumBlue;
48 this.panel_Title.BackgroundImage = global::MagnetismForm.Properties.Resources._5;
49 this.panel_Title.Dock = System.Windows.Forms.DockStyle.Top;
50 this.panel_Title.Location = new System.Drawing.Point(0, 0);
51 this.panel_Title.Name = "panel_Title";
52 this.panel_Title.Size = new System.Drawing.Size(290, 31);
53 this.panel_Title.TabIndex = 0;
54 this.panel_Title.MouseMove += new System.Windows.Forms.MouseEventHandler(this.panel_Title_MouseMove);
55 this.panel_Title.MouseDown += new System.Windows.Forms.MouseEventHandler(this.panel_Title_MouseDown);
56 this.panel_Title.MouseUp += new System.Windows.Forms.MouseEventHandler(this.panel_Title_MouseUp);
57 //
58 // Frm_ListBox
59 //
60 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
61 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
62 this.ClientSize = new System.Drawing.Size(290, 120);
63 this.Controls.Add(this.pictureBox1);
64 this.Controls.Add(this.panel_Title);
65 this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
66 this.Name = "Frm_ListBox";
67 this.Text = "辅窗体1";
68 this.Load += new System.EventHandler(this.Frm_ListBox_Load);
69 ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
70 this.ResumeLayout(false);
71
72 }
73
74 #endregion
75
76 private System.Windows.Forms.Panel panel_Title;
77 private System.Windows.Forms.PictureBox pictureBox1;
78 }
79 }

Frm_Libretto.cs

View Code
 1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Drawing;
6 using System.Linq;
7 using System.Text;
8 using System.Windows.Forms;
9
10 namespace MagnetismForm
11 {
12 public partial class Frm_Libretto : Form
13 {
14 public Frm_Libretto()
15 {
16 InitializeComponent();
17 }
18
19 #region 公共变量
20 FrmClass Cla_FrmClass = new FrmClass();
21 #endregion
22
23 private void Frm_Libretto_Load(object sender, EventArgs e)
24 {
25 this.Top = FrmClass.Example_Play_Top;
26 this.Left = FrmClass.Example_Play_Left + FrmClass.Example_Play_Width;
27 Cla_FrmClass.FrmInitialize(this);
28 }
29
30 private void panel_Title_MouseDown(object sender, MouseEventArgs e)
31 {
32 FrmClass.CPoint = new Point(-e.X, -e.Y);
33 }
34
35 private void panel_Title_MouseMove(object sender, MouseEventArgs e)
36 {
37 FrmClass.Example_Assistant_AdhereTo = false;
38 FrmClass.Example_Libretto_AdhereTo = false;
39 Cla_FrmClass.FrmMove(this, e);
40 }
41
42 private void panel_Title_MouseUp(object sender, MouseEventArgs e)
43 {
44 Cla_FrmClass.FrmPlace(this);
45 }
46 }
47 }

Frm_Libretto.designer.cs

View Code
 1 namespace MagnetismForm
2 {
3 partial class Frm_Libretto
4 {
5 /// <summary>
6 /// Required designer variable.
7 /// </summary>
8 private System.ComponentModel.IContainer components = null;
9
10 /// <summary>
11 /// Clean up any resources being used.
12 /// </summary>
13 /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
14 protected override void Dispose(bool disposing)
15 {
16 if (disposing && (components != null))
17 {
18 components.Dispose();
19 }
20 base.Dispose(disposing);
21 }
22
23 #region Windows Form Designer generated code
24
25 /// <summary>
26 /// Required method for Designer support - do not modify
27 /// the contents of this method with the code editor.
28 /// </summary>
29 private void InitializeComponent()
30 {
31 this.pictureBox1 = new System.Windows.Forms.PictureBox();
32 this.panel_Title = new System.Windows.Forms.Panel();
33 ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
34 this.SuspendLayout();
35 //
36 // pictureBox1
37 //
38 this.pictureBox1.Image = global::MagnetismForm.Properties.Resources._2;
39 this.pictureBox1.Location = new System.Drawing.Point(0, 31);
40 this.pictureBox1.Name = "pictureBox1";
41 this.pictureBox1.Size = new System.Drawing.Size(290, 209);
42 this.pictureBox1.TabIndex = 1;
43 this.pictureBox1.TabStop = false;
44 //
45 // panel_Title
46 //
47 this.panel_Title.BackColor = System.Drawing.Color.MediumBlue;
48 this.panel_Title.BackgroundImage = global::MagnetismForm.Properties.Resources._5;
49 this.panel_Title.Dock = System.Windows.Forms.DockStyle.Top;
50 this.panel_Title.Location = new System.Drawing.Point(0, 0);
51 this.panel_Title.Name = "panel_Title";
52 this.panel_Title.Size = new System.Drawing.Size(290, 31);
53 this.panel_Title.TabIndex = 0;
54 this.panel_Title.MouseMove += new System.Windows.Forms.MouseEventHandler(this.panel_Title_MouseMove);
55 this.panel_Title.MouseDown += new System.Windows.Forms.MouseEventHandler(this.panel_Title_MouseDown);
56 this.panel_Title.MouseUp += new System.Windows.Forms.MouseEventHandler(this.panel_Title_MouseUp);
57 //
58 // Frm_Libretto
59 //
60 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
61 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
62 this.ClientSize = new System.Drawing.Size(290, 240);
63 this.Controls.Add(this.pictureBox1);
64 this.Controls.Add(this.panel_Title);
65 this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
66 this.Name = "Frm_Libretto";
67 this.Text = "Frm_Libretto";
68 this.Load += new System.EventHandler(this.Frm_Libretto_Load);
69 ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
70 this.ResumeLayout(false);
71
72 }
73
74 #endregion
75
76 private System.Windows.Forms.Panel panel_Title;
77 private System.Windows.Forms.PictureBox pictureBox1;
78 }
79 }

 

 

 

 

 

 

作者: 墨明棋妙
出处: http://www.cnblogs.com/ynbt/
关于作者:专注于.Net、WCF和移动互联网开发。
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,如有问题,可以通过ynbt_wang@163.com联系我,非常感谢。 。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值