c# RTB - paste plain text without colours/fonts?

前端 未结 10 1185
感动是毒
感动是毒 2021-02-06 07:42

I am using Rich Text object in my C# application. The only issue I am having is that when user pastes formated text from another app, it remains formated which I cannot have. Is

10条回答
  •  盖世英雄少女心
    2021-02-06 08:23

    Add a handler to the KeyDown-event to intercept the standard paste and manually insert only the plain text:

    private void rtb_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.Control && e.KeyCode == Keys.V)
        {
            ((RichTextBox)sender).Paste(DataFormats.GetFormat("Text"));
                e.Handled = true;
        }
    }
    

提交回复
热议问题