Reputation: 1832
Is there a way to detect and access properties of an active WinForm messagebox spawned from the MessageBox.Show() method within the same WinForm application?
Upvotes: 0
Views: 74
Reputation: 1832
MessageBox doesn't seem to have any exposed properties https://msdn.microsoft.com/en-us/library/system.windows.forms.messagebox%28v=vs.110%29.aspx. You might want to create a custom form to add and then read properties in it.
public class NewForm : Form
{
TextBox textProperty = new TextBox(); // <- it's actually a just field but you get the idea
public NewForm()
{
//can modify properties here or from the parent form which spawns this one
}
}
Upvotes: 1
Reputation: 374
If you mean window title and displayed message, you could use following code of mine
Public Shared Function GetDialogText() As String
Dim dialog As IntPtr = Diagnostics.Process.GetCurrentProcess.MainWindowHandle
Dim title = ""
Const WM_COPY As UInteger = &H301
WinDlls.SendMessage(dialog, WM_COPY, IntPtr.Zero, IntPtr.Zero)
Dim msg = My.Computer.Clipboard.GetText()
If Not msg.Contains("---") Then ' dialog not standard MessageBox
Dim sb As New System.Text.StringBuilder(1000)
WinDlls.GetWindowText(dialog, sb, sb.Capacity)
title = sb.ToString & ": "
End If
Return title & msg
End Function
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Public Shared Function SendMessage(hWnd As IntPtr, Msg As UInteger,
wParam As IntPtr, lParam As IntPtr) As IntPtr
End Function
Upvotes: 0