Sunday, 14 June 2015

Change Control Font Size At Runtime / Dynamically Using C#.Net and VB.Net In Windows Application

6/14/2015 - By Pranav Singh 0

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.


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.


About the Author

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Get Updates

Subscribe to our e-mail newsletter to receive updates.

Share This Post

0 comments:

Please let me know your view

Free Ebooks


About Us

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Contact Us

For writing article in this website please send request by your

GMAIL ID: dotnetpools@gmail.com

Bugs and Suggestions

As we all know that this website is for sharing knowledge and providing proper solution. So while reading the article is you find any bug or if you have any suggestion please mail us at contact@aspdotnet-pools.com.

Partners


Global Classified : Connectseekers.com
© 2014 aspdotnet-pools.com Designed by Bloggertheme9.
back to top