using System;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Drawing2D;
public class MyClass
{
Button btn;
bool isValid = true;
public static void Main()
{
new MyClass();
}
public MyClass()
{
var form = new Form();
btn = new Button();
btn.Size = new Size(50, 50);
btn.Paint += Button_Paint;
btn.Click += Button_Click;
form.Controls.Add(btn);
Application.Run(form);
}
private void Button_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
if (isValid) {
g.DrawString("This is a diagonal line drawn on the control",
new Font("Arial", 10), System.Drawing.Brushes.Blue, new Point(30, 30));
g.DrawLine(System.Drawing.Pens.Red, btn.Left, btn.Top,
btn.Right, btn.Bottom);
}
else {
g.FillRectangle(
new LinearGradientBrush(PointF.Empty, new PointF(0, btn.Height), Color.White, Color.Red),
new RectangleF(PointF.Empty, btn.Size));
}
}
private void Button_Click(object sender, EventArgs e)
{
isValid = false;
btn.Invalidate();
}
}