Assigning Bold,Underline & Italic to a selected Text in a richtex 
Author Message
 Assigning Bold,Underline & Italic to a selected Text in a richtex

The FontStyle enumeration

enum FontStyle{
  FontStyleRegular    = 0,
  FontStyleBold       = 1,
  FontStyleItalic     = 2,
  FontStyleBoldItalic = 3,
  FontStyleUnderline  = 4,
  FontStyleStrikeout  = 8

Quote:
};

so to get any values in combination we can add these values and make the
following.
like 1 = Bold , 3 = Bold + Italic , 5 = Underline + Bold.

So for any combination add the above values to the style you require.

----------------------------------------------------------------------------
----------------------
example.

Below: We are using Toggle Buttons for Bold,Underline,Italic. You can do it
in checked menus or toggle buttons.

 on richtextbox1_SelectionChanged

 Dim currentfont As System.Drawing.Font = richtextbox1.SelectionFont
 ' To get the current font of the selection
 Dim newfontstyle As System.Drawing.FontStyle
 Dim fontid As Integer

  If btstyle = "ToggleButton" Then
        If tb.Buttons(7).Pushed And Not (tb.Buttons(8).Pushed) And Not
(tb.Buttons(9).Pushed) Then
               fontid = 1 ' for Bold only
        ElseIf Not (tb.Buttons(7).Pushed) And Not (tb.Buttons(8).Pushed) And
(tb.Buttons(9).Pushed) Then
               fontid = 2 ' for Italic only
        ElseIf tb.Buttons(7).Pushed And Not (tb.Buttons(8).Pushed) And
tb.Buttons(9).Pushed Then
               fontid = 3 ' for Bold and Italic
        ElseIf Not (tb.Buttons(7).Pushed) And tb.Buttons(8).Pushed And Not
(tb.Buttons(9).Pushed) Then
               fontid = 4 ' for Underline only
        ElseIf tb.Buttons(7).Pushed And tb.Buttons(8).Pushed And Not
(tb.Buttons(9).Pushed) Then
               fontid = 5 ' for Bold and Underline
        ElseIf Not (tb.Buttons(7).Pushed) And tb.Buttons(8).Pushed And
tb.Buttons(9).Pushed Then
               fontid = 6 ' for Italic and Underline
        ElseIf tb.Buttons(7).Pushed And tb.Buttons(8).Pushed And
tb.Buttons(9).Pushed Then
               fontid = 7 ' for Bold,Italic and Underline
        Else
               fontid = 0 ' for Regular
        End If
   newfontstyle = (fontid)
   richtextbox1.SelectionFont = New Font(currentfont.FontFamily,
currentfont.Size, newfontstyle)
 End If

----------------------------------------------------------------------------
----------------------

Arvind



Mon, 27 Sep 2004 13:41:25 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. bold, italic and underline buttons.

2. Help: replace bold, italic and underline

3. Applying a style turns off bold, italic, or underlining

4. Bold, italics, underline, strikeout at the same time

5. bold, underline and italic for a rtf-control

6. RFT to HTML Bold,Italic,Underline,Bullet

7. Toolbar icons (Bold, Underline, Italic, ...)

8. Bold/Italics and underline in an Editor box!!

9. bold, italic and underline buttons.

10. How to maintain Bold font and underline in Text replacement

11. Bolding and Underlining Text

12. Italic, bold...

 

 
Powered by phpBB® Forum Software