fonts - C# word like FormatPainter -


in microsoft office word there's function called format painter, copies properties of text (color, fontfamily & fontsize) , stores whilst waits next selection made, function need make in assignment school well, have no idea how this, i've tried store properties in variables , using them in selectionchanged function paste them on selected text, did not work need work, need work 1 in word, in richtextbox in c#

any appreciated.

i've tried this:

private bool copiedselection = false;          void formatpainter()         {             var fc = new fontconverter();             font f1 = new font(rtxtinhoud.selectionfont.fontfamily, rtxtinhoud.selectionfont.size);             color c1 = rtxtinhoud.selectioncolor;             var fontasstring = fc.converttoinvariantstring(f1);              font f2 = (font)fc.convertfrominvariantstring(fontasstring);             font = f2.tostring();             kleur = c1.tostring();             var color = regex.match(kleur, @"\[(.*?)\]").groups[1];             kleur = color.tostring();             copiedselection = true;          }  private void rtxtinhoud_selectionchanged(object sender, mouseeventargs e)     {         if (copiedselection == true && ))         {             rtxtinhoud.selectioncolor = colortranslator.fromhtml(kleur);         }         copiedselection = false;     } 

here short example, using 2 buttons: 1 store format data , 1 paint current selection stored format data.

the selectionchanged event calls second button , clears flag indicates format data loaded.

    bool loaded = false;      font sfont;     color scolor;     color sbackcolor;     float sfontsize;     horizontalalignment salign;     //..      private void cb_store_click(object sender, eventargs e)     {         loaded = true;         sfont = rtb.selectionfont;         scolor =   rtb.selectioncolor;         salign = rtb.selectionalignment;         sbackcolor = rtb.backcolor;         sfontsize = rtb.selectionfont.size;         //..     }      private void cb_paint_click(object sender, eventargs e)     {         rtb.selectionfont = sfont;         rtb.selectioncolor = scolor ;         rtb.selectionalignment = salign;         rtb.backcolor = sbackcolor;         rtb.selectionfont = new font(sfont.fontfamily, sfontsize);         //..     }      private void rtb_selectionchanged(object sender, eventargs e)     {         if (!loaded || rtb.selectionlength <= 0) return;         cb_paint_click(null, null);         loaded = false;     } 

note rtb richtextbox; few format data covered; there many more: selectionbullet, selectioncharoffset, selectionhangingindent, rtb.selectionindent, rtb.selectionrightindent

also note need clear flag on several other occasions!

you can replace cb_paint_click function, of course..


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -