0
Hi friend,
The reason is though you set the color to the brush, you don't have access to that brush outside button click event.
So change your code as follows.
SolidBrush myBrush;//Define the varaible outside the methods.
public Form1()
{
InitializeComponent();
myBrush = new SolidBrush(Color.Black);//You set a default color as black.
pictureBox1.Paint += new PaintEventHandler(f1_paint);//Your picture box paint method
//You can write your other code here, if you want.
}
private void f1_paint(object sender, PaintEventArgs e)
{
System.Drawing.Graphics formGraphics = this.CreateGraphics();
formGraphics.FillEllipse(myBrush, 20, 20, 40, 40);
//You can write other drawing code as you like.
//But use 'myBrush ' to draw.
}
private void button2_Click(object sender, EventArgs e)
{
ColorDialog clrdlg = new ColorDialog();
if (clrdlg.ShowDialog() == DialogResult.OK)
{
myBrush = new SolidBrush(clrdlg.Color);
pictureBox1.Refresh();
}
}
If you find this answer helpful, please do not forget to check 'Do you like this answer' checkbox.

0
Friend what are you doin with that PictureBox because after changing... the color of Brush you need to DrawSomthing with that brush ...then you can see color changed or not .
0
Hi Kirtan
Thaks very much for replying to my question with the code. I added this code but unfortunately it didn't work. when I click on the button, the color dialog window opens, i select a new color for the brush, paint on the grid again but the color has not changed. I also tried this code, but it didnt work.
private void button2_Click(object sender, EventArgs e) {
SolidBrush myBrush;
ColorDialog clrdlg = new ColorDialog();
if (clrdlg.ShowDialog() == DialogResult.OK) {
myBrush = new SolidBrush(clrdlg.Color);
} }
|
I used myBrush as this is what I am using earlier in the code as my brush object. I also tried this code but it didn't work.
private void button2_Click(object sender, EventArgs e) {
SolidBrush myBrush;
ColorDialog clrdlg = new ColorDialog();
if (clrdlg.ShowDialog() == DialogResult.OK) {
myBrush = new SolidBrush(clrdlg.Color); pictureBox1.Refresh();
} }
|
Do you know why this isn't working? Do you have any suggestions on how I can resolve this issue? Thanks for your time.
Kind regards

0
Friend ,
Here is Code you need .!!
private void button1_Click(object sender, EventArgs e)
{
SolidBrush brush;
ColorDialog clrdlg = new ColorDialog();
if (clrdlg.ShowDialog() == DialogResult.OK)
{
brush = new SolidBrush(clrdlg.Color);
}
//Now use the Brush where you need
// Thats it
}