[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Change System Font in WinXP

Posted on 2004-11-01
12
Medium Priority
?
562 Views
Last Modified: 2013-12-03
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
0
Comment
Question by:vinhnl
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
12 Comments
 
LVL 18

Expert Comment

by:armoghan
ID: 12490717
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
 
LVL 8

Author Comment

by:vinhnl
ID: 12490978
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
 
LVL 18

Expert Comment

by:armoghan
ID: 12492397
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 8

Author Comment

by:vinhnl
ID: 12501325
No no, I can convert VB Struct to C# Struct. But Screen Object in C# have no Screen.Fonts Property.

VINHNL
0
 
LVL 18

Expert Comment

by:armoghan
ID: 12501543
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
 
LVL 18

Expert Comment

by:armoghan
ID: 12501549
Please do post the final code here if you can.. It would be a help to the community
Thanx
0
 
LVL 18

Expert Comment

by:armoghan
ID: 12702555
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
 
LVL 8

Author Comment

by:vinhnl
ID: 12714082
Would you write this method (Change Fonts of Windows appearence) for me? If you can do that, I will accept you!

VINHNL
0
 
LVL 18

Accepted Solution

by:
armoghan earned 2000 total points
ID: 12714310
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

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question