private void hexTextBox_MouseDown(object sender, MouseEventArgs e) { DarkTextBox textBox = (DarkTextBox)sender; int index = textBox.GetCharIndexFromPosition(textBox.PointToClient(Cursor.Position)); int posStart = textBox.SelectionStart; char delimiter = ' '; int start = textBox.SelectionStart; if (start < 1) { start = 1; } int left = textBox.Text.LastIndexOf(delimiter, start - 1); int right = textBox.Text.IndexOf(delimiter, start); if (right == -1) { right = textBox.Text.Length; } textBox.SelectionStart = left + 1; textBox.SelectionLength = right - left - 1; }
public static string ShowDialog(string text, string caption) { Form prompt = new DarkForm { Width = 400, Height = 150, FormBorderStyle = FormBorderStyle.FixedToolWindow, Text = caption, StartPosition = FormStartPosition.CenterScreen }; DarkLabel textLabel = new DarkLabel() { Left = 50, Top = 15, Height = 50, Width = 300, Text = text }; DarkTextBox textBox = new DarkTextBox() { Left = 50, Top = 50, Width = 300 }; DarkButton confirmation = new DarkButton() { Text = "Ok", Left = 250, Width = 100, Top = 80, DialogResult = DialogResult.OK }; confirmation.Click += (sender, e) => { prompt.Close(); }; prompt.Controls.Add(textBox); prompt.Controls.Add(confirmation); prompt.Controls.Add(textLabel); prompt.AcceptButton = confirmation; return(prompt.ShowDialog() == DialogResult.OK ? textBox.Text : ""); }