封装GeneralForm

This commit is contained in:
Mili 2023-02-18 16:16:39 +08:00
parent a0b54ec03b
commit ef2476e421
12 changed files with 72 additions and 152 deletions

View File

@ -43,9 +43,7 @@
<AutoGen>True</AutoGen> <AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon> <DependentUpon>Resources.resx</DependentUpon>
</Compile> </Compile>
<Compile Update="UI\Login\Login.cs"> <Compile Update="UI\Login\Login.cs" />
<SubType>Form</SubType>
</Compile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@ -10,6 +10,8 @@ namespace Milimoe.FunGame.Desktop.Library.Component
{ {
public partial class ExitButton : Button public partial class ExitButton : Button
{ {
public GeneralForm? RelativeForm { get; set; }
public ExitButton() public ExitButton()
{ {
InitializeComponent(); InitializeComponent();
@ -27,6 +29,8 @@ namespace Milimoe.FunGame.Desktop.Library.Component
Size = new System.Drawing.Size(47, 47); Size = new System.Drawing.Size(47, 47);
TextAlign = System.Drawing.ContentAlignment.TopLeft; TextAlign = System.Drawing.ContentAlignment.TopLeft;
UseVisualStyleBackColor = false; UseVisualStyleBackColor = false;
Click += ExitButton_Click;
} }
public ExitButton(IContainer container) public ExitButton(IContainer container)
@ -47,6 +51,19 @@ namespace Milimoe.FunGame.Desktop.Library.Component
Size = new System.Drawing.Size(47, 47); Size = new System.Drawing.Size(47, 47);
TextAlign = System.Drawing.ContentAlignment.TopLeft; TextAlign = System.Drawing.ContentAlignment.TopLeft;
UseVisualStyleBackColor = false; UseVisualStyleBackColor = false;
Click += ExitButton_Click;
}
/// <summary>
/// 自带的关闭按钮,可以重写
/// 绑定RelativeForm才能生效
/// </summary>
/// <param name="sender">object?</param>
/// <param name="e">EventArgs</param>
protected virtual void ExitButton_Click(object? sender, EventArgs e)
{
RelativeForm?.Dispose();
} }
} }
} }

View File

@ -28,13 +28,27 @@
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
this.Title = new System.Windows.Forms.Label();
this.SuspendLayout(); 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 // GeneralForm
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F); this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(536, 284); this.ClientSize = new System.Drawing.Size(536, 284);
this.Controls.Add(this.Title);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.Name = "GeneralForm"; this.Name = "GeneralForm";
this.Text = "GeneralForm"; this.Text = "GeneralForm";
@ -43,5 +57,7 @@
} }
#endregion #endregion
protected Label Title;
} }
} }

View File

@ -24,7 +24,7 @@ namespace Milimoe.FunGame.Desktop.Library.Component
/// </summary> /// </summary>
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
protected void Title_MouseDown(object sender, MouseEventArgs e) protected virtual void Title_MouseDown(object sender, MouseEventArgs e)
{ {
//判断是否为鼠标左键 //判断是否为鼠标左键
if (e.Button == MouseButtons.Left) if (e.Button == MouseButtons.Left)
@ -40,7 +40,7 @@ namespace Milimoe.FunGame.Desktop.Library.Component
/// </summary> /// </summary>
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
protected void Title_MouseMove(object sender, MouseEventArgs e) protected virtual void Title_MouseMove(object sender, MouseEventArgs e)
{ {
if (e.Button == MouseButtons.Left) if (e.Button == MouseButtons.Left)
{ {

View File

@ -57,4 +57,10 @@
<resheader name="writer"> <resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader> </resheader>
<metadata name="Title.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="$this.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
</root> </root>

View File

@ -10,6 +10,8 @@ namespace Milimoe.FunGame.Desktop.Library.Component
{ {
public partial class MinButton : Button public partial class MinButton : Button
{ {
public GeneralForm? RelativeForm { get; set; }
public MinButton() public MinButton()
{ {
InitializeComponent(); InitializeComponent();
@ -27,6 +29,8 @@ namespace Milimoe.FunGame.Desktop.Library.Component
Size = new System.Drawing.Size(47, 47); Size = new System.Drawing.Size(47, 47);
TextAlign = System.Drawing.ContentAlignment.TopLeft; TextAlign = System.Drawing.ContentAlignment.TopLeft;
UseVisualStyleBackColor = false; UseVisualStyleBackColor = false;
Click += MinForm_Click;
} }
public MinButton(IContainer container) public MinButton(IContainer container)
@ -47,6 +51,22 @@ namespace Milimoe.FunGame.Desktop.Library.Component
Size = new System.Drawing.Size(47, 47); Size = new System.Drawing.Size(47, 47);
TextAlign = System.Drawing.ContentAlignment.TopLeft; TextAlign = System.Drawing.ContentAlignment.TopLeft;
UseVisualStyleBackColor = false; UseVisualStyleBackColor = false;
Click += MinForm_Click;
}
/// <summary>
/// 自带的最小化窗口
/// 绑定RelativeForm才能生效
/// </summary>
/// <param name="sender">object?</param>
/// <param name="e">EventArgs</param>
private void MinForm_Click(object? sender, EventArgs e)
{
if (RelativeForm != null)
{
RelativeForm.WindowState = FormWindowState.Minimized;
}
} }
} }
} }

View File

@ -63,7 +63,7 @@
this.ExitButton.TabIndex = 7; this.ExitButton.TabIndex = 7;
this.ExitButton.TextAlign = System.Drawing.ContentAlignment.TopLeft; this.ExitButton.TextAlign = System.Drawing.ContentAlignment.TopLeft;
this.ExitButton.UseVisualStyleBackColor = false; this.ExitButton.UseVisualStyleBackColor = false;
this.ExitButton.Click += new System.EventHandler(this.ExitButton_Click); this.ExitButton.RelativeForm = this;
// //
// MinButton // MinButton
// //
@ -83,6 +83,7 @@
this.MinButton.TabIndex = 6; this.MinButton.TabIndex = 6;
this.MinButton.TextAlign = System.Drawing.ContentAlignment.TopLeft; this.MinButton.TextAlign = System.Drawing.ContentAlignment.TopLeft;
this.MinButton.UseVisualStyleBackColor = false; this.MinButton.UseVisualStyleBackColor = false;
this.MinButton.RelativeForm = this;
// //
// Title // Title
// //
@ -221,7 +222,6 @@
private Library.Component.ExitButton ExitButton; private Library.Component.ExitButton ExitButton;
private Library.Component.MinButton MinButton; private Library.Component.MinButton MinButton;
private Label Title;
private Label Username; private Label Username;
private Label Password; private Label Password;
private TextBox UsernameText; private TextBox UsernameText;

View File

@ -1,55 +1,14 @@
using System; using Milimoe.FunGame.Desktop.Library.Component;
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;
namespace Milimoe.FunGame.Desktop.UI namespace Milimoe.FunGame.Desktop.UI
{ {
public partial class Login : Form public partial class Login : GeneralForm
{ {
private int loc_x, loc_y; // 窗口当前坐标
public Login() public Login()
{ {
InitializeComponent(); InitializeComponent();
} }
/// <summary>
/// 鼠标按下,开始移动主窗口
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Title_MouseDown(object sender, MouseEventArgs e)
{
//判断是否为鼠标左键
if (e.Button == MouseButtons.Left)
{
//获取鼠标左键按下时的位置
loc_x = e.Location.X;
loc_y = e.Location.Y;
}
}
/// <summary>
/// 鼠标移动,正在移动主窗口
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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;
}
}
/// <summary> /// <summary>
/// 打开注册界面 /// 打开注册界面
/// </summary> /// </summary>
@ -59,15 +18,5 @@ namespace Milimoe.FunGame.Desktop.UI
{ {
new Register().ShowDialog(); new Register().ShowDialog();
} }
/// <summary>
/// 关闭窗口
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ExitButton_Click(object sender, EventArgs e)
{
Dispose();
}
} }
} }

View File

@ -35,7 +35,7 @@ namespace Milimoe.FunGame.Desktop.UI
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Main)); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Main));
this.Exit = new FunGame.Desktop.Library.Component.ExitButton(this.components); this.Exit = new FunGame.Desktop.Library.Component.ExitButton(this.components);
this.Title = new System.Windows.Forms.Label(); 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.Connection = new System.Windows.Forms.Label();
this.Light = new System.Windows.Forms.Label(); this.Light = new System.Windows.Forms.Label();
this.SendTalkText = new System.Windows.Forms.Button(); this.SendTalkText = new System.Windows.Forms.Button();
@ -125,7 +125,7 @@ namespace Milimoe.FunGame.Desktop.UI
this.MinForm.TabIndex = 14; this.MinForm.TabIndex = 14;
this.MinForm.TextAlign = System.Drawing.ContentAlignment.TopLeft; this.MinForm.TextAlign = System.Drawing.ContentAlignment.TopLeft;
this.MinForm.UseVisualStyleBackColor = false; this.MinForm.UseVisualStyleBackColor = false;
this.MinForm.Click += new System.EventHandler(this.MinForm_Click); this.MinForm.RelativeForm = this;
// //
// Connection // Connection
// //
@ -607,8 +607,7 @@ namespace Milimoe.FunGame.Desktop.UI
#endregion #endregion
private ExitButton Exit; private ExitButton Exit;
private Label Title; private MinButton MinForm;
private Button MinForm;
private Label Connection; private Label Connection;
private Label Light; private Label Light;
private Button StartMatch; private Button StartMatch;

View File

@ -15,7 +15,7 @@ using Milimoe.FunGame.Core.Entity;
namespace Milimoe.FunGame.Desktop.UI namespace Milimoe.FunGame.Desktop.UI
{ {
public partial class Main : Form public partial class Main : GeneralForm
{ {
#region #region
@ -26,8 +26,6 @@ namespace Milimoe.FunGame.Desktop.UI
public int MaxRetryTimes { get; } = SocketSet.MaxRetryTimes; // 最大重试连接次数 public int MaxRetryTimes { get; } = SocketSet.MaxRetryTimes; // 最大重试连接次数
public int CurrentRetryTimes { get; set; } = -1; // 当前重试连接次数 public int CurrentRetryTimes { get; set; } = -1; // 当前重试连接次数
private int loc_x, loc_y; // 窗口当前坐标
/** /**
* *
*/ */
@ -811,37 +809,6 @@ namespace Milimoe.FunGame.Desktop.UI
} }
} }
/// <summary>
/// 鼠标按下,开始移动主窗口
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Title_MouseDown(object sender, MouseEventArgs e)
{
//判断是否为鼠标左键
if (e.Button == MouseButtons.Left)
{
//获取鼠标左键按下时的位置
loc_x = e.Location.X;
loc_y = e.Location.Y;
}
}
/// <summary>
/// 鼠标移动,正在移动主窗口
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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;
}
}
/// <summary> /// <summary>
/// 开始匹配 /// 开始匹配
/// </summary> /// </summary>
@ -1165,16 +1132,6 @@ namespace Milimoe.FunGame.Desktop.UI
} }
} }
/// <summary>
/// 最小化窗口
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void MinForm_Click(object sender, EventArgs e)
{
WindowState = FormWindowState.Minimized;
}
#endregion #endregion
#region #region

View File

@ -241,7 +241,6 @@
private Library.Component.ExitButton ExitButton; private Library.Component.ExitButton ExitButton;
private Library.Component.MinButton MinButton; private Library.Component.MinButton MinButton;
private Label Title;
private Label Username; private Label Username;
private Label Password; private Label Password;
private Label CheckPassword; private Label CheckPassword;

View File

@ -1,55 +1,14 @@
using System; using Milimoe.FunGame.Desktop.Library.Component;
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;
namespace Milimoe.FunGame.Desktop.UI namespace Milimoe.FunGame.Desktop.UI
{ {
public partial class Register : Form public partial class Register : GeneralForm
{ {
private int loc_x, loc_y; // 窗口当前坐标
public Register() public Register()
{ {
InitializeComponent(); InitializeComponent();
} }
/// <summary>
/// 鼠标按下,开始移动主窗口
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Title_MouseDown(object sender, MouseEventArgs e)
{
//判断是否为鼠标左键
if (e.Button == MouseButtons.Left)
{
//获取鼠标左键按下时的位置
loc_x = e.Location.X;
loc_y = e.Location.Y;
}
}
/// <summary>
/// 鼠标移动,正在移动主窗口
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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;
}
}
/// <summary> /// <summary>
/// 关闭窗口 /// 关闭窗口
/// </summary> /// </summary>