Design A Menu Based Vb.net program

lynn09

Member
Joined
Sep 15, 2004
Messages
17
Programming Experience
Beginner
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??:confused: :mad:
 
Private Sub MenuItem6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem6.Click



If MenuItem6.Text = "Small" Then

TextBox1.Text = "Small"

End If

End Sub

Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem2.Click

End Sub

Private Sub MenuItem7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem7.Click

If MenuItem7.Text = "Medium" Then

TextBox1.Text = "Medium"

End If

End Sub

Private Sub MenuItem8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem8.Click

If MenuItem8.Text = "Large" Then

'TextBox1.FontSize = 18

'TextBox1.Text = "Large"

End If





so far..i onli managed to make the wordings appear but as to the coding as of hw to make the font face n size change according to the menu as i click it..i m confused with it..the codings to the font size and face i couldnt get it..can some1 assist me?thanks so much:)
 
i mean when i click on the word small,medium,large..then font size could be changed accordingly..
must i use a fontdialog?
so far i was only able to make the words appear..but not the size change..can some1 assist me?thanks
 
To change the size of the textbox's font, use one of the overloaded constructors of the Font class. Here's an example:
VB.NET:
TextBox1.Font = New Font(TextBox1.Font.FontFamily, 20.0F, _
          TextBox1.Font.Style, GraphicsUnit.Point)
This will change the font size to 20 points.

Yes, fontFace is the design of the font (Arial, Times New Roman, ...)
Here's code that will load a comboBox with the font Families installed on the computer on which it is run:
VB.NET:
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
To change the fontFace of the textBox's font, handle the SelectedIndexChanged event of the comboBox and again use an overloaded contructor of the Font class, this time setting the FontFamily to the selected text in the comboBox.

Hope this helps.
 
wad if i use tis solution??
like Textbox1.Text=("Arial")'8,fontstyle,Italic or Fontstyle.Bold)

could someone tell mi wads wrong??

or is it like Textbox1.Font.Name()??

can some1 assist me on wad went wrong??
thanks :)
 
I do not understand why you still say you need help. You want to change the font size based on a menuitem. Paszt gave you the code to change the font style and size, just put it in the click event of your menuitem.....

VB.NET:
' 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....

What else do you need helkp with?

This is a help forum for programmming questions, and we do not mind helping, but we will not do people's homework assignments.....
 
i cant use the codes that u all have helped mi
i tried the codings for tis..
like
Textbox1.Font.Name()
Textbox1.Font.Size()
Textbox1.Font.Bold()

is there any changes i can do to tis??or wad should i add in??thanks
 
From the .NET Framework Documentation:

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)

I tested my own example using Visual Studio, so I know it works. If it does not work for you I suggest you typed something in wrong, or you are not using .NET 1.1
 
hey..thanks so much..but wad abt my solution for tis??cant work out using my solutioN??

Textbox1.Font.Name()
Textbox1.Font.Size()
Textbox1.Font.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.

till nw..i havent gotten the codings to apply on the font..but the method i got is already there..argh :(
 
Back
Top