diff --git a/FunGame.Desktop/FunGame.Desktop.csproj b/FunGame.Desktop/FunGame.Desktop.csproj
index 9235522..19d53a1 100644
--- a/FunGame.Desktop/FunGame.Desktop.csproj
+++ b/FunGame.Desktop/FunGame.Desktop.csproj
@@ -43,9 +43,7 @@
True
Resources.resx
-
- Form
-
+
diff --git a/FunGame.Desktop/Library/Component/ExitButton.cs b/FunGame.Desktop/Library/Component/ExitButton.cs
index 11c0d3d..fba5a87 100644
--- a/FunGame.Desktop/Library/Component/ExitButton.cs
+++ b/FunGame.Desktop/Library/Component/ExitButton.cs
@@ -10,6 +10,8 @@ namespace Milimoe.FunGame.Desktop.Library.Component
{
public partial class ExitButton : Button
{
+ public GeneralForm? RelativeForm { get; set; }
+
public ExitButton()
{
InitializeComponent();
@@ -27,6 +29,8 @@ namespace Milimoe.FunGame.Desktop.Library.Component
Size = new System.Drawing.Size(47, 47);
TextAlign = System.Drawing.ContentAlignment.TopLeft;
UseVisualStyleBackColor = false;
+
+ Click += ExitButton_Click;
}
public ExitButton(IContainer container)
@@ -47,6 +51,19 @@ namespace Milimoe.FunGame.Desktop.Library.Component
Size = new System.Drawing.Size(47, 47);
TextAlign = System.Drawing.ContentAlignment.TopLeft;
UseVisualStyleBackColor = false;
+
+ Click += ExitButton_Click;
+ }
+
+ ///
+ /// 自带的关闭按钮,可以重写
+ /// 绑定RelativeForm才能生效
+ ///
+ /// object?
+ /// EventArgs
+ protected virtual void ExitButton_Click(object? sender, EventArgs e)
+ {
+ RelativeForm?.Dispose();
}
}
}
diff --git a/FunGame.Desktop/Library/Component/GeneralForm.Designer.cs b/FunGame.Desktop/Library/Component/GeneralForm.Designer.cs
index df9f82a..d66ad2e 100644
--- a/FunGame.Desktop/Library/Component/GeneralForm.Designer.cs
+++ b/FunGame.Desktop/Library/Component/GeneralForm.Designer.cs
@@ -28,13 +28,27 @@
///
private void InitializeComponent()
{
+ this.Title = new System.Windows.Forms.Label();
this.SuspendLayout();
//
+ // Title
+ //
+ this.Title.Font = new System.Drawing.Font("LanaPixel", 26.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point);
+ this.Title.Location = new System.Drawing.Point(3, 3);
+ this.Title.Name = "Title";
+ this.Title.Size = new System.Drawing.Size(387, 47);
+ this.Title.TabIndex = 9;
+ this.Title.Text = "Please Override";
+ this.Title.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
+ this.Title.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Title_MouseDown);
+ this.Title.MouseMove += new System.Windows.Forms.MouseEventHandler(this.Title_MouseMove);
+ //
// GeneralForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(536, 284);
+ this.Controls.Add(this.Title);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.Name = "GeneralForm";
this.Text = "GeneralForm";
@@ -43,5 +57,7 @@
}
#endregion
+
+ protected Label Title;
}
}
\ No newline at end of file
diff --git a/FunGame.Desktop/Library/Component/GeneralForm.cs b/FunGame.Desktop/Library/Component/GeneralForm.cs
index 7fc2aa7..a8ee9ee 100644
--- a/FunGame.Desktop/Library/Component/GeneralForm.cs
+++ b/FunGame.Desktop/Library/Component/GeneralForm.cs
@@ -24,7 +24,7 @@ namespace Milimoe.FunGame.Desktop.Library.Component
///
///
///
- protected void Title_MouseDown(object sender, MouseEventArgs e)
+ protected virtual void Title_MouseDown(object sender, MouseEventArgs e)
{
//判断是否为鼠标左键
if (e.Button == MouseButtons.Left)
@@ -40,7 +40,7 @@ namespace Milimoe.FunGame.Desktop.Library.Component
///
///
///
- protected void Title_MouseMove(object sender, MouseEventArgs e)
+ protected virtual void Title_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
diff --git a/FunGame.Desktop/Library/Component/GeneralForm.resx b/FunGame.Desktop/Library/Component/GeneralForm.resx
index f298a7b..405ea9b 100644
--- a/FunGame.Desktop/Library/Component/GeneralForm.resx
+++ b/FunGame.Desktop/Library/Component/GeneralForm.resx
@@ -57,4 +57,10 @@
System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+ True
+
+
+ True
+
\ No newline at end of file
diff --git a/FunGame.Desktop/Library/Component/MinButton.cs b/FunGame.Desktop/Library/Component/MinButton.cs
index 0ae1f43..9299638 100644
--- a/FunGame.Desktop/Library/Component/MinButton.cs
+++ b/FunGame.Desktop/Library/Component/MinButton.cs
@@ -10,6 +10,8 @@ namespace Milimoe.FunGame.Desktop.Library.Component
{
public partial class MinButton : Button
{
+ public GeneralForm? RelativeForm { get; set; }
+
public MinButton()
{
InitializeComponent();
@@ -27,6 +29,8 @@ namespace Milimoe.FunGame.Desktop.Library.Component
Size = new System.Drawing.Size(47, 47);
TextAlign = System.Drawing.ContentAlignment.TopLeft;
UseVisualStyleBackColor = false;
+
+ Click += MinForm_Click;
}
public MinButton(IContainer container)
@@ -47,6 +51,22 @@ namespace Milimoe.FunGame.Desktop.Library.Component
Size = new System.Drawing.Size(47, 47);
TextAlign = System.Drawing.ContentAlignment.TopLeft;
UseVisualStyleBackColor = false;
+
+ Click += MinForm_Click;
+ }
+
+ ///
+ /// 自带的最小化窗口
+ /// 绑定RelativeForm才能生效
+ ///
+ /// object?
+ /// EventArgs
+ private void MinForm_Click(object? sender, EventArgs e)
+ {
+ if (RelativeForm != null)
+ {
+ RelativeForm.WindowState = FormWindowState.Minimized;
+ }
}
}
}
diff --git a/FunGame.Desktop/UI/Login/Login.Designer.cs b/FunGame.Desktop/UI/Login/Login.Designer.cs
index 2d9bbd3..ad78aba 100644
--- a/FunGame.Desktop/UI/Login/Login.Designer.cs
+++ b/FunGame.Desktop/UI/Login/Login.Designer.cs
@@ -63,7 +63,7 @@
this.ExitButton.TabIndex = 7;
this.ExitButton.TextAlign = System.Drawing.ContentAlignment.TopLeft;
this.ExitButton.UseVisualStyleBackColor = false;
- this.ExitButton.Click += new System.EventHandler(this.ExitButton_Click);
+ this.ExitButton.RelativeForm = this;
//
// MinButton
//
@@ -83,6 +83,7 @@
this.MinButton.TabIndex = 6;
this.MinButton.TextAlign = System.Drawing.ContentAlignment.TopLeft;
this.MinButton.UseVisualStyleBackColor = false;
+ this.MinButton.RelativeForm = this;
//
// Title
//
@@ -221,7 +222,6 @@
private Library.Component.ExitButton ExitButton;
private Library.Component.MinButton MinButton;
- private Label Title;
private Label Username;
private Label Password;
private TextBox UsernameText;
diff --git a/FunGame.Desktop/UI/Login/Login.cs b/FunGame.Desktop/UI/Login/Login.cs
index 88c17c0..0346b6d 100644
--- a/FunGame.Desktop/UI/Login/Login.cs
+++ b/FunGame.Desktop/UI/Login/Login.cs
@@ -1,55 +1,14 @@
-using System;
-using System.Collections.Generic;
-using System.ComponentModel;
-using System.Data;
-using System.Drawing;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using System.Windows.Forms;
+using Milimoe.FunGame.Desktop.Library.Component;
namespace Milimoe.FunGame.Desktop.UI
{
- public partial class Login : Form
+ public partial class Login : GeneralForm
{
- private int loc_x, loc_y; // 窗口当前坐标
-
public Login()
{
InitializeComponent();
}
- ///
- /// 鼠标按下,开始移动主窗口
- ///
- ///
- ///
- private void Title_MouseDown(object sender, MouseEventArgs e)
- {
- //判断是否为鼠标左键
- if (e.Button == MouseButtons.Left)
- {
- //获取鼠标左键按下时的位置
- loc_x = e.Location.X;
- loc_y = e.Location.Y;
- }
- }
-
- ///
- /// 鼠标移动,正在移动主窗口
- ///
- ///
- ///
- private void Title_MouseMove(object sender, MouseEventArgs e)
- {
- if (e.Button == MouseButtons.Left)
- {
- //计算鼠标移动距离
- Left += e.Location.X - loc_x;
- Top += e.Location.Y - loc_y;
- }
- }
-
///
/// 打开注册界面
///
@@ -59,15 +18,5 @@ namespace Milimoe.FunGame.Desktop.UI
{
new Register().ShowDialog();
}
-
- ///
- /// 关闭窗口
- ///
- ///
- ///
- private void ExitButton_Click(object sender, EventArgs e)
- {
- Dispose();
- }
}
}
diff --git a/FunGame.Desktop/UI/Main/Main.Designer.cs b/FunGame.Desktop/UI/Main/Main.Designer.cs
index 4eed058..6a6d6fa 100644
--- a/FunGame.Desktop/UI/Main/Main.Designer.cs
+++ b/FunGame.Desktop/UI/Main/Main.Designer.cs
@@ -35,7 +35,7 @@ namespace Milimoe.FunGame.Desktop.UI
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Main));
this.Exit = new FunGame.Desktop.Library.Component.ExitButton(this.components);
this.Title = new System.Windows.Forms.Label();
- this.MinForm = new System.Windows.Forms.Button();
+ this.MinForm = new Library.Component.MinButton();
this.Connection = new System.Windows.Forms.Label();
this.Light = new System.Windows.Forms.Label();
this.SendTalkText = new System.Windows.Forms.Button();
@@ -125,7 +125,7 @@ namespace Milimoe.FunGame.Desktop.UI
this.MinForm.TabIndex = 14;
this.MinForm.TextAlign = System.Drawing.ContentAlignment.TopLeft;
this.MinForm.UseVisualStyleBackColor = false;
- this.MinForm.Click += new System.EventHandler(this.MinForm_Click);
+ this.MinForm.RelativeForm = this;
//
// Connection
//
@@ -607,8 +607,7 @@ namespace Milimoe.FunGame.Desktop.UI
#endregion
private ExitButton Exit;
- private Label Title;
- private Button MinForm;
+ private MinButton MinForm;
private Label Connection;
private Label Light;
private Button StartMatch;
diff --git a/FunGame.Desktop/UI/Main/Main.cs b/FunGame.Desktop/UI/Main/Main.cs
index 7a01108..3dcb270 100644
--- a/FunGame.Desktop/UI/Main/Main.cs
+++ b/FunGame.Desktop/UI/Main/Main.cs
@@ -15,7 +15,7 @@ using Milimoe.FunGame.Core.Entity;
namespace Milimoe.FunGame.Desktop.UI
{
- public partial class Main : Form
+ public partial class Main : GeneralForm
{
#region 变量定义
@@ -26,8 +26,6 @@ namespace Milimoe.FunGame.Desktop.UI
public int MaxRetryTimes { get; } = SocketSet.MaxRetryTimes; // 最大重试连接次数
public int CurrentRetryTimes { get; set; } = -1; // 当前重试连接次数
- private int loc_x, loc_y; // 窗口当前坐标
-
/**
* 定义全局对象
*/
@@ -811,37 +809,6 @@ namespace Milimoe.FunGame.Desktop.UI
}
}
- ///
- /// 鼠标按下,开始移动主窗口
- ///
- ///
- ///
- private void Title_MouseDown(object sender, MouseEventArgs e)
- {
- //判断是否为鼠标左键
- if (e.Button == MouseButtons.Left)
- {
- //获取鼠标左键按下时的位置
- loc_x = e.Location.X;
- loc_y = e.Location.Y;
- }
- }
-
- ///
- /// 鼠标移动,正在移动主窗口
- ///
- ///
- ///
- private void Title_MouseMove(object sender, MouseEventArgs e)
- {
- if (e.Button == MouseButtons.Left)
- {
- //计算鼠标移动距离
- Left += e.Location.X - loc_x;
- Top += e.Location.Y - loc_y;
- }
- }
-
///
/// 开始匹配
///
@@ -1165,16 +1132,6 @@ namespace Milimoe.FunGame.Desktop.UI
}
}
- ///
- /// 最小化窗口
- ///
- ///
- ///
- private void MinForm_Click(object sender, EventArgs e)
- {
- WindowState = FormWindowState.Minimized;
- }
-
#endregion
#region 工具方法
diff --git a/FunGame.Desktop/UI/Register/Register.Designer.cs b/FunGame.Desktop/UI/Register/Register.Designer.cs
index 903a186..00e13c1 100644
--- a/FunGame.Desktop/UI/Register/Register.Designer.cs
+++ b/FunGame.Desktop/UI/Register/Register.Designer.cs
@@ -241,7 +241,6 @@
private Library.Component.ExitButton ExitButton;
private Library.Component.MinButton MinButton;
- private Label Title;
private Label Username;
private Label Password;
private Label CheckPassword;
diff --git a/FunGame.Desktop/UI/Register/Register.cs b/FunGame.Desktop/UI/Register/Register.cs
index f794147..8def1c8 100644
--- a/FunGame.Desktop/UI/Register/Register.cs
+++ b/FunGame.Desktop/UI/Register/Register.cs
@@ -1,55 +1,14 @@
-using System;
-using System.Collections.Generic;
-using System.ComponentModel;
-using System.Data;
-using System.Drawing;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using System.Windows.Forms;
+using Milimoe.FunGame.Desktop.Library.Component;
namespace Milimoe.FunGame.Desktop.UI
{
- public partial class Register : Form
+ public partial class Register : GeneralForm
{
- private int loc_x, loc_y; // 窗口当前坐标
-
public Register()
{
InitializeComponent();
}
- ///
- /// 鼠标按下,开始移动主窗口
- ///
- ///
- ///
- private void Title_MouseDown(object sender, MouseEventArgs e)
- {
- //判断是否为鼠标左键
- if (e.Button == MouseButtons.Left)
- {
- //获取鼠标左键按下时的位置
- loc_x = e.Location.X;
- loc_y = e.Location.Y;
- }
- }
-
- ///
- /// 鼠标移动,正在移动主窗口
- ///
- ///
- ///
- private void Title_MouseMove(object sender, MouseEventArgs e)
- {
- if (e.Button == MouseButtons.Left)
- {
- //计算鼠标移动距离
- Left += e.Location.X - loc_x;
- Top += e.Location.Y - loc_y;
- }
- }
-
///
/// 关闭窗口
///