Click to See Complete Forum and Search --> : How do I make button text bold when the button is pressed?


irishman
March 12th, 2008, 02:31 PM
I have two buttons. When I press one button, I want it's text to become bold and the text of the other button to become "unbold."

Can anyone help me with this?

GremlinSA
March 12th, 2008, 03:14 PM
Well it might be a bit of a hack, but this does work....

Add two lables (or any other control) and set the visible to false...

On the first label set the font bold property to true, leave the second one normal, and add this code to your two button's Private Sub Button1_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.GotFocus
Button1.Font = Label1.Font
End Sub

Private Sub Button1_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.LostFocus
Button1.Font = Label2.Font
End Sub

Private Sub Button2_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.GotFocus
Button2.Font = Label1.Font
End Sub

Private Sub Button2_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.LostFocus
Button2.Font = Label2.Font
End Sub


Hope this helps..

Gremmy.....

PeejAvery
March 12th, 2008, 03:52 PM
A little easier and with no "hack"...

Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim newBold As New Font(Button1.Font.FontFamily, Button1.Font.Size, FontStyle.Bold)
Dim newRegular As New Font(Button1.Font.FontFamily, Button1.Font.Size, FontStyle.Regular)

Button1.Font = newBold
Button2.Font = newRegular

newBold.Dispose()
newRegular.Dispose()
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim newBold As New Font(Button1.Font.FontFamily, Button1.Font.Size, FontStyle.Bold)
Dim newRegular As New Font(Button1.Font.FontFamily, Button1.Font.Size, FontStyle.Regular)

Button2.Font = newBold
Button1.Font = newRegular

newBold.Dispose()
newRegular.Dispose()
End Sub
End Class

HanneSThEGreaT
March 13th, 2008, 01:39 AM
You can also do :
Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click, Button2.Click
ToggleStyle(Font.Bold)
End Sub

Private Sub ToggleStyle(ByVal style As FontStyle)
Dim Font1 As New Font(Button1.Font, Button1.Font.Style Xor style)
Dim Font2 As New Font(Button2.Font, Button2.Font.Style Xor style)

Button1.Font = Font2
Button2.Font = Font1
End Sub

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Button1.Font = New Font(Button1.Font, FontStyle.Bold)
End Sub
End Class

Marraco
March 13th, 2008, 08:00 AM
I have two buttons. When I press one button, I want it's text to become bold and the text of the other button to become "unbold."

Can anyone help me with this?
Use two RadioButton instead of button.
If you want them to look like button, set his Appearance property to "Button".
Each time you check one, the other will uncheck (And you can write the checked and unchecked events subroutines)