|
-
Jan 2nd, 2004, 10:19 PM
#1
Thread Starter
Fanatic Member
[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.
-
Jan 2nd, 2004, 10:35 PM
#2
Frenzied Member
Dim myFont As New Font(Label1.Font.Name, Label1.Font.Size, FontStyle.Bold)
Label1.Font = myFont
-
Jan 2nd, 2004, 10:51 PM
#3
Frenzied Member
VB Code:
Label1.Font = New Font(Label1.Font, FontStyle.Bold)
Being educated does not make you intelligent.
Need a weekend getaway??? Come Visit
-
Jan 3rd, 2004, 01:43 AM
#4
Thread Starter
Fanatic Member
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!
-
Jan 3rd, 2004, 02:10 AM
#5
Frenzied Member
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:
Dim myFontDialog As FontDialog
myFontDialog = New FontDialog()
If myFontDialog.ShowDialog() = DialogResult.OK Then
' Set the control's font.
Label1.Font = myFontDialog.Font
End If
-
Jan 7th, 2004, 07:56 AM
#6
Thread Starter
Fanatic Member
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!
-
Jan 7th, 2004, 08:18 AM
#7
try something like this ....
VB Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim fs As New FontStyle()
fs = FontStyle.Regular
Label1.Font = New Font(Label1.Font.Name, Label1.Font.Size, fs)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim fs As New FontStyle()
fs = FontStyle.Italic
Label1.Font = New Font(Label1.Font.Name, Label1.Font.Size, fs)
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim fs As New FontStyle()
fs = FontStyle.Bold Or FontStyle.Italic
Label1.Font = New Font(Label1.Font.Name, Label1.Font.Size, fs)
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]
-
Jan 7th, 2004, 08:39 AM
#8
Thread Starter
Fanatic Member
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!
-
Jan 7th, 2004, 04:15 PM
#9
Hi.
Try this.
VB Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim fs As FontStyle = Label1.Font.Style
fs = fs Xor FontStyle.Bold
Label1.Font = New Font(Label1.Font, fs)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim fs As FontStyle = Label1.Font.Style
fs = fs Xor FontStyle.Underline
Label1.Font = New Font(Label1.Font, fs)
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim fs As FontStyle = Label1.Font.Style
fs = fs Xor FontStyle.Italic
Label1.Font = New Font(Label1.Font, fs)
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Dim fs As FontStyle = Label1.Font.Style
fs = fs Xor FontStyle.Strikeout
Label1.Font = New Font(Label1.Font, fs)
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...
-
Jan 7th, 2004, 09:04 PM
#10
Thread Starter
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|