Change System Font in WinXP

Hi Experts,

Now I'm using WinXP, .Net Framework 1.1. I want to read and change current system font in my System. Can you help me?

Thanks for all help.

VINHNL
LVL 8
vinhnlAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

armoghanCommented:
Question is unclear..
Do you mean the font of your application window only. That is simple. Set the font of the form from designer

or

Do you mean the Font of Windows. i.e. which you chnage by going to
Control Panel -> Display -> Appearnce

see this VB code and convert it into C#
http://www.quantumcloud.com/forum/viewtopic.php?p=3110
0
vinhnlAuthor Commented:
Hi  armoghan,

I want change the Fonts of Windows appearence  (Message, Menu, Caption Fonts ).

Your url maybe change Fonts of Windows appearence  in VB6. I can't convert it into C#.

Can someone help me?

VINHNL
0
armoghanCommented:
I am sorry, i cannot convert it for you right now..
See the following link , This might help you in converting it to VB.NET

http://www.codeguru.com/forum/showthread.php?t=308842&goto=nextnewest



I have converted the Types into structures
see this .. You have to convertthe rest of it .. Sorry



Private Structure LOGFONT
        Dim lfHeight As Long
        Dim lfWidth As Long
        Dim lfEscapement As Long
        Dim lfOrientation As Long
        Dim lfWeight As Long
        Dim lfItalic As Byte
        Dim lfUnderline As Byte
        Dim lfStrikeOut As Byte
        Dim lfCharSet As Byte
        Dim lfOutPrecision As Byte
        Dim lfClipPrecision As Byte
        Dim lfQuality As Byte
        Dim lfPitchAndFamily As Byte
        Dim lfFaceName As Byte()
        Sub New(ByVal ArraySize As Integer)
            ReDim lfFaceName(ArraySize)
        End Sub
    End Structure
    Private Structure NONCLIENTMETRICS
        Dim cbSize As Long
        Dim iBorderWidth As Long
        Dim iScrollWidth As Long
        Dim iScrollHeight As Long
        Dim iCaptionWidth As Long
        Dim iCaptionHeight As Long
        Dim lfCaptionFont As LOGFONT
        Dim iSMCaptionWidth As Long
        Dim iSMCaptionHeight As Long
        Dim lfSMCaptionFont As LOGFONT
        Dim iMenuWidth As Long
        Dim iMenuHeight As Long
        Dim lfMenuFont As LOGFONT
        Dim lfStatusFont As LOGFONT
        Dim lfMessageFont As LOGFONT
    End Structure

0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

vinhnlAuthor Commented:
No no, I can convert VB Struct to C# Struct. But Screen Object in C# have no Screen.Fonts Property.

VINHNL
0
armoghanCommented:
Ok, that problem I can solve
you need to use System.Drawing.Text.InstalledFontCollection to get the fonts instead of Screen.Fonts
see this link
http://www.c-sharpcorner.com/winforms/DisplayFontsJOD.asp
0
armoghanCommented:
Please do post the final code here if you can.. It would be a help to the community
Thanx
0
armoghanCommented:
All the help is provided. A working VB example which can be easily converted to .NET  
So would like to claim points for the question.
According to EE rules I do not want to provide the full working code. but if it is necessary. It can be done :)
0
vinhnlAuthor Commented:
Would you write this method (Change Fonts of Windows appearence) for me? If you can do that, I will accept you!

VINHNL
0
armoghanCommented:
Ok I tried to convert it to VB.NET. most of it is converted. It may have few problems and may not run "as is".

Imports System.Drawing
Imports System.Drawing.Text

Public Class Form1
    Inherits System.Windows.Forms.Form
    '<!--StartFragment-->'**************************************
    'Windows API/Global Declarations for :Change System (Message, Menu, Caption) Fonts
    Private Structure LOGFONT
        Dim lfHeight As Long
        Dim lfWidth As Long
        Dim lfEscapement As Long
        Dim lfOrientation As Long
        Dim lfWeight As Long
        Dim lfItalic As Byte
        Dim lfUnderline As Byte
        Dim lfStrikeOut As Byte
        Dim lfCharSet As Byte
        Dim lfOutPrecision As Byte
        Dim lfClipPrecision As Byte
        Dim lfQuality As Byte
        Dim lfPitchAndFamily As Byte
        Dim lfFaceName As Byte()
        Sub New(ByVal ArraySize As Integer)
            ReDim lfFaceName(ArraySize)
        End Sub
    End Structure
    Private Structure NONCLIENTMETRICS
        Public cbSize As Long
        Public iBorderWidth As Long
        Public iScrollWidth As Long
        Public iScrollHeight As Long
        Public iCaptionWidth As Long
        Public iCaptionHeight As Long
        Public lfCaptionFont As LOGFONT
        Public iSMCaptionWidth As Long
        Public iSMCaptionHeight As Long
        Public lfSMCaptionFont As LOGFONT
        Public iMenuWidth As Long
        Public iMenuHeight As Long
        Public lfMenuFont As LOGFONT
        Public lfStatusFont As LOGFONT
        Public lfMessageFont As LOGFONT

        Sub New(ByVal ArraySize As Integer)
            lfSMCaptionFont = New LOGFONT(ArraySize)
            lfCaptionFont = New LOGFONT(ArraySize)
            lfMenuFont = New LOGFONT(ArraySize)
            lfStatusFont = New LOGFONT(ArraySize)
            lfMessageFont = New LOGFONT(ArraySize)
        End Sub
    End Structure

    Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" (ByVal uAction As Integer, ByVal uParam As Integer, ByRef NONCLIENTMETRICS As Object, ByVal fuWinIni As Integer) As Integer
    '**************************************

    ' Inputs:ADD A COMBO BOX
    '
    ' Returns:Changes the Message box font a
    '    nd Windows Caption Font (Title Font).
    '
    'Assumes:Add a Combo box.
    '
    '**************************************


#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Public WithEvents ComboBox1 As System.Windows.Forms.ComboBox
    Friend WithEvents Button1 As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.ComboBox1 = New System.Windows.Forms.ComboBox
        Me.Button1 = New System.Windows.Forms.Button
        Me.SuspendLayout()
        '
        'ComboBox1
        '
        Me.ComboBox1.Location = New System.Drawing.Point(64, 80)
        Me.ComboBox1.Name = "ComboBox1"
        Me.ComboBox1.Size = New System.Drawing.Size(448, 21)
        Me.ComboBox1.TabIndex = 0
        Me.ComboBox1.Text = "ComboBox1"
        '
        'Button1
        '
        Me.Button1.Location = New System.Drawing.Point(72, 136)
        Me.Button1.Name = "Button1"
        Me.Button1.TabIndex = 1
        Me.Button1.Text = "Button1"
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(536, 266)
        Me.Controls.Add(Me.Button1)
        Me.Controls.Add(Me.ComboBox1)
        Me.Name = "Form1"
        Me.Text = "Form1"
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim i As Integer
        Show()
        Dim ifc As New InstalledFontCollection
        Dim ffs As FontFamily() = ifc.Families
        Dim f As Font


        For i = 0 To ffs.Length - 1 ' or use For i = 1 To Screen.FontCount to flood all the fonts in your pc
            Dim ff As FontFamily
            ff = ffs(i)
            If ff.IsStyleAvailable(System.Drawing.FontStyle.Regular) Then
                f = New Font(ff.GetName(1), 12, System.Drawing.FontStyle.Regular)
            ElseIf ff.IsStyleAvailable(System.Drawing.FontStyle.Bold) Then
                f = New Font(ff.GetName(1), 12, System.Drawing.FontStyle.Bold)
            ElseIf (ff.IsStyleAvailable(System.Drawing.FontStyle.Italic)) Then
                f = New Font(ff.GetName(1), 12, System.Drawing.FontStyle.Italic)
            Else
                f = New Font(ff.GetName(1), 12, System.Drawing.FontStyle.Underline)
            End If

            ComboBox1.Items.Add(f.Name)
        Next i
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim ncm As New NONCLIENTMETRICS(32)  'NONCLIENTMETRICS to change

        Dim Orincm As New NONCLIENTMETRICS(32) 'NONCLIENTMETRICS to replace original
        Dim Returned As Long
        'Dim xa As Integer = Len(ncm)
        'ncm.cbSize = xa
        Try
            Returned = SystemParametersInfo(41, 0, ncm, 0)   'get the system NONCLIENTMETRICS
        Catch ex As Exception
            Console.WriteLine(ex.StackTrace)
        End Try

        Orincm = ncm 'store the value of system NONCLIENTMETRICS to use later now to change the font name
        Console.WriteLine(Me.ComboBox1.Text)
        ncm.lfMessageFont.lfFaceName = System.Text.Encoding.ASCII.GetBytes(ComboBox1.Text)
        ncm.lfCaptionFont.lfFaceName = System.Text.Encoding.ASCII.GetBytes(ComboBox1.Text)

        'ncm.lfMessageFont.lfFaceName(i) = 0 'add null at the end of font name
        'ncm.lfCaptionFont.lfFaceName(i) = 0
        Returned = SystemParametersInfo(42, 0, ncm, &H1 Or &H2) 'remove &H2 if you don't want to affect all the open windows
        MsgBox("Message & Caption Font Changed to " & ComboBox1.Text, vbOKOnly)
        Returned = SystemParametersInfo(42, 0, Orincm, &H1 Or &H2) 'replace original font
        'MsgBox("Message & Caption Font Replaced to " & StrConv(System.Text.Encoding.ASCII.GetString(Orincm.lfCaptionFont.lfFaceName, 0, Orincm.lfCaptionFont.lfFaceName.Length), VbStrConv.None), vbOKOnly, "NILESH")
    End Sub

    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged

    End Sub
End Class
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Fonts Typography

From novice to tech pro — start learning today.