1

I have a form with a GroupBox and an ErrorProvider. When I try to use the following code:

errorProvider1.SetError(groupBox1, "error");

The error icon is shown to the right of the group box:

1

I would like the icon to be shown next to the header. Something like this (made with Photoshop):

2

How can I achieve that?

Reza Aghaei
  • 120,393
  • 18
  • 203
  • 398
Michael Haddad
  • 4,085
  • 7
  • 42
  • 82

2 Answers2

1

You can use SetIconAlignment and SetIconPadding to set the location of the error icon. For example:

errorProvider1.SetError(groupBox1, "Error!");
errorProvider1.SetIconAlignment(groupBox1, ErrorIconAlignment.TopLeft);
errorProvider1.SetIconPadding(groupBox1, -24);

You need to shift the text a bit to right, by preppending some space, to have more room for the icon.

Reza Aghaei
  • 120,393
  • 18
  • 203
  • 398
1

Following should help you.

errorProvider1.SetIconAlignment(groupBox1, ErrorIconAlignment.TopLeft);
errorProvider1.SetIconPadding(groupBox1, -5);
errorProvider1.SetError(groupBox1,"error");

As explained in your previous question regarding TabControl, you would need to provide sufficient space in your GroupBox Text for showing the icon

enter image description here

Anu Viswan
  • 17,797
  • 2
  • 22
  • 51