[System.Runtime.InteropServices.DllImport("coredll")] public static extern bool ShowWindow(IntPtr hwnd, int nCmdShow); public const int SW_MINIMIZE = 6;拿去用。
问题算是解决了吧,但不算完美,我的解决办法是:先屏蔽了"最小化"按钮,然后是:TopMost=true;这样做是为了一,不让客户最小化窗体,那么就不会出现找不到窗体的问题,当然允许他们隐藏;二,让窗体总是显示在最前端,那么按"桌面"按钮,就不会把窗体隐去.总体上算是接受吧,但就是不那么好,有点别扭;不是不想让客户最小化,而是最小化后,窗体隐藏在左下角"开始"那里,而且还是靠边隐藏那种,要是不留意,还是会找不到窗体,可能是"隐藏"代码段那里有点小缺陷,但现在又找不到解决办法,希望大侠们教教我...我把控制"隐藏"的代码贴出来,大家看看: private void ConsoleForm_Load(object sender, EventArgs e) { System.Windows.Forms.Timer StopRectTimer = new System.Windows.Forms.Timer(); StopRectTimer.Tick += new EventHandler(timer1_Tick); StopRectTimer.Interval = 100; StopRectTimer.Enabled = true; } private void timer1_Tick(object sender, EventArgs e) { if (this.Bounds.Contains(Cursor.Position)) { switch (this.StopAanhor) { case AnchorStyles.Top: this.Location = new Point(this.Location.X, 0); break; case AnchorStyles.Left: this.Location = new Point(0, this.Location.Y); break; case AnchorStyles.Right: this.Location = new Point(Screen.PrimaryScreen.Bounds.Width - this.Width, this.Location.Y); break; } } else { switch (this.StopAanhor) { case AnchorStyles.Top: this.Location = new Point(this.Location.X, (this.Height - 3) * (-1)); break; case AnchorStyles.Left: this.Location = new Point((-1) * (this.Width - 3), this.Location.Y); break; case AnchorStyles.Right: this.Location = new Point(Screen.PrimaryScreen.Bounds.Width - 3, this.Location.Y); break; } } } internal AnchorStyles StopAanhor = AnchorStyles.None; private void mStopAnhor() { if (this.Top <= 0) { StopAanhor = AnchorStyles.Top; } else if (this.Left <= 0) { StopAanhor = AnchorStyles.Left; } else if (this.Left >= Screen.PrimaryScreen.Bounds.Width - this.Width) { StopAanhor = AnchorStyles.Right; } else { StopAanhor = AnchorStyles.None; } } private void ConsoleForm_LocationChanged(object sender, EventArgs e) { this.mStopAnhor(); }
这里有个隐藏的下载!我搜的!但是我没有用过!
前段时间写的隐藏类,靠左考上靠右的隐藏,都没问题
这里有含源码的例子,也没多少代码
{
if (this.WindowState == FormWindowState.Minimized)//最小化时才执行
{
this.Visible = false;//隐藏窗体
this.notifyIcon1.Visible = true;//显示托盘图标
this.notifyIcon1.Text = this.Text;//设置托盘文本
}
}
private void notifyIcon1_MouseClick(object sender, MouseEventArgs e)
{
if (this.ShowInTaskbar == false)
notifyIcon1.Visible = true;//icon显示
this.ShowInTaskbar = true;//窗体图标
this.Show();
this.Activate();
this.WindowState = FormWindowState.Normal;//恢复
}
public static extern bool ShowWindow(IntPtr hwnd, int nCmdShow);
public const int SW_MINIMIZE = 6;拿去用。
{
System.Windows.Forms.Timer StopRectTimer = new System.Windows.Forms.Timer();
StopRectTimer.Tick += new EventHandler(timer1_Tick);
StopRectTimer.Interval = 100;
StopRectTimer.Enabled = true;
}
private void timer1_Tick(object sender, EventArgs e)
{
if (this.Bounds.Contains(Cursor.Position))
{
switch (this.StopAanhor)
{
case AnchorStyles.Top:
this.Location = new Point(this.Location.X, 0);
break;
case AnchorStyles.Left:
this.Location = new Point(0, this.Location.Y);
break;
case AnchorStyles.Right:
this.Location = new Point(Screen.PrimaryScreen.Bounds.Width - this.Width, this.Location.Y);
break;
}
}
else
{
switch (this.StopAanhor)
{
case AnchorStyles.Top:
this.Location = new Point(this.Location.X, (this.Height - 3) * (-1));
break;
case AnchorStyles.Left:
this.Location = new Point((-1) * (this.Width - 3), this.Location.Y);
break;
case AnchorStyles.Right:
this.Location = new Point(Screen.PrimaryScreen.Bounds.Width - 3, this.Location.Y);
break;
}
}
}
internal AnchorStyles StopAanhor = AnchorStyles.None;
private void mStopAnhor()
{
if (this.Top <= 0)
{
StopAanhor = AnchorStyles.Top;
}
else if (this.Left <= 0)
{
StopAanhor = AnchorStyles.Left;
}
else if (this.Left >= Screen.PrimaryScreen.Bounds.Width - this.Width)
{
StopAanhor = AnchorStyles.Right;
}
else
{
StopAanhor = AnchorStyles.None;
}
}
private void ConsoleForm_LocationChanged(object sender, EventArgs e)
{
this.mStopAnhor();
}
显示出来了。如果是这样的话 说声。很好实现。我给你一个我写过的类似源码