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?
Printable View
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?
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'sHope this helps..Code: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
Gremmy.....
A little easier and with no "hack"...
Code: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
You can also do :
Code: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
Use two RadioButton instead of button.Quote:
Originally Posted by irishman
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)