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

前端 未结 10 1186
感动是毒
感动是毒 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:28

    I achieved this by udpating the font and colour for the whole RTB when its contents are changed. This works fine for me as the entry box does not need to deal with huge amounts of text.

    public FormMain()
    {
        InitializeComponent();
        txtRtb.TextChanged += txtRtb_TextChanged;
    }
    
    void txtRtb_TextChanged(object sender, EventArgs e)
    {
        RichTextBox rtb = (RichTextBox)sender;
        rtb.SelectAll();
        rtb.SelectionFont = rtb.Font;
        rtb.SelectionColor = System.Drawing.SystemColors.WindowText;
        rtb.Select(rtb.TextLength,0);
    }
    

提交回复
热议问题