Answered by:
Can I change The Font Size in a one line of Code?

Question
-
Hello All!
I want to do some sort of EASY change if it's possible with the Font Size!
My form has 3 buttons that sends Text to TextBox1. Their suppose to be
different sizes! I haven't been able to figure the Source Code to do it!
Can someone Help? Thanks for reading this post!
ifilikeituwill
Source Code for this small project follows!
Public Class FrmVB9_Font_Change_1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'Proposed Font Size 6 Here! TextBox1.Text = "This is Font Size 6 Change! " End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click 'Proposed Font Size 7 Here! TextBox1.Text = "This is Font Size 7 Change! " End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click 'Proposed Font Size 8 Here! TextBox1.Text = "This is Font Size 8 Change! " End Sub Private Sub ExitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitButton.Click End End Sub End Class
Wednesday, May 13, 2009 2:48 AM
Answers
-
Public Class FrmVB9_Font_Change_1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'Proposed Font Size 6 Here! Dim ft As Font ft = New Font("Arial", 6, FontStyle.Regular) TextBox1.Text = "This is Font Size 6 Change! " Textbox1.Font=ft End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click 'Proposed Font Size 7 Here! Dim ft As Font ft = New Font("Arial", 7, FontStyle.Regular) TextBox1.Text = "This is Font Size 7 Change! " Textbox1.Font=ft End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click 'Proposed Font Size 8 Here! Dim ft As Font ft = New Font("Arial", 8, FontStyle.Regular) TextBox1.Text = "This is Font Size 8 Change! " Textbox1.Font=ft End Sub Private Sub ExitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitButton.Click End End Sub End Class
Thanks,
A.m.a.L
.Net Goodies
[Remember to click "mark as answered" when you get a correct reply to your question]- Marked as answer by ifilikeituwill Wednesday, May 13, 2009 5:23 AM
Wednesday, May 13, 2009 5:00 AM
All replies
-
try this
Dim ft As Font
ft = New Font("Arial", 48, FontStyle.Regular) 'Arial is the name of the font, 48 is the size,you can change 48 to any size you want
Textbox1.Font=ft
kaymaf
I hope this helps, if that is what you want, just mark it as answer so that we can move on- Proposed as answer by A.m.a.L Hashim Wednesday, May 13, 2009 5:30 AM
Wednesday, May 13, 2009 3:27 AM -
Hi kaymaf!
Nope! Didn't work for me! Of coarse I don't have the foggiest idea where to put them in the program either!
Everyting I tried is a BIG NO!
Thanks for trying! (I don't consider this an answer yet!)
ifilikeituwill
Public Class FrmVB9_Font_Change_1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'Proposed Font Size 6 Here! TextBox1.Text = "This is Font Size 6 Change! " End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click 'Proposed Font Size 7 Here! TextBox1.Text = "This is Font Size 7 Change! " End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click 'Proposed Font Size 8 Here! TextBox1.Text = "This is Font Size 8 Change! " End Sub Private Sub ExitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitButton.Click End End Sub End Class
Wednesday, May 13, 2009 4:48 AM -
Public Class FrmVB9_Font_Change_1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'Proposed Font Size 6 Here! Dim ft As Font ft = New Font("Arial", 6, FontStyle.Regular) TextBox1.Text = "This is Font Size 6 Change! " Textbox1.Font=ft End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click 'Proposed Font Size 7 Here! Dim ft As Font ft = New Font("Arial", 7, FontStyle.Regular) TextBox1.Text = "This is Font Size 7 Change! " Textbox1.Font=ft End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click 'Proposed Font Size 8 Here! Dim ft As Font ft = New Font("Arial", 8, FontStyle.Regular) TextBox1.Text = "This is Font Size 8 Change! " Textbox1.Font=ft End Sub Private Sub ExitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitButton.Click End End Sub End Class
Thanks,
A.m.a.L
.Net Goodies
[Remember to click "mark as answered" when you get a correct reply to your question]- Marked as answer by ifilikeituwill Wednesday, May 13, 2009 5:23 AM
Wednesday, May 13, 2009 5:00 AM -
I just tested it, it works. I dont know why is not work on your side. even i use size 6 font
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Proposed Font Size 6 Here!
Dim ft As Font
ft = New Font("Arial", 24, FontStyle.Regular) 'Arial is the name of the font, 48 is the size,you can change 24 to any size you want
TextBox1.Font = ft
TextBox1.Text = "This is Font Size 6 Change! "
End Sub
kaymaf
- Edited by kaymaf Wednesday, May 13, 2009 5:07 AM
Wednesday, May 13, 2009 5:04 AM -
I just tested it, it works. I dont know why is not work on your side. even i use size 6 font
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Proposed Font Size 6 Here!
Dim ft As Font
ft = New Font("Arial", 24, FontStyle.Regular) 'Arial is the name of the font, 48 is the size,you can change 24 to any size you want
TextBox1.Font = ft
TextBox1.Text = "This is Font Size 6 Change! "
End Sub
kaymaf
It will work kaymaf, i think the OP was not sure where to place the code.
Thanks,
A.m.a.L
.Net Goodies
[Remember to click "mark as answered" when you get a correct reply to your question]Wednesday, May 13, 2009 5:15 AM -
Hello A.m.a.l. !
VERY, VERY, VERY NICELY ANSWERED!
Their was no room for error buy me the way the source was filled in by you!
Your a God send! Thanks! Thanks! Thanks for the help! It really looks neat
in the mini project too!
ifilikeituwill!Wednesday, May 13, 2009 5:28 AM -
Hi,
If you add one NumericUpDown Control to your FORM then you could use the value from that to change your FONT size with one control or change it then use a BUTTON to see the change.
Do you want to see more example code?
Here is the code by A.m.a.L written in fewer lines.>>
Public Class FrmVB9_Font_Change_1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'Proposed Font Size 6 Here! TextBox1.Text = "This is Font Size 6 Change! " Textbox1.Font = New Font("Arial", 6, FontStyle.Regular) End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click 'Proposed Font Size 7 Here! TextBox1.Text = "This is Font Size 7 Change! " Textbox1.Font = New Font("Arial", 7, FontStyle.Regular)) End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click 'Proposed Font Size 8 Here! TextBox1.Text = "This is Font Size 8 Change! " Textbox1.Font = New Font("Arial", 8, FontStyle.Regular) End Sub Private Sub ExitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitButton.Click End End Sub End Class
John- Edited by John Anthony Oliver Tuesday, May 19, 2009 12:06 PM
Tuesday, May 19, 2009 11:50 AM -
Hi again,
The above code even shorter like this.
Regards,
John
Public Class FrmVB9_Font_Change_1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click, Button2.Click, Button3.Click Select Case CType(sender, Control).Name 'Proposed Font Size 6 Here! Case "Button1" TextBox1.Text = "This is Font Size 6 Change! " Textbox1.Font = New Font("Arial", 6, FontStyle.Regular) Case "Button2" 'Proposed Font Size 7 Here! TextBox1.Text = "This is Font Size 7 Change! " Textbox1.Font = New Font("Arial", 7, FontStyle.Regular) Case "Button3" 'Proposed Font Size 8 Here! TextBox1.Text = "This is Font Size 8 Change! " Textbox1.Font = New Font("Arial", 8, FontStyle.Regular) End Select End Sub Private Sub ExitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitButton.Click End End Sub End Class
Tuesday, May 19, 2009 12:13 PM