0

Hello everybody. I am struggling with this issue, which is probably something simple. How do you change the font style and font size while a VB application is running? I want to to be able to choose a different font and size based on choices from the ToolStripComboBoxe(s). Any help would be greatly appreciated. Thanks

Craig

2
Contributors
10
Replies
14
Views
6 Years
Discussion Span
Last Post by Oxiegen
1
Dim FontName As String = "Arial"
Dim FontSize As Integer = 14
Dim FS As New Font(FontName, FontSize, FontStyle.Regular)
Me.Font = FS
0

After a little monkeying around with what you provided and what I had, I got the form to change font. Thank you very much. Can I assume that your code (modified a little) can be used to change the font size also? Thanks again. That little snippet of code was 4 hours of internet searching!

0

Sure. If you have a combobox full of different size-values, you can use those to set the size of the font. Dim FontSize As Integer = Cint(ComboSizes.Text)

0

One last question. Is there a way to have these modifications apply to an entire application and not just to the active form? Thanks again for ALL the help.

0

I'm thinking that's it's possible.
And I'm sure there is a very clever way of managing that.
That said, this is how I would do it:

Dim fontName As String = "Arial"
        Dim fontSize As Integer = 14
        Dim fontStyle As System.Drawing.FontStyle = Drawing.FontStyle.Regular
        Dim FS As New Font(fontName, fontSize, fontStyle)

        For Each frm As Form In Application.OpenForms
            frm.Font = FS
            frm.Invalidate()  '' Causes a repaint of the form to make sure that the change goes through.
        Next
0

Wow, you have been a lifesaver. Is there a way to change the background color just like the font was changed? I do not see any choices to change to except one color at a time. Better put, is there a color family to choose from just like there was a font family to choose from?

0

No, there's no Color family.
But there is a possibility for choosing colors, one at a time.
You can use a ColorDialog.

If ColorDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
    Dim c As Color = ColorDialog1.Color
    form.BackColor = c
End If

Or to put it the codesample I provided earilier:

Dim c As Color = System.Drawing.SystemColors.Control
        If ColorDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
            c = ColorDialog1.Color
        End If

        Dim fontName As String = "Arial"
        Dim fontSize As Integer = 14
        Dim fontStyle As System.Drawing.FontStyle = Drawing.FontStyle.Regular
        Dim FS As New Font(fontName, fontSize, fontStyle)

        For Each frm As Form In Application.OpenForms
            frm.BackColor = c
            frm.Font = FS
            frm.Invalidate()  '' Causes a repaint of the form to make sure that the change goes through.
        Next
0

This just keeps going! Ok, now that I have the color chosen from the ColorDialog and it has been applied to the forms, how do I get a color that is slightly darker (if a lighter color was chosen) or slightly lighter (if a darker color was chosen) for the various backcolors? i.e. if somebody chose blue, I want to automatically change the various backcolors to light blue so that the textboxes, listboxes, etc stand out more. This is a tall order and I greatly appreciate any help on this!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.