Thursday, July 30, 2009

Visual Studio 2005 - Custom Font Size of a Textbox/Object Via Code?

'm using visual studio 2005, i'm doing a project in college and fairly new to the program. i'm using visual basic language (no C,c++,java, ect)





I currently have:





Dim number As Integer


number = Int(NumericUpDown1.TextAlign)


TextBox1.Font = New Font(FontFamily.GenericSansSerif, number)





Originally i only had:


TextBox1.Font = New Font(FontFamily.GenericSansSerif, 12.0F)


'This Worked Fine but limits me to only changing the font to one size per line of code.





The code i have now doesn't work, but its the area i'm looking at to fix the problem. i basically want the font in txt1 to be the size that is in the numeric value in txt2.





eg, txt2 = 12, then txt1's fontsize = 12





Any help would be greatly apreciatted.


Otherwise only thing i can think of is to create 72 different lines of code just for this :(

Visual Studio 2005 - Custom Font Size of a Textbox/Object Via Code?
So i decided to give this a shot, i opened up visual studio (vb.net) and created a new application to simulate your problem. I had two text boxes and a button that changed the font in TextBox1 to the number value in TextBox2 when clicked. This is the code i wrote in the button's click event.


Hope this helped you





'number should be of a single type not an integer type


'i also set a default just incase what ever is in textbox2


'wasn't numeric.





Dim number As Single = 8.0F





'i added a bit of error checking


'although it works without the if..then statement





If IsNumeric(TextBox2.Text) Then number = CSng(TextBox2.Text)





'this will change the font in TextBox1





TextBox1.Font = New Font(FontFamily.GenericSansSerif, number)
Reply:Dim number As Single = 10.0F


number = CSng(NumericUpDown1.Value)


TextBox1.Font = New Font(FontFamily.GenericSansSer... number)











.value saved it all - Thanks it works great now, couldn't have done it without your help Report It


wedding flowers

No comments:

Post a Comment