how do I feed an rtf string to a richtextbox control

后端 未结 2 1853
时光说笑
时光说笑 2021-01-18 05:19

I have a string of richtext characters/tokens that I would like to feed to a richtextbox in code.

string rt  = @\" {\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang         


        
相关标签:
2条回答
  • 2021-01-18 05:34

    Rich textbox has a property named Rtf. Set that property to your string value. Also, your string has an extra space as the first character. I had to remove that before I saw your Hello World.

    0 讨论(0)
  • 2021-01-18 05:46

    Expanding on gbogumil's answer:

    string rt  = @"{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fswiss\fcharset0     Arial;}{\f1\fnil\fprq2\fcharset0 Biondi;}}"+
    @"{\colortbl ;\red255\green0\blue0;}"+
    @"{\*\generator Msftedit 5.41.15.1507;}\viewkind4\uc1\pard\f0\fs20\par"+
    @"\cf1\f1 hello\cf0\f0  \ul world\par}";
    
    this.richTextBox1.Rtf = rt;
    
    0 讨论(0)
提交回复
热议问题