This article will show you how you can dynamically change form
background color on button clink using c#.net in windows application. In this I
have used windows form button control and c# to write code.
Some of my previous articles are as follows: Dynamically
Add Textbox Control in Panel and Clear All on Single Click Using C#.Net in
Windows Application, Confirmation
Message on Button Click and Capture YES/NO Click by User in Windows
application, C#, Error
Handling in Windows Application Using C#.Net, Restrict
User to Enter Only Negative, Non-Negative and Decimal Number in TextBox Using
C#.Net in Windows Application, Dynamically
Add textbox control on button click in windows application using C#.net and
VB.net, Paging
in DataGridview Using C#.Net In Windows Application, Show
Progressbar While Moving Folder File From One Directory To Other Using C#.Net
In Windows Application.
So for this article first we will create a new windows application and add button controls to generate click event.
You’re for design will be as shown below.
Now add the below code on button click event.
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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
public
Form1()
{
InitializeComponent();
}
private
void button1_Click(object
sender, EventArgs e)
{
this.BackColor
= Color.Red;
}
private
void button2_Click(object
sender, EventArgs e)
{
this.BackColor
= Color.Green;
}
private
void button3_Click(object
sender, EventArgs e)
{
this.BackColor
= Color.Blue;
}
private
void button4_Click(object
sender, EventArgs e)
{
this.BackColor
= Color.Pink;
}
}
}
|
Please check the above code. In above code I have assign the
backcolor property with a color.
So we have done have a look for the output.
0 comments:
Please let me know your view