Last active
October 11, 2023 17:32
-
-
Save hqf00342/3872bbb34171d408642f08b1cc2a7703 to your computer and use it in GitHub Desktop.
Linqpad multiline textbox dialog
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// TextboxDialog for LINQPad | |
// You can use it anywhere by adding the following code to MyExtensions class on Linqpad6. | |
// Usage: | |
// var lines = MyExtensions.ReadLines() | |
// foreach (var line in lines) | |
// Console.WriteLine(line); | |
public static class MyExtensions | |
{ | |
// Write custom extension methods here. They will be available to all queries. | |
public static IEnumerable<string> ReadLines(string title = null) | |
{ | |
var win = new System.Windows.Window() { Width = 400, Height = 300, Title = title ?? string.Empty }; | |
var grid = new System.Windows.Controls.Grid(); | |
grid.RowDefinitions.Add(new System.Windows.Controls.RowDefinition() { Height = new System.Windows.GridLength(1, System.Windows.GridUnitType.Star) }); | |
grid.RowDefinitions.Add(new System.Windows.Controls.RowDefinition() { Height = new System.Windows.GridLength(36) }); | |
var margin3 = new System.Windows.Thickness(3); | |
var tbox = new System.Windows.Controls.TextBox() | |
{ | |
Margin = margin3, | |
AcceptsReturn = true, | |
AcceptsTab = true, | |
VerticalScrollBarVisibility = System.Windows.Controls.ScrollBarVisibility.Auto, | |
HorizontalScrollBarVisibility = System.Windows.Controls.ScrollBarVisibility.Auto, | |
}; | |
var btnOk = new System.Windows.Controls.Button() { Content = "OK", Margin = margin3, Width = 80 }; | |
var btnCancel = new System.Windows.Controls.Button() { Content = "Cancel", Margin = margin3, Width = 80 }; | |
btnOk.Click += (_, _) => { win.DialogResult = true; win.Close(); }; | |
btnCancel.Click += (_, _) => { win.DialogResult = false; win.Close(); }; | |
var sp = new System.Windows.Controls.StackPanel() | |
{ | |
Orientation = System.Windows.Controls.Orientation.Horizontal, | |
HorizontalAlignment = System.Windows.HorizontalAlignment.Right, | |
}; | |
sp.Children.Add(btnOk); | |
sp.Children.Add(btnCancel); | |
System.Windows.Controls.Grid.SetRow(tbox, 0); | |
System.Windows.Controls.Grid.SetRow(sp, 1); | |
grid.Children.Add(tbox); | |
grid.Children.Add(sp); | |
win.Content = grid; | |
return win.ShowDialog() == true ? tbox.Text.Split("\r\n") : new string[0]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment