程序主要代码:[C#] 纯文本查看 复制代码 /// <summary>
/// 设置自定义最大化、最小化和关闭图片按钮的单击事件
/// </summary>
/// <param Frm_Tem="Form">窗体</param>
/// <param n="int">PictureBox的Tag标识</param>
public void FrmClickMeans(Form Frm, int n)
{
switch (n)//窗体的操作样式
{
case 1://窗体最小化
Frm.WindowState = FormWindowState.Minimized;//窗体最小化
break;
case 2://窗体最大化和还原的切换
{
if (Frm.WindowState == FormWindowState.Maximized)//如果窗体当前是最大化
Frm.WindowState = FormWindowState.Normal;//还原窗体大小
else
Frm.WindowState = FormWindowState.Maximized;//窗体最大化
break;
}
case 3: //关闭窗体
Frm.Close();
break;
}
}
/// <summary>
/// 控制图片的切换状态
/// </summary>
/// <param sender =" object ">要改变图片的对象</param>
/// <param n="int">标识</param>
/// <param ns="int">移出移入标识</param>
public static PictureBox Tem_PictB = new PictureBox();//实例化PictureBox控件
public void ImageSwitch(object sender, int n, int ns)
{
Tem_PictB = (PictureBox)sender;
switch (n)//获取标识
{
case 1://当前为最小化按钮
{
Tem_PictB.Image = null;//清空图片
if (ns == 0)//鼠标移入
Tem_PictB.Image = Properties.Resources.最小化变色;
if (ns == 1)//鼠标移出
Tem_PictB.Image = Properties.Resources.最小化按钮;
break;
}
case 2://最大化按钮
{
Tem_PictB.Image = null;
if (ns == 0)
Tem_PictB.Image = Properties.Resources.最大化变色;
if (ns == 1)
Tem_PictB.Image = Properties.Resources.最大化按钮;
break;
}
case 3://关闭按钮
{
Tem_PictB.Image = null;
if (ns == 0)
Tem_PictB.Image = Properties.Resources.关闭变色;
if (ns == 1)
Tem_PictB.Image = Properties.Resources.关闭按钮;
break;
}
}
}
Point mouseOff;//鼠标移动位置变量
bool leftFlag;//标签是否为左键
private void frm_Main_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
mouseOff = new Point(-e.X, -e.Y); //得到变量的值
leftFlag = true; //点击左键按下时标注为true;
}
}
private void frm_Main_MouseMove(object sender, MouseEventArgs e)
{
if (leftFlag)
{
Point mouseSet = Control.MousePosition;
mouseSet.Offset(mouseOff.X, mouseOff.Y); //设置移动后的位置
Location = mouseSet;
}
}
private void frm_Main_MouseUp(object sender, MouseEventArgs e)
{
if (leftFlag)
{
leftFlag = false;//释放鼠标后标注为false;
}
}
|