This article will show you how you can change the label
control font size by clicking on button control using c#.net in windows
application.
Some of my previous articles are as follows: Export
GridView Data To Excel Sheet Using C#.Net In Windows Application, How
to Create a Code 128 Barcode Label Using windows Font in C# ,Windows
Application, How
To Get Enumerate Installed Fonts List In Your Computer Using C# Windows
Application, Copy
File In C# Windows Application, Blinking
Text in C#.Net Windows Application, Focus
on TextBox in C#.Net in Windows Application, Limit
OR Restrict Number of Characters in Textbox C#.Net In windows Application, AutoSuggest
DropDownList In Windows Application Using C#.Net, Random
Character and String Generation Using C#.Net, Windows Application and Linq.
So for this article first we will create a new windows application and add the below mention controls on form.
Now on button control click event add the below code.
C#.Net
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public
Form1()
{
InitializeComponent();
}
private
void button1_Click(object
sender, EventArgs e)
{
FontFamily
fontFamily = new FontFamily("Arial");
int
fontSize = Convert.ToInt32(ddlFontSize.SelectedItem);
Font
font = new Font(fontFamily,
fontSize, FontStyle.Regular, GraphicsUnit.Pixel);
label1.Font = font;
}
}
}
|
VB.Net
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Windows.Forms
Namespace WindowsFormsApplication2
Public Partial Class Form1
Inherits
Form
Public
Sub New()
InitializeComponent()
End
Sub
Private
Sub button1_Click(sender As Object, e As EventArgs)
Dim
fontFamily As New
FontFamily("Arial")
Dim
fontSize As Integer
= Convert.ToInt32(ddlFontSize.SelectedItem)
Dim
font As New
Font(fontFamily, fontSize, FontStyle.Regular, GraphicsUnit.Pixel)
label1.Font = font
End
Sub
End Class
End Namespace
|
In above code I have first assign the font and after that I have
taken the font size from dropdown list. Now we have done run the application
and check the output.
0 comments:
Please let me know your view