You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

165 lines
4.1 KiB
C#

using Rs.Controls;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Text;
using System.Linq;
using System.Reflection.Emit;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.VisualStyles;
namespace Rs.MotionPlat
{
public partial class BaseFormHeader : Form
{
private Color _HeaderBackgroundColor = Color.Black;
public Color HeaderBackgroundColor
{
get { return _HeaderBackgroundColor; }
set { _HeaderBackgroundColor = value;
tableLayoutPanel1.BackColor = value;
this.btnClose.BackColor = value;
this.btnMax.BackColor = value;
this.btnMin.BackColor = value;
}
}
private bool _ShowMin = true;
public bool ShowMin
{
get { return _ShowMin; }
set { _ShowMin = value; this.btnMin.Visible = value; }
}
private bool _ShowMax = true;
public bool ShowMax
{
get { return _ShowMax; }
set { _ShowMax = value;this.btnMax.Visible = value; }
}
private bool _ShowClose = true;
public bool ShowClose
{
get { return _ShowClose; }
set { _ShowClose = value; this.btnClose.Visible = value; }
}
private string _HeadText;
public string HeadText
{
get { return _HeadText; }
set { _HeadText = value;
this.lblHeaderText.Text = value;
}
}
Point startPoint;
Point endPoint;
Point curPoint;
bool pressed = false;
public BaseFormHeader()
{
InitializeComponent();
}
private void Head_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
if (e.Clicks == 2)
{
this.Close();
}
pressed = true;
curPoint = this.Location;
startPoint = e.Location;
}
}
private void Head_MouseMove(object sender, MouseEventArgs e)
{
if (pressed)
{
endPoint = e.Location;
int offsetX = endPoint.X - startPoint.X;
int offsetY = endPoint.Y - startPoint.Y;
curPoint.Offset(offsetX, offsetY);
this.Location = curPoint;
}
}
private void Head_MouseUp(object sender, MouseEventArgs e)
{
if (pressed)
{
pressed = false;
}
}
private void btnClose_Click(object sender, EventArgs e)
{
if (WindowsClose())
{
this.Close();
}
}
private void btnMin_Click(object sender, EventArgs e)
{
WindowState = FormWindowState.Minimized;
}
private void btnMax_Click(object sender, EventArgs e)
{
if(this.WindowState== FormWindowState.Normal)
{
this.btnMax.ButtonType = EButtonMode.NOMAL;
this.MaximizedBounds = Screen.PrimaryScreen.WorkingArea;
this.StartPosition = FormStartPosition.Manual;
this.WindowState = FormWindowState.Maximized;
}
else
{
this.btnMax.ButtonType = EButtonMode.MAX;
this.WindowState = FormWindowState.Normal;
}
}
protected void CloseWin(ControlCollection ctls)
{
foreach (Control ctl in ctls)
{
if (ctl is BaseForm)
{
((BaseForm)ctl).Close();
}
}
}
public virtual bool WindowsClose()
{
return true;
}
private void BaseFormHeader_Load(object sender, EventArgs e)
{
}
}
}