当窗口恢复时,C#中是否引发了一个事件? [英] Is there an event raised in C# when a window is restored?
问题描述
我注意到有一个事件是在一个窗口是激活,但是我找不到要恢复的窗口的相应事件,例如从最大化或最小化状态。
如果您不喜欢使用窗体的 WindowState
属性,并且不希望保留指示窗体以前状态的标志,则可以在
您需要覆盖窗体的窗口过程( WndProc
)并收听 WM_SYSCOMMAND
消息指示 SC_RESTORE
。例如:
protected override void WndProc(ref Message m)
{
const int WM_SYSCOMMAND = 0x0112 ;
const int SC_RESTORE = 0xF120;
if(m.Msg == WM_SYSCOMMAND&&(int)m.WParam == SC_RESTORE)
{
//做任何你需要的处理,或者提高一个事件
// ...
MessageBox.Show(Window was restored);
}
base.WndProc(ref m);
}
Is there any event that is raised when a window is restored in C#/.NET?
I noticed that there is an event that is raised when a window is activated, but I can't find a corresponding event for a window being restored, such as from a maximized or minimized state.
If you don't like using the form's WindowState
property and don't want to have to keep around a flag indicating the form's previous state, you can achieve the same result at a slightly lower level.
You'll need to override your form's window procedure (WndProc
) and listen for a WM_SYSCOMMAND
message indicating SC_RESTORE
. For example:
protected override void WndProc(ref Message m)
{
const int WM_SYSCOMMAND = 0x0112;
const int SC_RESTORE = 0xF120;
if (m.Msg == WM_SYSCOMMAND && (int)m.WParam == SC_RESTORE)
{
// Do whatever processing you need here, or raise an event
// ...
MessageBox.Show("Window was restored");
}
base.WndProc(ref m);
}
这篇关于当窗口恢复时,C#中是否引发了一个事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!