how to disable copy, Paste and delete features on a textbox using C#

前端 未结 6 793
既然无缘
既然无缘 2020-11-27 04:57

Can anybody please suggest how to handle Cut,Copy and Paste events on a Text Box in WinForms using C#?

6条回答
  •  感情败类
    2020-11-27 05:27

    int cusorposition = m_TextBox1.SelectionStart;
    if (TextBox1.Text[0] == ' ')
    {
    //Trim Spaces at beginning.
          m_TextBox1.Text = m_TextBox1.Text.TrimStart(' ');
          m_TextBox1.Text = m_TextBox1.Text.TrimEnd(' ');
          m_TextBox1.SelectionStart = cusorposition ;
    }
    

    Hi I found a way how to get the current cursor position instead of handling cut, copy and Paste event in a text box named TextBox1.Here in the above I am keeping the backup of current Cursor Position and after trimming the extra spaces from the starting and from end position I am reassigning the current cursor position.

    Thanks to all who helped me to fix this problem.

提交回复
热议问题