Results 1 to 7 of 7

Thread: Newbie Question...

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2000
    Posts
    16

    Post

    I have a form with a text box and three check boxes... One is called optBold one is called optItalic and the final is called optUnderline. When any of them is clicked then _all_ of the text in the text box is changed to either bold, italic, underline or a combination of all of them. What I really want is for the text in the box to stay the same and the next text that is typed to be underlined or bold or italic or whatever and so on... This is the main part of my code (I think I can remember it all)...

    Private Sub optBold_Click()

    If optBold Then txtMain.FontBold = True Else txtMain.FontBold = False

    End Sub

    ...and so on for optItalic_Click() and optUnderline_Click().

    Please help the newbie!
    Thanks in advance...

    Anton LaVey

  2. #2
    Hyperactive Member PITBULLCJR's Avatar
    Join Date
    Nov 1999
    Location
    New York
    Posts
    408

    Post

    I am not sure on what you mean but I think this is what you mean if not just email me or reply to this and hope I get it. Also you can not have 3 option buttons = true all at once unless you put them inside a fram so what I used is check Boxes so here it is.
    code:
    Private Sub Text1_Change()
    If Check1.Value = 1 Then
    Text1.FontBold = True
    Else
    Text1.FontBold = False
    End If
    If Check2.Value = 1 Then
    Text1.FontItalic = True
    Else
    Text1.FontItalic = False
    End If
    If Check3.Value = 1 Then
    Text1.FontUnderline = True
    Else
    Text1.FontUnderline = False
    End If
    End Sub

    I hope this helps

    ------------------
    Sincerely,
    Chris
    :-) ;-)
    Email [email protected]

  3. #3
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    If I understand you correctly you want to have text in the textbox of different styles, for example something like:

    Hello World

    If so, it's not possible with a standard Textbox, the Style used by the Textbox is used for all Text within it, so setting the Font Style to Italic, will make ALL the text in the textbox Italic.

    For what you want, you need to use the RichTextbox which allows you to format the Text, you can then use the SelBold and similar properties to change the Font Style of Blocks of Text within the Same Control.

    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]


  4. #4
    Hyperactive Member
    Join Date
    Jun 1999
    Location
    Calgary Alberta
    Posts
    359

    Post

    Even that will still Bold/Italic etc the whole text box. I assume that what you mean is that if I type in 'this', then check the Bold and type in 'is bold', you want the 'is bold' to be bolded and not the 'this'? I'm not sure if you can do this. It would be like changing fonts in the middle of the text box. I don't think it's possible to do that.

    Aaron beat me to it but I think you understand. :-)

    [This message has been edited by netSurfer (edited 01-11-2000).]

  5. #5
    Hyperactive Member PITBULLCJR's Avatar
    Join Date
    Nov 1999
    Location
    New York
    Posts
    408

    Post

    Oh now I see what you mean there is a way to do it you would have to say that the text in the text box is a string and then when the next stuff is typed as bold then add the old string with the new string and it would work. SO it is possible but will take a little bit of hard work. Well if you need any help doing it ask.

    ------------------
    Sincerely,
    Chris
    :-) ;-)
    Email [email protected]

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Jan 2000
    Posts
    16

    Post

    Yeah, thanks for the input ppl..!
    I have got check boxes and a frame around them (simply for clarity) but I use optBold because my teacher told me to, I guess they should be chkBold, etc.?

    Well, I can't understand why I can't do this - I don't mind whether I have to use a different control but I need to get this working some time soon... The suggestion above is a bit hard and would involve too much messy code in my opinion, thanks anyway. Any code examples would be good too!

    Thanks in advance (again)...

    Anton LaVey

  7. #7
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    Adda Richtextbox to a Form with 3 Checkboxes; (chkBold, chkItalic and chkUnderscore)..
    Code:
    Private bProg As Boolean
    
    Private Sub chkBold_Click()
        If bProg Then Exit Sub
        RichTextBox1.SelBold = chkBold
        RichTextBox1.SetFocus
    End Sub
    
    Private Sub chkItalic_Click()
        If bProg Then Exit Sub
        RichTextBox1.SelItalic = chkItalic
        RichTextBox1.SetFocus
    End Sub
    
    Private Sub chkUnderscore_Click()
        If bProg Then Exit Sub
        RichTextBox1.SelUnderline = chkUnderscore
        RichTextBox1.SetFocus
    End Sub
    
    Private Sub RichTextBox1_SelChange()
        With RichTextBox1
            bProg = True
            If Not IsNull(.SelBold) Then chkBold = Abs(.SelBold)
            If Not IsNull(.SelItalic) Then chkItalic = Abs(.SelItalic)
            If Not IsNull(.SelUnderline) Then chkUnderscore = Abs(.SelUnderline)
            bProg = False
        End With
    End Sub

    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]


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