Can I change font size ?

I have made this simple application using vb.net2003 and xml database. My form on the text box display from the .xml database, I need to put a button so that a user can change the font size which is display on the form through text box which was taken from the xml database ie. make the fonts bigger or smaller when using the program and reading the text on my form.

Is there anyway I can make a command button which will change the font size on my program.
Would be grateful if someone throw a light on my problem.



  • seancampbellseancampbell Pennsylvania, USA
    Not sure if I am understanding what you are asking exactly, here is something to try and think about:

    Dim Size As Single = 11
    If IsNumeric(TextBox1.Text) Then
    Size = CType(TextBox1.Text, Single)
    End If

    Button1.Font = New Font("arial", Size, FontStyle.Regular, GraphicsUnit.Point)

    You can replace Button1.Font with the Object.Font of what you want to change, TextBox1.Text should replaced with the name of the textbox object you have.

    This code would go in the ButtonClick event.
  • seancampbellseancampbell Pennsylvania, USA
    Edit: oops, double posted
  • Many thanks. Can I make my character bold and italic too if my text file is in .xml and display those text through a text box on my form.
  • Well thanks for the response, but what i mean is to put a control button on my form so that i can change the font size i.e increase or decrease which is display on the text box. Can you give a hint or a small code to do that. Would be very grateful.

    Thanks anyway.
  • seancampbellseancampbell Pennsylvania, USA
    I think your wording is off a little. I think this is what you are looking for:

    Private Sub btnFontSize_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFontSize.Click
    Dim FD As New FontDialog
    Dim DiRes As DialogResult
    DiRes = FD.ShowDialog
    If DiRes = Windows.Forms.DialogResult.OK Then
    'They accepted the new font in the font Dialog
    TextBox1.Text = FD.Font.Size
    End If
    End Sub

    You will have to change the Button click even that this code is in, you will have to change TextBox1.Text to the text box you want to put the font in. You could have found this on google in 5 minutes...
    -Sean Campbell
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!