i should design a textbox in the form which should accept the input from the user,Using the menu based interface,i must be able to change the font size and the font face..but i got quite confused with it..help anyone??
TextBox1.Font = New Font(TextBox1.Font.FontFamily, 20.0F, _
TextBox1.Font.Style, GraphicsUnit.Point)
Dim myFonts As Drawing.Text.InstalledFontCollection
myFonts = New Drawing.Text.InstalledFontCollection()
Dim family As FontFamily
For Each family In myFonts.Families
ComboBox1.Items.Add(family.Name)
Next
' This is the click event for small
Private Sub MenuItem1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles MenuItem1.Click
TextBox1.Font = New Font(TextBox1.Font.FontFamily, 6.0F, TextBox1.Font.Style, GraphicsUnit.Point)
End Sub
' This is medium
Private Sub MenuItem2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles MenuItem2.Click
TextBox1.Font = New Font(TextBox1.Font.FontFamily, 10.0F, TextBox1.Font.Style, GraphicsUnit.Point)
End Sub
' Etc....
Because the Font object is immutable (meaning that you cannot adjust any of it's properties), you can only assign the Font property a new Font object. However, you can base the new font on the existing font.
The following is an example of how to adjust the existing font to make it bold:
MyControl.Font = New Font(MyControl.Font, _
MyControl.Font.Style Or FontStyle.Bold)
Schenz said:You can retrieve values from TextBox1.Font, but you cannot change them. You must apply a new Font Object in order to change it.