How to Change the Fonts in C#

This time, I’m going to teach you how to change the font using C#. This is just a very simple that can be easily learned by beginners. In this method you will be able to change the font in a textbox, there are lots of fonts to choose from and it depends on you which one will you choose according to your desire. So, let’s begin.

Creating Application

Step 1

Open Microsoft Visual Studio 2015 and create a new windows form application for c#. ps1

Step 2

Add a Richtexbox, button and a fontDialog into the form. Do the form just like shown below. ps2

Step 3

Press F7 to open the code editor. In the code editor, create a method for changing the fonts of a textbox.
  1.  
  2. private void Change_Font()
  3.         {
  4.             // Instantiate a new class
  5.             FontDialog fnt = new FontDialog();
  6.             fnt = fontDialog1;
  7.             //    'THE APPLY BUTTON APPEARS ON THE DIALOG BOX
  8.             fnt.ShowApply = true;
  9.             //    'SET THE EFFECTS TO BE SELECTED.
  10.             fnt.ShowEffects = true;  
  11.             //    'DON'T ALLOW SIMULATION, VECTOR FONTS OR VERTICAL FONTS.
  12.             //    ' THEN, LET THE USER CHANGE THE CHARACTER SET.
  13.             fnt.AllowScriptChange = true;
  14.             fnt.AllowSimulations = false;
  15.             fnt.AllowVectorFonts = false;
  16.             fnt.AllowVerticalFonts = false;
  17.             //    'SET THE FIXED AND PROPORTIONAL FONTS.
  18.             fnt.FixedPitchOnly = false;
  19.             //    'ALLOW ONLY FONTS THAT EXIST.
  20.             fnt.FontMustExist = true;
  21.             //    'SET THE MAXIMUM SIZE SELECTABLE FONT SIZE
  22.             fnt.MaxSize = 48;
  23.             //    'SET THE MINIMUM SIZE SELECTABLE FONT SIZE
  24.             fnt.MinSize = 8;
  25.             //    'SET UP THE REQUESTED FONTS.
  26.             if (fnt.ShowDialog() == DialogResult.OK)
  27.             {
  28.                 richTextBox1.Font = fnt.Font;
  29.             }
  30.         }

Step 4

Write the following code to execute the method that you have created when the button is clicked.
  1.    
  2.         private void button1_Click(object sender, EventArgs e)
  3.         {
  4.             Change_Font();
  5.         }
For any questions about this article. You can contact me @ Email – [email protected] Mobile No. – 09305235027 – TNT Or feel free to comment below.

Add new comment