is there way to make the default messagebox ( MessageBox.Show()
) TopMost true which also stays on top even if the messagebox lost the focus? I don't want to create a custom one. Is there a way doing it by using SetWindowHook or something similar? I already researched a lot but all solutions I found were not working. Can someone help me out how to do this in VB.net or C#?
最简单的方法是调用MessageBox
函数并传递MB_SYSTEMMODAL
标志。
I got it. This will show a messagebox on top of all windows opened, doesn't matter if they have Topmost options or not, the messagebox appears always in front.
Public Enum MessageBoxResult As UInteger
Ok = 1
Cancel
Abort
Retry
Ignore
Yes
No
Close
Help
TryAgain
ContinueOn
Timeout = 32000
End Enum
Public Enum MessageBoxOptions As UInteger
SystemModal = &H1000
NoFocus = &H8000
SetForeground = &H10000
Topmost = &H40000
End Enum
<DllImport("user32.dll", EntryPoint:="MessageBoxW", SetLastError:=True, Charset:=CharSet.Unicode)> _
Public Shared Function MessageBox(hwnd As IntPtr, _
<MarshalAs(UnmanagedType.LPTStr)> lpText As String, _
<MarshalAs(UnmanagedType.LPTStr)> lpCaption As String, _
<MarshalAs(UnmanagedType.U4)> uType As MessageBoxOptions) As <MarshalAs(UnmanagedType.U4)> MessageBoxResult
End Function
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
MessageBox(IntPtr.Zero, TextBox2.Text, TextBox1.Text, MessageBoxButtons.OK Or MessageBoxOptions.SystemModal + MessageBoxOptions.Topmost + MessageBoxOptions.SetForeground + MessageBoxIcon.Information)
End Sub
End Class
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.