C# Button Control


CSharp.Net-Informations.com
SiteMap

Windows Forms controls are reusable components that encapsulate user interface functionality and are used in client side Windows applications. A button is a control, which is an interactive component that enables users to communicate with an application. The Button class inherits directly from the ButtonBase class. A Button can be clicked by using the mouse, ENTER key, or SPACEBAR if the button has focus.

button.jpg

When you want to change display text of the Button , you can change the Text property of the button.

  button1.Text = "Click Here";

Similarly if you want to load an Image to a Button control , you can code like this

  button1.Image = Image.FromFile("C:\\testimage.jpg");

The following C# source code shows how to change the button Text property while Form loading event and to display a message box when pressing a Button Control.


using System;
using System.Drawing;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            button1.Text = "Click Here";
        }

        private void button1_Click(object sender, EventArgs e)
        {
            MessageBox.Show("http://cshap.net-informations.com");
        }
    }
}







More Source Code :
|  Home  |   VB.NET  |   C#  |   ASP.NET  |   SiteMap  |   Terms of Use  |   About  |