Results 1 to 2 of 2

Thread: Word-styled application

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 1999
    Location
    Atlanta, GA
    Posts
    75

    Post

    I am trying to build an application that has some of the functionality of Word: the ability to change font color, font size, etc. of certain lines of text while leaving others alone. Any ideas of what control would be good for this? Thanks.

    Jay

  2. #2
    Addicted Member
    Join Date
    May 1999
    Location
    Californ-I- A
    Posts
    207

    Post

    It's very simple to do using the Rich Text Box control and the Common Dialog. Looks a little something like this...


    Private Sub mnuFont_Click()
    On Error GoTo cancelerror

    'Setup and show font dialog
    CommonDialog.FontName = currentRTF.SelFontName
    CommonDialog.FontSize = currentRTF.SelFontSize
    CommonDialog.FontBold = currentRTF.SelBold
    CommonDialog.FontItalic = currentRTF.SelItalic
    CommonDialog.FontUnderline = currentRTF.SelUnderline
    CommonDialog.FontStrikethru = currentRTF.SelStrikeThru
    CommonDialog.Color = currentRTF.SelColor
    CommonDialog.Flags = cdlCFScreenFonts Or cdlCFPrinterFonts Or cdlCFEffects
    CommonDialog.ShowFont

    'Apply new font to text
    currentRTF.SelFontName = CommonDialog.FontName
    currentRTF.SelFontSize = CommonDialog.FontSize
    currentRTF.SelBold = CommonDialog.FontBold
    currentRTF.SelItalic = CommonDialog.FontItalic
    currentRTF.SelUnderline = CommonDialog.FontUnderline
    currentRTF.SelStrikeThru = CommonDialog.FontStrikethru
    currentRTF.SelColor = CommonDialog.Color

    Exit Sub
    cancelerror:
    'User canceled common dialog. Do nothing.
    End Sub




    And of course you can add fonts to a combo box and put it on the toolbar, and a color dropdown, and toolbar buttons for bold, italic etc.





    Private Sub tlbFont_ButtonClick(ByVal Button As MSComctlLib.Button)
    Select Case Button.Key

    Case "BOLD" 'Toggle bold on text
    If Button.Value = tbrPressed Then
    currentRTF.SelBold = True
    Else
    currentRTF.SelBold = False
    End If

    Case "UNDERLINE" 'Toggle underline on text
    If Button.Value = tbrPressed Then
    currentRTF.SelUnderline = True
    Else
    currentRTF.SelUnderline = False
    End If

    Case "ITALIC" 'Toggle italic on text
    If Button.Value = tbrPressed Then
    currentRTF.SelItalic = True
    Else
    currentRTF.SelItalic = False
    End If

    'etc etc etc

    End Sub




    And then in the Rich Text Box's Change, Click, and KeyPress,events, call some function to update your controls.



    Private Sub UpdateRTFControls()
    With Toolbar1

    If currentRTF.SelBold = True Then .Buttons("BOLD").Value = tbrPressed
    If currentRTF.SelBold = False Then .Buttons("BOLD").Value = tbrUnpressed
    If currentRTF.SelUnderline = True Then .Buttons("UNDERLINE").Value = tbrPressed
    If currentRTF.SelUnderline = False Then .Buttons("UNDERLINE").Value = tbrUnpressed
    If currentRTF.SelItalic = True Then .Buttons("ITALIC").Value = tbrPressed
    If currentRTF.SelItalic = False Then .Buttons("ITALIC").Value = tbrUnpressed
    If currentRTF.SelAlignment = 0 Then .Buttons("LEFT").Value = tbrPressed
    If currentRTF.SelAlignment = 1 Then .Buttons("RIGHT").Value = tbrPressed
    If currentRTF.SelAlignment = 2 Then .Buttons("CENTER").Value = tbrPressed

    'etc etc etc

    End With
    End Sub





    Good luck
    Micah Carrick
    Visual Basic 6 SP5
    Visual Basic.NET
    Quixotix Software
    [email protected]
    Download QCM 1.0 - Intelligent ActiveX Control Management

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width