本文整理汇总了C#中System.Windows.Forms.TextBoxBase.SelectionStart属性的典型用法代码示例。如果您正苦于以下问题:C# TextBoxBase.SelectionStart属性的具体用法?C# TextBoxBase.SelectionStart怎么用?C# TextBoxBase.SelectionStart使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类System.Windows.Forms.TextBoxBase
的用法示例。
在下文中一共展示了TextBoxBase.SelectionStart属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Menu_Copy
private void Menu_Copy(System.Object sender, System.EventArgs e)
{
// Ensure that text is selected in the text box.
if(textBox1.SelectionLength > 0)
// Copy the selected text to the Clipboard.
textBox1.Copy();
}
private void Menu_Cut(System.Object sender, System.EventArgs e)
{
// Ensure that text is currently selected in the text box.
if(textBox1.SelectedText != "")
// Cut the selected text in the control and paste it into the Clipboard.
textBox1.Cut();
}
private void Menu_Paste(System.Object sender, System.EventArgs e)
{
// Determine if there is any text in the Clipboard to paste into the text box.
if(Clipboard.GetDataObject().GetDataPresent(DataFormats.Text) == true)
{
// Determine if any text is selected in the text box.
if(textBox1.SelectionLength > 0)
{
// Ask user if they want to paste over currently selected text.
if(MessageBox.Show("Do you want to paste over current selection?", "Cut Example", MessageBoxButtons.YesNo) == DialogResult.No)
// Move selection to the point after the current selection and paste.
textBox1.SelectionStart = textBox1.SelectionStart + textBox1.SelectionLength;
}
// Paste current text in Clipboard into text box.
textBox1.Paste();
}
}
private void Menu_Undo(System.Object sender, System.EventArgs e)
{
// Determine if last operation can be undone in text box.
if(textBox1.CanUndo == true)
{
// Undo the last operation.
textBox1.Undo();
// Clear the undo buffer to prevent last action from being redone.
textBox1.ClearUndo();
}
}
示例2: Form1
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.button1.Click += new System.EventHandler(this.ButtonClickWork);
}
private void ButtonClickWork(object sender, EventArgs e)
{
this.textBox1.Text = "Hello world!";
this.textBox1.ReadOnly = true;
this.textBox1.Focus();
this.textBox1.SelectionStart = this.textBox1.SelectionStart + 1;
this.textBox1.SelectionLength = 1;
}
}