一个窗体最小化了,如何用代码让它恢复到原来的状态呢?

zsdlOO 2010-09-06 04:00:04
一个窗体最小化了,如何用代码让它恢复到原来的状态呢?
------------------------------------

我已经实现了,让一个窗口以单例模式打开,现在有一个问题。
如果用户将窗口最小化了(注意,没有关闭,是最小化),可是用户不知道这个窗口是最小化,以后没有打开,所以再次
执行打开操作,可是这个窗口无法恢复到最小化前的状态。

所以我想实现,让这个最小化的窗口恢复到刚才的显示状态,如何用代码实现呢?
...全文
990 10 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
dancingbit 2010-09-06
  • 打赏
  • 举报
回复
不嫌麻烦的话,可以看看这个:
http://www.cnblogs.com/dancingbit/archive/2010/08/11/1797685.html
无论窗口是何种状态,都能正确地恢复。
hui_hui_2007 2010-09-06
  • 打赏
  • 举报
回复
frm.WindowState = FormWindowState.Normal;
garfieldzf 2010-09-06
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 libinguest 的回复:]
错了:用下面这个


C# code
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Diagnostics;
using System.Runtime.InteropServices;

namespace WindowsApplication1
……
[/Quote]

learning!
风之影子 2010-09-06
  • 打赏
  • 举报
回复
错了:用下面这个

using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Diagnostics;
using System.Runtime.InteropServices;

namespace WindowsApplication1
{
static class Program
{
[DllImport("user32.dll", EntryPoint="ShowWindow")]
public static extern int ShowWindow(IntPtr hwnd, int nCmdShow);
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Process[] p = Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName);
//防止程序启动多次,只有一个运行的实例
if (p.Length > 1)
{
//将之前启动的窗体显示出来。
ShowWindow(p[1].MainWindowHandle, 1);
return;//退出软件
}
//正常情况下的窗体显示
Application.Run(new Form1());
}

}
}
chokobo 2010-09-06
  • 打赏
  • 举报
回复
最小化的时候把窗口的位置大小等保存下来,再次打开的时候恢复一下不就行了。
chen307418756 2010-09-06
  • 打赏
  • 举报
回复
[DllImport("User32.dll")]
public static extern bool ShowWindowAsync(IntPtr hWnd, int cmdShow);

ShowWindowAsync(childHwnd, 1);
风之影子 2010-09-06
  • 打赏
  • 举报
回复
using System; 
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Diagnostics;
using System.Runtime.InteropServices;

namespace WindowsFormsApplication2
{
static class Program
{
[DllImport("user32.dll", EntryPoint = "SetForegroundWindow")]
public static extern int SetForegroundWindow(IntPtr hwnd);

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Process[] p = Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName);
//防止程序启动多次,只有一个运行的实例
if (p.Length > 1)
{
//将之前启动的窗体显示出来。
SetForegroundWindow(p[1].MainWindowHandle);
return;//退出软件
}
//正常情况下的窗体显示
Application.Run(new Form1());
}
}
}
glest 2010-09-06
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 glest 的回复:]

引用 1 楼 glest 的回复:

frm.WindowState = FormWindowState.Normal;


打开方法中调用。
[/Quote]

加上:
frm.Activate();//激活
glest 2010-09-06
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 glest 的回复:]

frm.WindowState = FormWindowState.Normal;
[/Quote]

打开方法中调用。
glest 2010-09-06
  • 打赏
  • 举报
回复
frm.WindowState = FormWindowState.Normal;

111,098

社区成员

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

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

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