<em>Mac</em>Book项目 2009年学校开始实施<em>Mac</em>Book项目,所有师生配备一本<em>Mac</em>Book,并同步更新了校园无线网络。学校每周进行电脑技术更新,每月发送技术支持资料,极大改变了教学及学习方式。因此2011
2021-06-01 09:32:01
public partial class Frm_Libretto : Form { public Frm_Libretto() { InitializeComponent(); } #region 公共變數 FrmClass Cla_FrmClass = new FrmClass(); #endregion private void Frm_Libretto_Load(object sender, EventArgs e) { this.Top = FrmClass.Example_Play_Top; this.Left = FrmClass.Example_Play_Left + FrmClass.Example_Play_Width; Cla_FrmClass.FrmInitialize(this); } private void panel_Title_MouseDown(object sender, MouseEventArgs e) { FrmClass.CPoint = new Point(-e.X, -e.Y); } private void panel_Title_MouseMove(object sender, MouseEventArgs e) { FrmClass.Example_Assistant_AdhereTo = false; FrmClass.Example_Libretto_AdhereTo = false; Cla_FrmClass.FrmMove(this, e); } private void panel_Title_MouseUp(object sender, MouseEventArgs e) { Cla_FrmClass.FrmPlace(this); } }
public partial class Frm_ListBox : Form { public Frm_ListBox() { InitializeComponent(); } #region 公共變數 FrmClass Cla_FrmClass = new FrmClass(); #endregion private void Frm_ListBox_Load(object sender, EventArgs e) { this.Left = FrmClass.Example_Play_Left; this.Top = FrmClass.Example_Play_Top + FrmClass.Example_Play_Height; Cla_FrmClass.FrmInitialize(this); } private void panel_Title_MouseDown(object sender, MouseEventArgs e) { FrmClass.CPoint = new Point(-e.X, -e.Y); } private void panel_Title_MouseMove(object sender, MouseEventArgs e) { FrmClass.Example_Assistant_AdhereTo = false; FrmClass.Example_List_AdhereTo = false; Cla_FrmClass.FrmMove(this, e); } private void panel_Title_MouseUp(object sender, MouseEventArgs e) { Cla_FrmClass.FrmPlace(this); } }
public partial class Frm_Play : Form { public Frm_Play() { InitializeComponent(); } #region 公共變數 FrmClass Cla_FrmClass = new FrmClass(); public static Form F_List = new Form(); public static Form F_Libretto = new Form(); public static Form F_Screen = new Form(); #endregion private void Frm_Play_Load(object sender, EventArgs e) { //表單位置的初始化 Cla_FrmClass.FrmInitialize(this); } private void panel_Title_MouseDown(object sender, MouseEventArgs e) { int Tem_Y = 0; if (e.Button == MouseButtons.Left) //按下的是否為滑鼠左鍵 { Cla_FrmClass.FrmBackCheck(); //檢測各表單是否連在一起 Tem_Y = e.Y; FrmClass.FrmPoint = new Point(e.X, Tem_Y); //獲取滑鼠在表單上的位置,用於磁性表單 FrmClass.CPoint = new Point(-e.X, -Tem_Y); //獲取滑鼠在螢幕上的位置,用於表單的移動 if (FrmClass.Example_List_AdhereTo) //如果與frm_ListBox表單相連線 { Cla_FrmClass.FrmDistanceJob(this, F_List); //計算表單的距離差 if (FrmClass.Example_Assistant_AdhereTo) //兩個輔表單是否連線在一起 { Cla_FrmClass.FrmDistanceJob(this, F_Libretto); //計算表單的距離差 } } if (FrmClass.Example_Libretto_AdhereTo) //如果與frm_Libretto表單相連線 { Cla_FrmClass.FrmDistanceJob(this, F_Libretto); //計算表單的距離差 if (FrmClass.Example_Assistant_AdhereTo) //兩個輔表單是否連線在一起 { Cla_FrmClass.FrmDistanceJob(this, F_List); //計算表單的距離差 } } } } private void panel_Title_MouseMove(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) //按下的是否為滑鼠左鍵 { Cla_FrmClass.FrmMove(this, e); //利用控制元件移動表單 if (FrmClass.Example_List_AdhereTo) //如果frm_ListBox表單與主表單連線 { Cla_FrmClass.ManyFrmMove(this, e, F_List); //磁性表單的移動 Cla_FrmClass.FrmInitialize(F_List); //對frm_ListBox表單的位置進行初始化 if (FrmClass.Example_Assistant_AdhereTo) //如果兩個子表單連線在一起 { Cla_FrmClass.ManyFrmMove(this, e, F_Libretto); Cla_FrmClass.FrmInitialize(F_Libretto); } } if (FrmClass.Example_Libretto_AdhereTo) //如果frm_Libretto表單與主表單連線 { Cla_FrmClass.ManyFrmMove(this, e, F_Libretto); Cla_FrmClass.FrmInitialize(F_Libretto); if (FrmClass.Example_Assistant_AdhereTo) { Cla_FrmClass.ManyFrmMove(this, e, F_List); Cla_FrmClass.FrmInitialize(F_List); } } Cla_FrmClass.FrmInitialize(this); } } private void panel_Title_MouseUp(object sender, MouseEventArgs e) { Cla_FrmClass.FrmPlace(this); } private void Frm_Play_Shown(object sender, EventArgs e) { //顯示列表表單 F_List = new Frm_ListBox(); F_List.ShowInTaskbar = false; FrmClass.Example_ListShow = true; F_List.Show(); //顯示歌詞表單 F_Libretto = new Frm_Libretto(); F_Libretto.ShowInTaskbar = false; FrmClass.Example_LibrettoShow = true; F_Libretto.Show(); F_Libretto.Left = this.Left + this.Width; F_Libretto.Top = this.Top; //各表單位置的初始化 Cla_FrmClass.FrmInitialize(F_List); Cla_FrmClass.FrmInitialize(F_Libretto); } private void panel_Close_Click(object sender, EventArgs e) { F_List.Close(); F_List.Dispose(); F_Libretto.Close(); F_Libretto.Dispose(); F_Screen.Close(); F_Screen.Dispose(); this.Close(); } private void panel_Title_Click(object sender, EventArgs e) { F_List.Focus(); F_Libretto.Focus(); this.Focus(); } }
class FrmClass { #region 磁性表單-公共變數 //記錄表單的隱藏與顯示 public static bool Example_ListShow = false; public static bool Example_LibrettoShow = false; public static bool Example_ScreenShow = false; //記錄滑鼠的當前位置 public static Point CPoint; //新增名稱空間using System.Drawing; public static Point FrmPoint; public static int Example_FSpace = 10; //設定表單間的距離 //Frm_Play表單的位置及大小 public static int Example_Play_Top = 0; public static int Example_Play_Left = 0; public static int Example_Play_Width = 0; public static int Example_Play_Height = 0; public static bool Example_Assistant_AdhereTo = false; //輔助表單是否磁性在一起 //Frm_ListBos表單的位置及大小 public static int Example_List_Top = 0; public static int Example_List_Left = 0; public static int Example_List_Width = 0; public static int Example_List_Height = 0; public static bool Example_List_AdhereTo = false; //輔助表單是否與主表單磁性在一起 //Frm_Libretto表單的位置及大小 public static int Example_Libretto_Top = 0; public static int Example_Libretto_Left = 0; public static int Example_Libretto_Width = 0; public static int Example_Libretto_Height = 0; public static bool Example_Libretto_AdhereTo = false; //輔助表單是否與主表單磁性在一起 //表單之間的距離差 public static int Example_List_space_Top = 0; public static int Example_List_space_Left = 0; public static int Example_Libretto_space_Top = 0; public static int Example_Libretto_space_Left = 0; #endregion #region 檢測各表單是否連線在一起 /// <summary> /// 檢測各表單是否連線在一起 /// </summary> public void FrmBackCheck() { bool Tem_Magnetism = false; //Frm_ListBos與主表單 Tem_Magnetism = false; if ((Example_Play_Top - Example_List_Top) == 0) Tem_Magnetism = true; if ((Example_Play_Left - Example_List_Left) == 0) Tem_Magnetism = true; if ((Example_Play_Left - Example_List_Left - Example_List_Width) == 0) Tem_Magnetism = true; if ((Example_Play_Left - Example_List_Left + Example_List_Width) == 0) Tem_Magnetism = true; if ((Example_Play_Top - Example_List_Top - Example_List_Height) == 0) Tem_Magnetism = true; if ((Example_Play_Top - Example_List_Top + Example_List_Height) == 0) Tem_Magnetism = true; if (Tem_Magnetism) Example_List_AdhereTo = true; //Frm_Libretto與主表單 Tem_Magnetism = false; if ((Example_Play_Top - Example_Libretto_Top) == 0) Tem_Magnetism = true; if ((Example_Play_Left - Example_Libretto_Left) == 0) Tem_Magnetism = true; if ((Example_Play_Left - Example_Libretto_Left - Example_Libretto_Width) == 0) Tem_Magnetism = true; if ((Example_Play_Left - Example_Libretto_Left + Example_Libretto_Width) == 0) Tem_Magnetism = true; if ((Example_Play_Top - Example_Libretto_Top - Example_Libretto_Height) == 0) Tem_Magnetism = true; if ((Example_Play_Top - Example_Libretto_Top + Example_Libretto_Height) == 0) Tem_Magnetism = true; if (Tem_Magnetism) Example_Libretto_AdhereTo = true; //兩個輔表單 Tem_Magnetism = false; if ((Example_List_Top - Example_Libretto_Top) == 0) Tem_Magnetism = true; if ((Example_List_Left - Example_Libretto_Left) == 0) Tem_Magnetism = true; if ((Example_List_Left - Example_Libretto_Left - Example_Libretto_Width) == 0) Tem_Magnetism = true; if ((Example_List_Left - Example_Libretto_Left + Example_Libretto_Width) == 0) Tem_Magnetism = true; if ((Example_List_Top - Example_Libretto_Top - Example_Libretto_Height) == 0) Tem_Magnetism = true; if ((Example_List_Top - Example_Libretto_Top + Example_Libretto_Height) == 0) Tem_Magnetism = true; if (Tem_Magnetism) Example_Assistant_AdhereTo = true; } #endregion #region 利用表單上的控制元件移動表單 /// <summary> /// 利用控制元件移動表單 /// </summary> /// <param Frm="Form">表單</param> /// <param e="MouseEventArgs">控制元件的移動事件</param> public void FrmMove(Form Frm, MouseEventArgs e) //Form或MouseEventArgs新增名稱空間using System.Windows.Forms; { if (e.Button == MouseButtons.Left) { Point myPosittion = Control.MousePosition; //獲取當前滑鼠的螢幕座標 myPosittion.Offset(CPoint.X, CPoint.Y); //過載當前滑鼠的位置 Frm.DesktopLocation = myPosittion; //設定當前表單在螢幕上的位置 } } #endregion #region 計算表單之間的距離差 /// <summary> /// 計算表單之間的距離差 /// </summary> /// <param Frm="Form">表單</param> /// <param Follow="Form">跟隨表單</param> public void FrmDistanceJob(Form Frm, Form Follow) { switch (Follow.Name) { case "Frm_ListBox": { Example_List_space_Top = Follow.Top - Frm.Top; Example_List_space_Left = Follow.Left - Frm.Left; break; } case "Frm_Libretto": { Example_Libretto_space_Top = Follow.Top - Frm.Top; Example_Libretto_space_Left = Follow.Left - Frm.Left; break; } } } #endregion #region 磁性表單的移動 /// <summary> /// 磁性表單的移動 /// </summary> /// <param Frm="Form">表單</param> /// <param e="MouseEventArgs">控制元件的移動事件</param> /// <param Follow="Form">跟隨表單</param> public void ManyFrmMove(Form Frm, MouseEventArgs e, Form Follow) //Form或MouseEventArgs新增名稱空間using System.Windows.Forms; { if (e.Button == MouseButtons.Left) { int Tem_Left = 0; int Tem_Top = 0; Point myPosittion = Control.MousePosition; //獲取當前滑鼠的螢幕座標 switch (Follow.Name) { case "Frm_ListBox": { Tem_Top = Example_List_space_Top - FrmPoint.Y; Tem_Left = Example_List_space_Left - FrmPoint.X; break; } case "Frm_Libretto": { Tem_Top = Example_Libretto_space_Top - FrmPoint.Y; Tem_Left = Example_Libretto_space_Left - FrmPoint.X; break; } } myPosittion.Offset(Tem_Left, Tem_Top); Follow.DesktopLocation = myPosittion; } } #endregion #region 對錶單的位置進行初始化 /// <summary> /// 對錶單的位置進行初始化 /// </summary> /// <param Frm="Form">表單</param> public void FrmInitialize(Form Frm) { switch (Frm.Name) { case "Frm_Play": { Example_Play_Top = Frm.Top; Example_Play_Left = Frm.Left; Example_Play_Width = Frm.Width; Example_Play_Height = Frm.Height; break; } case "Frm_ListBox": { Example_List_Top = Frm.Top; Example_List_Left = Frm.Left; Example_List_Width = Frm.Width; Example_List_Height = Frm.Height; break; } case "Frm_Libretto": { Example_Libretto_Top = Frm.Top; Example_Libretto_Left = Frm.Left; Example_Libretto_Width = Frm.Width; Example_Libretto_Height = Frm.Height; break; } } } #endregion #region 儲存各表單的當前資訊 /// <summary> /// 儲存各表單的當前資訊 /// </summary> /// <param Frm="Form">表單</param> /// <param e="MouseEventArgs">控制元件的移動事件</param> public void FrmPlace(Form Frm) { FrmInitialize(Frm); FrmMagnetism(Frm); } #endregion #region 表單的磁性設定 /// <summary> /// 表單的磁性設定 /// </summary> /// <param Frm="Form">表單</param> public void FrmMagnetism(Form Frm) { if (Frm.Name != "Frm_Play") { FrmMagnetismCount(Frm, Example_Play_Top, Example_Play_Left, Example_Play_Width, Example_Play_Height, "Frm_Play"); } if (Frm.Name != "Frm_ListBos") { FrmMagnetismCount(Frm, Example_List_Top, Example_List_Left, Example_List_Width, Example_List_Height, "Frm_ListBos"); } if (Frm.Name != "Frm_Libratto") { FrmMagnetismCount(Frm, Example_Libretto_Top, Example_Libretto_Left, Example_Libretto_Width, Example_Libretto_Height, "Frm_Libratto"); } FrmInitialize(Frm); } #endregion #region 磁性表單的計算 /// <summary> /// 磁性表單的計算 /// </summary> /// <param Frm="Form">表單</param> /// <param e="MouseEventArgs">控制元件的移動事件</param> public void FrmMagnetismCount(Form Frm, int top, int left, int width, int height, string Mforms) { bool Tem_Magnetism = false; //判斷是否有磁性發生 string Tem_MainForm = ""; //臨時記錄主表單 string Tem_AssistForm = ""; //臨時記錄輔表單 //上面進行磁性表單 if ((Frm.Top + Frm.Height - top) <= Example_FSpace && (Frm.Top + Frm.Height - top) >= -Example_FSpace) { //當一個主表單不包含輔表單時 if ((Frm.Left >= left && Frm.Left <= (left + width)) || ((Frm.Left + Frm.Width) >= left && (Frm.Left + Frm.Width) <= (left + width))) { Frm.Top = top - Frm.Height; if ((Frm.Left - left) <= Example_FSpace && (Frm.Left - left) >= -Example_FSpace) Frm.Left = left; Tem_Magnetism = true; } //當一個主表單包含輔表單時 if (Frm.Left <= left && (Frm.Left + Frm.Width) >= (left + width)) { Frm.Top = top - Frm.Height; if ((Frm.Left - left) <= Example_FSpace && (Frm.Left - left) >= -Example_FSpace) Frm.Left = left; Tem_Magnetism = true; } } //下面進行磁性表單 if ((Frm.Top - (top + height)) <= Example_FSpace && (Frm.Top - (top + height)) >= -Example_FSpace) { //當一個主表單不包含輔表單時 if ((Frm.Left >= left && Frm.Left <= (left + width)) || ((Frm.Left + Frm.Width) >= left && (Frm.Left + Frm.Width) <= (left + width))) { Frm.Top = top + height; if ((Frm.Left - left) <= Example_FSpace && (Frm.Left - left) >= -Example_FSpace) Frm.Left = left; Tem_Magnetism = true; } //當一個主表單包含輔表單時 if (Frm.Left <= left && (Frm.Left + Frm.Width) >= (left + width)) { Frm.Top = top + height; if ((Frm.Left - left) <= Example_FSpace && (Frm.Left - left) >= -Example_FSpace) Frm.Left = left; Tem_Magnetism = true; } } //左面進行磁性表單 if ((Frm.Left + Frm.Width - left) <= Example_FSpace && (Frm.Left + Frm.Width - left) >= -Example_FSpace) { //當一個主表單不包含輔表單時 if ((Frm.Top > top && Frm.Top <= (top + height)) || ((Frm.Top + Frm.Height) >= top && (Frm.Top + Frm.Height) <= (top + height))) { Frm.Left = left - Frm.Width; if ((Frm.Top - top) <= Example_FSpace && (Frm.Top - top) >= -Example_FSpace) Frm.Top = top; Tem_Magnetism = true; } //當一個主表單包含輔表單時 if (Frm.Top <= top && (Frm.Top + Frm.Height) >= (top + height)) { Frm.Left = left - Frm.Width; if ((Frm.Top - top) <= Example_FSpace && (Frm.Top - top) >= -Example_FSpace) Frm.Top = top; Tem_Magnetism = true; } } //右面進行磁性表單 if ((Frm.Left - (left + width)) <= Example_FSpace && (Frm.Left - (left + width)) >= -Example_FSpace) { //當一個主表單不包含輔表單時 if ((Frm.Top > top && Frm.Top <= (top + height)) || ((Frm.Top + Frm.Height) >= top && (Frm.Top + Frm.Height) <= (top + height))) { Frm.Left = left + width; if ((Frm.Top - top) <= Example_FSpace && (Frm.Top - top) >= -Example_FSpace) Frm.Top = top; Tem_Magnetism = true; } //當一個主表單包含輔表單時 if (Frm.Top <= top && (Frm.Top + Frm.Height) >= (top + height)) { Frm.Left = left + width; if ((Frm.Top - top) <= Example_FSpace && (Frm.Top - top) >= -Example_FSpace) Frm.Top = top; Tem_Magnetism = true; } } if (Frm.Name == "Frm_Play") Tem_MainForm = "Frm_Play"; else Tem_AssistForm = Frm.Name; if (Mforms == "Frm_Play") Tem_MainForm = "Frm_Play"; else Tem_AssistForm = Mforms; if (Tem_MainForm == "") { Example_Assistant_AdhereTo = Tem_Magnetism; } else { switch (Tem_AssistForm) { case "Frm_ListBos": Example_List_AdhereTo = Tem_Magnetism; break; case "Frm_Libratto": Example_Libretto_AdhereTo = Tem_Magnetism; break; } } } #endregion #region 恢復表單的初始大小 /// <summary> /// 恢復表單的初始大小(當鬆開滑鼠時,如果表單的大小小於300*200,恢復初始狀態) /// </summary> /// <param Frm="Form">表單</param> public void FrmScreen_FormerlySize(Form Frm, int PWidth, int PHeight) { if (Frm.Width < PWidth || Frm.Height < PHeight) { Frm.Width = PWidth; Frm.Height = PHeight; //Example_Size = false; } } #endregion }
static class Program { /// <summary> /// 應用程式的主入口點。 /// </summary> [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Frm_Play()); } }
到此這篇關於基於C#實現磁性吸附表單的文章就介紹到這了,更多相關C#磁性吸附表單內容請搜尋it145.com以前的文章或繼續瀏覽下面的相關文章希望大家以後多多支援it145.com!
相關文章
<em>Mac</em>Book项目 2009年学校开始实施<em>Mac</em>Book项目,所有师生配备一本<em>Mac</em>Book,并同步更新了校园无线网络。学校每周进行电脑技术更新,每月发送技术支持资料,极大改变了教学及学习方式。因此2011
2021-06-01 09:32:01
综合看Anker超能充系列的性价比很高,并且与不仅和iPhone12/苹果<em>Mac</em>Book很配,而且适合多设备充电需求的日常使用或差旅场景,不管是安卓还是Switch同样也能用得上它,希望这次分享能给准备购入充电器的小伙伴们有所
2021-06-01 09:31:42
除了L4WUDU与吴亦凡已经多次共事,成为了明面上的厂牌成员,吴亦凡还曾带领20XXCLUB全队参加2020年的一场音乐节,这也是20XXCLUB首次全员合照,王嗣尧Turbo、陈彦希Regi、<em>Mac</em> Ova Seas、林渝植等人全部出场。然而让
2021-06-01 09:31:34
目前应用IPFS的机构:1 谷歌<em>浏览器</em>支持IPFS分布式协议 2 万维网 (历史档案博物馆)数据库 3 火狐<em>浏览器</em>支持 IPFS分布式协议 4 EOS 等数字货币数据存储 5 美国国会图书馆,历史资料永久保存在 IPFS 6 加
2021-06-01 09:31:24
开拓者的车机是兼容苹果和<em>安卓</em>,虽然我不怎么用,但确实兼顾了我家人的很多需求:副驾的门板还配有解锁开关,有的时候老婆开车,下车的时候偶尔会忘记解锁,我在副驾驶可以自己开门:第二排设计很好,不仅配置了一个很大的
2021-06-01 09:30:48
不仅是<em>安卓</em>手机,苹果手机的降价力度也是前所未有了,iPhone12也“跳水价”了,发布价是6799元,如今已经跌至5308元,降价幅度超过1400元,最新定价确认了。iPhone12是苹果首款5G手机,同时也是全球首款5nm芯片的智能机,它
2021-06-01 09:30:45