c# - How do I change the text in a RichTextBox size and removing the highlight on the text? -


this code. when open text file it's changing font size of text coloring text making highlight select text.

private void opentoolstripmenuitem1_click(object sender, eventargs e)         {             openfiledialog thedialog = new openfiledialog();             thedialog.title = "open text file";             thedialog.filter = "txt files|*.txt";             thedialog.initialdirectory = @"c:\";             if (thedialog.showdialog() == dialogresult.ok)             {                 string filename = thedialog.filename;                 richtextbox1.text = file.readalltext(filename);                 this.richtextbox1.selectionstart = 0;                 this.richtextbox1.selectionlength = this.richtextbox1.text.length;                 this.richtextbox1.selectionfont = new system.drawing.font("maiandra gd", 30);                 string s = richtextbox1.text;                 richtextbox1.clear();                 richtextbox1.text = s;             }         } 

i tried add this:

string s = richtextbox1.text; richtextbox1.clear(); richtextbox1.text = s; 

it did trick problem text it's original small size. tried before add this:

this.richtextbox.selectionstart = 0; this.richtextbox.selectionlength = richtextbox.text.length;      this.richtextbox.selectionbackcolor = color.white; 

but didn't it.

you changing text property directly.: richtextbox1.text = s; never or richtextbox1.text = file.readalltext(filename); if don't want mess formatting. see here rules!

change this

        if (thedialog.showdialog() == dialogresult.ok)         {             string filename = thedialog.filename;             richtextbox1.text = file.readalltext(filename);             this.richtextbox1.selectionstart = 0;             this.richtextbox1.selectionlength = this.richtextbox1.text.length;             this.richtextbox1.selectionfont = new system.drawing.font("maiandra gd", 30);             string s = richtextbox1.text;             richtextbox1.clear();             richtextbox1.text = s;         } 

to this:

        if (thedialog.showdialog() == dialogresult.ok)         {             string filename = thedialog.filename;             string s = file.readalltext(filename);              this.richtextbox1.selectionstart = 0;  // or wherever want insert..             this.richtextbox1.selectionlength = 0;             this.richtextbox1.selectionfont = new system.drawing.font("maiandra gd", 30);             this.richtextbox1.selectdtext = s;         } 

i don't know 'highlighting' mention inserting text outside of selection reverting text default font & attributes had set before..


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -