How do I raise a property error without killing the IDE?

  • Thread starter Thread starter Jeff Johnson
  • Start date Start date
J

Jeff Johnson

[This isn't really a C# question, but the IDE group is all but dead, so I'm
crossposting....]

I have a user control that should only accept fixed-width fonts for its Font
property. If the user tries to assign a proportional font, I want to return
an error. This works fine for code, but if the user sets the font via the
Properties window in the IDE, my error ("throw new Exception(<blah>)") locks
the IDE up solid. I want it to work more like, for example, when you try to
set the (name) property of a control to something invalid. A little message
box pops up telling you that the "Property value is invalid" or words to
that effect. Any idea how to do that?
 
[...]
I want it to work more like, for example, when you try to
set the (name) property of a control to something invalid. A little
message
box pops up telling you that the "Property value is invalid" or words to
that effect. Any idea how to do that?

Maybe check the DesignMode property and display the MessageBox instead of
throwing an exception if the property is set to "true"?

Ahhh, from Component. I looked for such a thing, but I must have only looked
in the Public properties section and not Protected. I'll give it a shot!
 
Back
Top