if (colorDialog1.ShowDialog () == DialogResult.OK) {

button2.BackColor = colorDialog1.Color; } 

What type and how to assign a variable to the color selected in ColorDialog, then to use for the brush color (which is drawn using small ellipses).

  • @AlekMalek, fix the code a little bit - Emil Sabitov

2 answers 2

The color of the brush is set when it is created (passed to the constructor). If you need to change the color of the brush, destroy the old one ( Dispose() ) and create a new one by passing a new color to the constructor.

  • @Flammable, the most likely question was to pass the desired color from ColorDialog to the brush constructor by assigning it to a variable. - Emil Sabitov
  • @ Emil Sabitov, shtoa? - nitrocaster
  • ... "to pass the desired color from ColorDialog to the brush constructor by assigning it to a variable." exactly. - AlekMalek
  • @Flammable, smiled :) Yes: SolidBrush myBrush = new SolidBrush (Color.Red); Instead of Color.Red, you need to use a variable that stores the selected color from ColorDialog. Here's how to save color in this variable)? - Emil Sabitov
  • And where is the problem? var selectedColor = ColorDialog1.Color; var brush = new SolidBrush (selectedColor); - nitrocaster
 private void button1_Click(object sender, System.EventArgs e) { ColorDialog MyDialog = new ColorDialog(); //Меняет цвет текста в текстбоксе if (MyDialog.ShowDialog() == DialogResult.OK) textBox1.ForeColor = MyDialog.Color; } 

I think this is what you need. Try using this method. Based on this, the brush can be assigned the value MyDialog.Color.