Code:
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Security.Cryptography;
namespace Form_Paint_event
{
public class Form_Paint_event : System.Windows.Forms.Form
{
private Button myButton;
private TextBox myText;
private Form_Paint_event myFrm;
public Form_Paint_event()
{
myButton = new Button();
myButton.Text = "Refresh";
myButton.Location = new System.Drawing.Point(64, 32);
this.myButton.Click += new System.EventHandler(this.myButton_Click);
myButton.Size = new System.Drawing.Size(150, 50);
myText = new TextBox();
myText.Location = new System.Drawing.Point(100, 100);
myText.Size = new System.Drawing.Size(150,150);
Controls.AddRange(new System.Windows.Forms.Control[] { this.myButton, this.myText });
CenterToScreen();
}
private void myButton_Click(object sender, System.EventArgs e)
{
myFrm = new Form_Paint_event();
myFrm.BackColor = System.Drawing.Color.Red; //this is not working is this correct way to do so, if not then please correct it or at least suggest me
myText.Text = this.Text;
}
static void MyPaintHandler(object objSender, PaintEventArgs pea)
{
Random rand = new Random();
Color color = Color.FromArgb(rand.Next(256),
rand.Next(256),
rand.Next(256));
Console.WriteLine("Color code: {0}", color.Name);
Graphics graphics = pea.Graphics;
graphics.Clear(color);
}
public static void Main()
{
Form_Paint_event form = new Form_Paint_event();
form.Text = "Paint Event";
form.Paint += new PaintEventHandler(MyPaintHandler);
form.StartPosition = FormStartPosition.CenterScreen;
Application.Run(form);
}
}
}
Code:
private void myButton_Click(object sender, System.EventArgs e)
{
myFrm = new Form_Paint_event();
myFrm.BackColor = System.Drawing.Color.Red; //this is not working is this correct way to do so, if not then please correct it or at least suggest me
myText.Text = this.Text;
}
Thanks & Regards
Shahzad
