Results 1 to 10 of 10

Thread: [Resolved] - Make text bold?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2003
    Posts
    830

    [Resolved] - Make text bold?

    Hello,

    I know this is probably simple but I have been racking my brains on it so here you go...

    I want to click on a button and make the text in a label bold. How do I do it?

    Thanks!
    Last edited by birthjay; Jan 7th, 2004 at 09:03 PM.

  2. #2
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,539
    Dim myFont As New Font(Label1.Font.Name, Label1.Font.Size, FontStyle.Bold)
    Label1.Font = myFont

  3. #3
    Frenzied Member Memnoch1207's Avatar
    Join Date
    Feb 2002
    Location
    DUH, Guess...Hint: It's really hot!
    Posts
    1,861
    VB Code:
    1. Label1.Font = New Font(Label1.Font, FontStyle.Bold)
    Being educated does not make you intelligent.

    Need a weekend getaway??? Come Visit

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2003
    Posts
    830

    Thanks

    Thanks!

    Both of these work great. Can you tell me now how I can apply BOLD and UNDERLINE at the same time? As it is now, I have two buttons and when I click BOLD, it make the text BOLD. When I click UNDERLINE, the text becomes UNDERLINE but the BOLD goes away.

    Thanks!

  5. #5
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,539
    Dim myFont As New Font(Label1.Font.Name, Label1.Font.Size, FontStyle.Bold Or FontStyle.Underline)

    Label1.Font = myFont


    use this, to bring up the font dialog.
    i know next u will ask me how i can change the colour

    or strike it

    VB Code:
    1. Dim myFontDialog As FontDialog
    2.    myFontDialog = New FontDialog()
    3.    
    4.    If myFontDialog.ShowDialog() = DialogResult.OK Then
    5.       ' Set the control's font.
    6.       Label1.Font  = myFontDialog.Font
    7.    End If

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2003
    Posts
    830

    Thanks!

    Thank you, but I am not using the dialog box. I have created buttons for Bold, Italic, Underline, and Strikeout. The problem I am running into now is that I can only do one effect at a time.

    For example, if I click on Bold then I get Bold. If I click on Underline then I get Underline, but the Bold goes away.

    The way I want it to work is if I click on Bold, Italic, and Underline, I want the effects to stay. It is the same way the Microsoft Word handles it when you highlight text and then apply the Bold, Italic, etc.....to the text.

    I know I can do this by writing a lot of "If's" and "Then's", but is there a somewhat simple solution to this?

    Thanks!

  7. #7
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142
    try something like this ....
    VB Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.         Dim fs As New FontStyle()
    3.         fs = FontStyle.Regular
    4.         Label1.Font = New Font(Label1.Font.Name, Label1.Font.Size, fs)
    5.     End Sub
    6.  
    7.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    8.         Dim fs As New FontStyle()
    9.         fs = FontStyle.Italic
    10.         Label1.Font = New Font(Label1.Font.Name, Label1.Font.Size, fs)
    11.     End Sub
    12.  
    13.     Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
    14.         Dim fs As New FontStyle()
    15.         fs = FontStyle.Bold Or FontStyle.Italic
    16.         Label1.Font = New Font(Label1.Font.Name, Label1.Font.Size, fs)
    17.     End Sub
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2003
    Posts
    830

    Thanks

    Thank you, but that is pretty much what I have now.

    If I code it that way, I have to account for every state of each button. For example, if I want the text Bold, then I click on Bold, but what if I want the text Bold and Italic? Do I have to create a button just for that or should I check the state of the Bold button before pushing the Italic button? Well....you see the problem? I have to check the state of ALL the buttons (Bold, Italic, Underline, Strikeout, Regular) and then make a determination to how the font will look. It can be done of course, but I thought there might be a simple solution.

    Basically, I want it to work just like the buttons in Microsoft Word.

    Thanks!

  9. #9
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840
    Hi.

    Try this.

    VB Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.         Dim fs As FontStyle = Label1.Font.Style
    3.         fs = fs Xor FontStyle.Bold
    4.         Label1.Font = New Font(Label1.Font, fs)
    5.     End Sub
    6.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    7.         Dim fs As FontStyle = Label1.Font.Style
    8.         fs = fs Xor FontStyle.Underline
    9.         Label1.Font = New Font(Label1.Font, fs)
    10.     End Sub
    11.     Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
    12.         Dim fs As FontStyle = Label1.Font.Style
    13.         fs = fs Xor FontStyle.Italic
    14.         Label1.Font = New Font(Label1.Font, fs)
    15.     End Sub
    16.     Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
    17.         Dim fs As FontStyle = Label1.Font.Style
    18.         fs = fs Xor FontStyle.Strikeout
    19.         Label1.Font = New Font(Label1.Font, fs)
    20.     End Sub

    This will toggle the appropiate effect every time you press a button.
    I wish I could think of something witty to put in my sig...

    ...Currently using VS2013...

  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2003
    Posts
    830

    Thanks!

    Works like a champ!

    Thanks folks!

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