Files
29WxOrder/Work/BaseForms/BaseGeneralForm.cs
T
2026-06-15 20:48:52 +08:00

296 lines
9.2 KiB
C#

using AllBase;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Work.BaseForms
{
public partial class BaseGeneralForm : BaseForm
{
const int WM_NCHITTEST = 0x0084;
const int HTLEFT = 10; //左边界
const int HTRIGHT = 11; //右边界
const int HTTOP = 12; //上边界
const int HTTOPLEFT = 13; //左上角
const int HTTOPRIGHT = 14; //右上角
const int HTBOTTOM = 15; //下边界
const int HTBOTTOMLEFT = 0x10; //左下角
const int HTBOTTOMRIGHT = 17; //右下角
protected bool Minimized { get { return this.pbMinBase.Visible; } set { this.pbMinBase.Visible = value; } }
protected override void WndProc(ref Message m)
{
switch (m.Msg)
{
case WM_NCHITTEST:
base.WndProc(ref m);
Point vPoint = new Point((int)m.LParam & 0xFFFF,
(int)m.LParam >> 16 & 0xFFFF);
vPoint = PointToClient(vPoint);
if (vPoint.X <= 5)
if (vPoint.Y <= 5)
m.Result = (IntPtr)HTTOPLEFT;
else if (vPoint.Y >= ClientSize.Height - 5)
m.Result = (IntPtr)HTBOTTOMLEFT;
else m.Result = (IntPtr)HTLEFT;
else if (vPoint.X >= ClientSize.Width - 5)
if (vPoint.Y <= 5)
m.Result = (IntPtr)HTTOPRIGHT;
else if (vPoint.Y >= ClientSize.Height - 5)
m.Result = (IntPtr)HTBOTTOMRIGHT;
else m.Result = (IntPtr)HTRIGHT;
else if (vPoint.Y <= 5)
m.Result = (IntPtr)HTTOP;
else if (vPoint.Y >= ClientSize.Height - 5)
m.Result = (IntPtr)HTBOTTOM;
break;
default:
base.WndProc(ref m);
break;
}
}
public BaseGeneralForm()
{
InitializeComponent();
this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
if (FileBase.Exists(BaseClass.ProgromLogoIco))
{
Image img = Image.FromFile(BaseClass.ProgromLogoIco);
pictureBox3.Image = img;
}
}
private void LcBaseForm_Load(object sender, EventArgs e)
{
if (BaseClass.Ico != null)
Iconx = Icon = BaseClass.Ico;
//else
// Iconx = Icon = BaseClass.Ico = ImageBuild.ConvertToIcon(Properties.Resources.icon);
if (this.IsShowMax)
{
if (this.WindowState == FormWindowState.Maximized)
{
this.pbMaxBase.Visible = false;
this.pbNormalBase.Visible = true;
}
else
{
this.pbMaxBase.Visible = true;
this.pbNormalBase.Visible = false;
}
}
SetPanelVisible(this.TopLevel || DesignMode);
}
public void SetPanelVisible(bool visible)
{
if (visible)
{
this.Padding = new Padding(1);
this.pnlTitle.Visible = true;
}
else
{
this.Padding = new Padding(0);
this.pnlTitle.Visible = false;
}
}
private void PictureBox2_Click(object sender, EventArgs e)
{
WindowState = FormWindowState.Minimized;
}
public virtual void PictureBox1_Click(object sender, EventArgs e)
{
//pictureBox3.Image?.Dispose();
Close();
}
private Icon _iconx;
public Icon Iconx
{
set
{
_iconx = value;
if (_iconx == null) return;
using (MemoryStream mStream = new MemoryStream())
{
_iconx.Save(mStream);
Image image = Image.FromStream(mStream);
pictureBox3.Image = image;
}
}
}
private bool isShowMax = false;
public bool IsShowMax
{
get { return isShowMax; }
set
{
isShowMax = value;
if (isShowMax)
{
if (this.WindowState == FormWindowState.Maximized)
{
this.pbMaxBase.Visible = false;
this.pbNormalBase.Visible = true;
}
else
{
this.pbMaxBase.Visible = true;
this.pbNormalBase.Visible = false;
}
}
else
{
this.pbMaxBase.Visible = false;
this.pbNormalBase.Visible = false;
}
}
}
public string TitleText
{
get
{
return Text;
}
set
{
Text = lbTitle.Text = value;
}
}
private Point mouseOffset;//记录鼠标指针的坐标
private bool isMouseDown;//记录鼠标左键是否按下
private void Panel1_MouseMove(object sender, MouseEventArgs e)
{
if (isMouseDown)
{//获取鼠标的位置
Point mousePos = MousePosition;
mousePos.Offset(mouseOffset.X, mouseOffset.Y);
Location = mousePos;
}
}
private void Panel1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
mouseOffset = new Point(-e.X, -e.Y);
isMouseDown = true;
}
}
private void Panel1_MouseUp(object sender, MouseEventArgs e)
{
isMouseDown = false;
}
private void PictureBox1_MouseHover(object sender, EventArgs e)
{
this.pbCloseBase.Image = global::Work.Properties.Resources.close_hover;
this.Cursor = Cursors.Hand;
}
private void PictureBox1_MouseLeave(object sender, EventArgs e)
{
this.pbCloseBase.Image = global::Work.Properties.Resources.close;
this.Cursor = Cursors.Default;
}
private void PictureBox2_MouseHover(object sender, EventArgs e)
{
this.pbMinBase.Image = global::Work.Properties.Resources.min_hover;
this.Cursor = Cursors.Hand;
}
private void PictureBox2_MouseLeave(object sender, EventArgs e)
{
this.pbMinBase.Image = global::Work.Properties.Resources.min;
this.Cursor = Cursors.Default;
}
public virtual void HideTitle()
{
// this.panel1.Visible = false;
}
#region 窗体提交数据完成事件
public event Action<object> SaveComplete;
protected virtual void OnSaveComplete(object param)
{
this.SaveComplete?.Invoke(param);
}
#endregion
private void pbNormalBase_Click(object sender, EventArgs e)
{
WindowState = FormWindowState.Normal;
this.pbMaxBase.Visible = true;
this.pbNormalBase.Visible = false;
}
private void pbNormalBase_MouseHover(object sender, EventArgs e)
{
this.pbNormalBase.Image = global::Work.Properties.Resources.normal_hover;
this.Cursor = Cursors.Hand;
}
private void pbNormalBase_MouseLeave(object sender, EventArgs e)
{
this.pbNormalBase.Image = global::Work.Properties.Resources.normal;
this.Cursor = Cursors.Default;
}
private void pbMaxBase_Click(object sender, EventArgs e)
{
WindowState = FormWindowState.Maximized;
this.pbMaxBase.Visible = false;
this.pbNormalBase.Visible = true;
}
private void pbMaxBase_MouseHover(object sender, EventArgs e)
{
this.pbMaxBase.Image = global::Work.Properties.Resources.max_hover;
this.Cursor = Cursors.Hand;
}
private void pbMaxBase_MouseLeave(object sender, EventArgs e)
{
this.pbMaxBase.Image = global::Work.Properties.Resources.max;
this.Cursor = Cursors.Default;
}
private Point mPoint;
private void panel2_MouseDown(object sender, MouseEventArgs e)
{
mPoint = new Point(e.X, e.Y);
}
private void panel2_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
this.Location = new Point(this.Location.X + e.X - mPoint.X, this.Location.Y + e.Y - mPoint.Y);
}
}
}
}