Hi all
I have created a custom buttom round in shape .Now i want the color of the button to be changed at the mouse click of the button .
using System.Windows.Forms;
using System.Drawing;
using System;
using MyNamespace;
public class MyForm : Form
{
public MyForm()
{
RoundButton roundButton = new RoundButton();
MouseEventHandler handler = new MouseEventHandler(roundButton_MouseClick);
roundButton.MouseClick += handler;
roundButton.backgroundColor = System.Drawing.Color.White;
roundButton.Size = new System.Drawing.Size(50, 50);
roundButton.Location = new System.Drawing.Point(100, 30);
this.Controls.Add(roundButton);
}
public void roundButton_MouseClick(Object source, System.Windows.Forms.MouseEventArgs e)
{
Color backgroundColor = Color.Red;
Graphics graphics = CreateGraphics();
int penWidth = 4;
Pen pen = new Pen(Color.Green, 4);
SolidBrush brush = new SolidBrush(backgroundColor);
graphics.FillEllipse(brush, 0, 0, Width, Height);
graphics.DrawEllipse(pen, (int)penWidth / 2,
(int)penWidth / 2, Width - penWidth, Height - penWidth);
graphics.DrawLine(pen, 26, 15, 26, 30);
graphics.DrawArc(pen, (this.Width / 4), (this.Height / 2), (this.Width / 2), (this.Height / 4), 0, 180); // Mouth
}
}
using System.Windows.Forms;
using System.Drawing;
using System.ComponentModel;
namespace MyNamespace
{
[Description("Button Control")]
[ToolboxBitmap(typeof(Button))]
[Designer(typeof(RoundButton))]
public class RoundButton : UserControl
{
public Color backgroundColor = Color.Blue;
protected override void OnPaint(PaintEventArgs e)
{
Graphics graphics = e.Graphics;
int penWidth = 4;
Pen pen = new Pen(Color.Yellow, 4);
SolidBrush brush = new SolidBrush(backgroundColor);
graphics.FillEllipse(brush, 0, 0, Width, Height);
graphics.DrawEllipse(pen, (int)penWidth / 2,(int)penWidth / 2, Width - penWidth, Height - penWidth);
graphics.DrawLine(pen, 26, 15, 26, 30);
e.Graphics.DrawArc(pen, (this.Width / 4), (this.Height / 2), (this.Width / 2), (this.Height / 4), 0, 180); // Mouth
}
private void InitializeComponent()
{
this.SuspendLayout();
//
// RoundButton
//
this.Name = "RoundButton";
//this.Load += new System.EventHandler(this.RoundButton_Load);
this.ResumeLayout(false);
}
}
}
Here in my code what it happens is the button size is large and the old button is still visible .Its not getting repainted.Can anyone help me .Am in need of it .