无边框窗体状态的缩小问题

Keep_Silence_ 2012-08-29 09:13:39
在项目中有个无边框的窗体,添加了个按钮,此按钮的功能很简单,代码如下:

this.WindowState = FormWindowState.Minimized;


但是问题出现了,窗体缩小是缩小了,但是点击任务栏的图标是不能还原的,而有边框的窗体则没有这种问题,
请问我该如何解决或者改处理什么消息。
...全文
266 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
美丽的鸡翅膀 2012-09-29
  • 打赏
  • 举报
回复
学习了,刚好可以用上.
cry222222 2012-08-31
  • 打赏
  • 举报
回复
收藏了!
Keep_Silence_ 2012-08-31
  • 打赏
  • 举报
回复
自己找个个解决方案,下面贴出,让以后碰到这种问题的兄弟少走点弯路:


private const int WS_MINIMIZEBOX = 0x00020000;



protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
if (!DesignMode)
{
cp.Style |= WS_MINIMIZEBOX;
}
return cp;
}
}
wfl258 2012-08-30
  • 打赏
  • 举报
回复
我的可以啊
Keep_Silence_ 2012-08-30
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 的回复:]
C# code

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms……
[/Quote]
对不起 ,我少描述了一个,我的问题是这样做 即点击状态栏的图标他不能连续的缩小和还原,还原时可以还原,但是点击它之后就不能缩小到任务栏了 ,也不知道我描述清楚了没有。
newtee 2012-08-30
  • 打赏
  • 举报
回复
private void button1_Click(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Minimized;
}
newtee 2012-08-30
  • 打赏
  • 举报
回复
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ChangeFormSize
{
public partial class Frm_Main : Form
{
public Frm_Main()
{
InitializeComponent();
}

public static int Example_X = 0;
public static int Example_Y = 0;
public static int Example_W = 0;
public static Point CPoint;

#region 利用窗体上的控件移动窗体
/// <summary>
/// 利用控件移动窗体
/// </summary>
/// <param Frm="Form">窗体</param>
/// <param e="MouseEventArgs">控件的移动事件</param>
public void FrmMove(Form Frm, MouseEventArgs e) //Form或MouseEventArgs添加命名空间using System.Windows.Forms;
{
if (e.Button == MouseButtons.Left)
{
Point myPosittion = Control.MousePosition;//获取当前鼠标的屏幕坐标
myPosittion.Offset(CPoint.X, CPoint.Y);//重载当前鼠标的位置
Frm.DesktopLocation = myPosittion;//设置当前窗体在屏幕上的位置
}
}
#endregion

#region 获取鼠标的当前位置
/// <summary>
/// 获取鼠标的当前位置
/// </summary>
/// <param Frm="Form">窗体</param>
/// <param e="MouseEventArgs">窗体上有关鼠标的一些信息</param>
public void FrmScreen_SizeInfo(Form Frm, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
Example_X = e.X;
Example_Y = e.Y;
Example_W = Frm.Width;
}
}
#endregion

#region 改变窗体的大小(用于鼠标的移动事件)
/// <summary>
/// 改变窗体的大小(用于鼠标的移动事件)
/// </summary>
/// <param Frm="Form">窗体</param>
/// <param Pan="Panel">设置窗体边框的控件</param>
/// <param e="MouseEventArgs">窗体上有关鼠标的一些信息</param>
public void FrmScreen_EnlargeSize(Form Frm, Panel Pan, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
switch (Pan.Name)
{
case "panel_Right": //如果移动的是窗体的右边框
{
if (this.Width <= 70) //如果窗体的宽度小于等于70
{
Frm.Width = 70; //设置窗体的宽度为70
//如果用鼠标向右移动窗体的右边框
if (Cursor.Position.X - Frm.Left + (Pan.Width - Example_X) > Frm.Width)
{
//根据鼠标的移动值,增加窗体的宽度
Frm.Width = Cursor.Position.X - Frm.Left + (Pan.Width - Example_X);
}
break;
}
//根据鼠标的移动值,增加窗体的宽度
Frm.Width = Cursor.Position.X - Frm.Left + (Pan.Width - Example_X);
break;
}
case "panel_BR": //如果移动的是窗体的右下角
{
//如果窗体的大小不为窗体大小的最小值
if (this.Width > 70 && this.Height > (panel_Title.Height + panel_Bn.Height + 1))
{
//根据鼠标的移动改变窗体的大小
Frm.Height = Cursor.Position.Y - Frm.Top + (Pan.Height - Example_Y);
Frm.Width = Cursor.Position.X - Frm.Left + (Pan.Width - Example_X);
}
else
{
if (this.Width <= 70) //如果窗体的宽度小于等于最小值
{
Frm.Width = 70; //设置窗体的宽度为70
if (this.Height <= (panel_Title.Height + panel_Bn.Height + 1))//如果窗体的高小于最小值
{
Frm.Height = panel_Title.Height + panel_Bn.Height + 1;//设置窗体的最小高度
//如果用鼠标向下移动窗体的底边框
if (Cursor.Position.Y - Frm.Top + (Pan.Height - Example_Y) > Frm.Height)
{
//根据鼠标的移动值,增加窗体的高度
Frm.Height = Cursor.Position.Y - Frm.Top + (Pan.Height - Example_Y);
}
break;
}
//如果用鼠标向右移动窗体
if (Cursor.Position.X - Frm.Left + (Pan.Width - Example_X) > Frm.Width)
{
//增加窗体的宽度
Frm.Width = Cursor.Position.X - Frm.Left + (Pan.Width - Example_X);
}
break;
}
if (this.Height <= (panel_Title.Height + panel_Bn.Height + 1))//如果窗体的高度小于等于最小值
{
Frm.Height = panel_Title.Height + panel_Bn.Height + 1;//设置窗体的高度为最小值
Frm.Width = Cursor.Position.X - Frm.Left + (Pan.Width - Example_X);//改变窗体的宽度
//如果用鼠标向下移动窗体的边框
if (Cursor.Position.Y - Frm.Top + (Pan.Height - Example_Y) > Frm.Height)
{
Frm.Height = Cursor.Position.Y - Frm.Top + (Pan.Height - Example_Y);//增加窗体的高度
}
break;
}
}
break;
}
case "panel_Bn"://如果移动的是窗体的底边框
{
if (this.Height <= (panel_Title.Height + panel_Bn.Height + 1))//如果窗体的高度小于等于最小值
{
Frm.Height = panel_Title.Height + panel_Bn.Height + 1;//设置窗体的高度为最小值
//如果用鼠标向下移动窗体的下边框
if (Cursor.Position.Y - Frm.Top + (Pan.Height - Example_Y) > Frm.Height)
{
Frm.Height = Cursor.Position.Y - Frm.Top + (Pan.Height - Example_Y); //增加窗体的高度
}
break;
}
Frm.Height = Cursor.Position.Y - Frm.Top + (Pan.Height - Example_Y); //增加窗体的高度
break;
}
}
}
}
#endregion

private void panel_Right_MouseDown(object sender, MouseEventArgs e)
{
FrmScreen_SizeInfo(this, e);//获取鼠标的当前位置
}

private void panel_Right_MouseMove(object sender, MouseEventArgs e)
{
FrmScreen_EnlargeSize(this, (Panel)sender, e);//改变窗体的大小
}

private void pictureBox1_Click(object sender, EventArgs e)
{
this.Close();
}

private void panel_TitL_MouseDown(object sender, MouseEventArgs e)
{
int Tem_X = -e.X;
if (Convert.ToInt16(((Panel)sender).Tag.ToString()) == 2)//如果移动的是标题栏的中间部分
Tem_X = -e.X - panel_TitL.Width;
if (Convert.ToInt16(((Panel)sender).Tag.ToString()) == 3)//如果移动的是标题栏的尾端
Tem_X = -(this.Width - ((Panel)sender).Width) - e.X;
CPoint = new Point(Tem_X, -e.Y);
}

private void panel_TitL_MouseMove(object sender, MouseEventArgs e)
{
FrmMove(this, e);
}

private void button1_Click(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Minimized;
}


}
}
为什么我的可以呢?
wangxianshou 2012-08-29
  • 打赏
  • 举报
回复
应该是自带那个 -
和 你的这个代码是不一样的实现机制

110,545

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧