0% found this document useful (0 votes)
18 views3 pages

Custom Dialog Box Implementation

Uploaded by

secpdivision
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views3 pages

Custom Dialog Box Implementation

Uploaded by

secpdivision
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

public static class Prompt

{
public static string ShowDialog(string text, string caption)
{
Form prompt = new Form()
{
Width = 400,
Height = 200,
FormBorderStyle = [Link],
Text = caption,
StartPosition = [Link]
};

Label textLabel = new Label() { Left = 20, Top = 20, Text = text,
Width = 340 };
TextBox textBox = new TextBox()
{
Left = 20,
Top = 50,
Width = 340,
Height = 60,
Multiline = true,
AcceptsReturn = false // disables default Enter newline
};

Button confirmation = new Button() { Text = "OK", Left = 280, Width


= 80, Top = 120, DialogResult = [Link] };

[Link] += (sender, e) => { [Link](); };


[Link](textBox);
[Link](confirmation);
[Link](textLabel);
//[Link] = confirmation;

// Handle Enter / Shift+Enter


[Link] += (sender, e) =>
{
if ([Link] == [Link])
{
if ([Link])
{
// Shift+Enter → add newline
int pos = [Link];
[Link] = [Link](pos,
[Link]);
[Link] = pos +
[Link];
[Link] = true;
}
else
{
// Enter → trigger OK button
[Link] = true;
[Link]();
}
}
};

return [Link]() == [Link] ? [Link] : "";


}
}

[Link]

Public NotInheritable Class Prompt


Private Sub New()
End Sub

Public Shared Function ShowDialog(text As String, caption As String) As String


Dim prompt As New Form() With {
.Width = 400,
.Height = 200,
.FormBorderStyle = [Link],
.Text = caption,
.StartPosition = [Link]
}

Dim textLabel As New Label() With {


.Left = 20,
.Top = 20,
.Text = text,
.Width = 340
}

Dim textBox As New TextBox() With {


.Left = 20,
.Top = 50,
.Width = 340,
.Height = 60,
.Multiline = True,
.AcceptsReturn = False
}

Dim confirmation As New Button() With {


.Text = "OK",
.Left = 280,
.Width = 80,
.Top = 120,
.DialogResult = [Link]
}

AddHandler [Link], Sub(sender, e) [Link]()

[Link](textBox)
[Link](confirmation)
[Link](textLabel)
'[Link] = confirmation 'disabled so Shift+Enter won't close

' Handle Enter / Shift+Enter


AddHandler [Link],
Sub(sender, e As KeyEventArgs)
If [Link] = [Link] Then
If [Link] Then
' Shift+Enter → add newline
Dim pos As Integer = [Link]
[Link] = [Link](pos,
[Link])
[Link] = pos + [Link]
[Link] = True
Else
' Enter → trigger OK button
[Link] = True
[Link]()
End If
End If
End Sub

Return If([Link]() = [Link], [Link], "")


End Function
End Class

You might also like