|
-
March 12th, 2008, 02:31 PM
#1
How do I make button text bold when the button is pressed?
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?
-
March 12th, 2008, 03:14 PM
#2
Re: How do I make button text bold when the button is pressed?
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
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
Hope this helps..
Gremmy.....
Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
WPF Articles : 3D Animation 1 , 2 , 3
Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.
-
March 12th, 2008, 03:52 PM
#3
Re: How do I make button text bold when the button is pressed?
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
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
March 13th, 2008, 01:39 AM
#4
Re: How do I make button text bold when the button is pressed?
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
-
March 13th, 2008, 08:00 AM
#5
Re: How do I make button text bold when the button is pressed?
 Originally Posted by irishman
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)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|