How to Change the Fonts in C#
Submitted by janobe on Wednesday, May 22, 2019 - 20:38.
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.
For any questions about this article. You can contact me @
Email – [email protected]
Mobile No. – 09305235027 – TNT
Or feel free to comment below.
Creating Application
Step 1
Open Microsoft Visual Studio 2015 and create a new windows form application for c#.
Step 2
Add a Richtexbox, button and a fontDialog into the form. Do the form just like shown below.
Step 3
Press F7 to open the code editor. In the code editor, create a method for changing the fonts of a textbox.- private void Change_Font()
- {
- // Instantiate a new class
- fnt = fontDialog1;
- // 'THE APPLY BUTTON APPEARS ON THE DIALOG BOX
- fnt.ShowApply = true;
- // 'SET THE EFFECTS TO BE SELECTED.
- fnt.ShowEffects = true;
- // 'DON'T ALLOW SIMULATION, VECTOR FONTS OR VERTICAL FONTS.
- // ' THEN, LET THE USER CHANGE THE CHARACTER SET.
- fnt.AllowScriptChange = true;
- fnt.AllowSimulations = false;
- fnt.AllowVectorFonts = false;
- fnt.AllowVerticalFonts = false;
- // 'SET THE FIXED AND PROPORTIONAL FONTS.
- fnt.FixedPitchOnly = false;
- // 'ALLOW ONLY FONTS THAT EXIST.
- fnt.FontMustExist = true;
- // 'SET THE MAXIMUM SIZE SELECTABLE FONT SIZE
- fnt.MaxSize = 48;
- // 'SET THE MINIMUM SIZE SELECTABLE FONT SIZE
- fnt.MinSize = 8;
- // 'SET UP THE REQUESTED FONTS.
- if (fnt.ShowDialog() == DialogResult.OK)
- {
- richTextBox1.Font = fnt.Font;
- }
- }
Step 4
Write the following code to execute the method that you have created when the button is clicked.- private void button1_Click(object sender, EventArgs e)
- {
- Change_Font();
- }
Add new comment
- 350 views