SpeakComputers.com
Home
Software
Electronics
Desktop Computers
Laptops
Games
Handheld Devices
Mobile Phones
Cameras
Camcorders
Printers
Books
Software Downloads 2012 Software Mac Software Security Student Editions Windows 7 Office 2010
ASP.NET C# VB.NET C++ .NET Infragistics DevComponents

Button Control.

The Button control can be used to initiate a function, confirm an entry, compare values and many other actions. The button can be clicked by the use of the mouse or if focused with the enter key or the space bar. The button can be disabled and only enabled under certain application conditions or changes.


Namespace: System.Windows.Forms
Assembly: Systems.Windows.Forms.dll

using System.Windows.Forms;
Calling: System.Windows.Forms.Button

Creating a new System.Windows.Forms.Button control.
Button button1 = new Button();

Adding the button control to a Windows form.
this.Controls.Add(button1);

Placing the button on the form at a specific location.
button1.Location = new Point(50, 50);

Assigning a text value to a button control.
button1.Text = "Enter";

Assigning a click event to the button control.
button1.Click+=new EventHandler(button1_Click);

Responding to the buttons click event.
private void button1_Click(object sender, EventArgs e)
{
//The MessageBox is part of the System.Windows.Forms namespace.
MessageBox.Show("HelloWorld");
}

Changing the background color of the button control.
button1.BackColor = System.Drawing.Color.Red;

To disable the button control.
button1.Enabled = false;
Here the Button control is still visible (partially faded) but will not respond to any events. To re-enable the Button control you would set the Enabled property to true. When adding the button control the default setting is for the control to be Enabled.

Adding an image to the Button control.
try
{
button1.Image = Image.FromFile(@"c:\Icons\helloworld.gif");
//Set the Image relationship.
button1.TextImageRelation = TextImageRelation.ImageBeforeText;
}
catch (System.IO.FileNotFoundException ex)
{
MessageBox.Show(ex.ToString());
}
The image can either be from a file or streamed via a datastream. Remember to ensure that the image exists.

To align the image for the button control.
button1.ImageAlign = ContentAlignment.MiddleLeft;

Computer Security
AntiVirus Software
Internet Security
Parental Controls
Backup & Recovery
Computer Protection
Anti Malware
Photo & Video
Photo & Video Editing
Video Music
Desktop Publishing
Professional Design
Home Publishing
Clipart
Business & Accounting
Accounting
Payroll
Check Printing
TAX
H&R Block
Microsoft Office
Design
Graphic Design
Home Design
Garden Design
Interior Design
Computer Aided Design
3D Design
Students & Teacher
Adobe
Microsoft Office
Dragon Naturally Speaking
Corel Draw
Serif
Student/Teacher Software
Copy Right 2006 SpeakComputers.com - All Rights Reserved.
Home About Privacy Policy Resouces