collectionControl

quwiltw

Contributor
Joined
Sep 18, 2001
Messages
486
Location
Washington, D.C.
I just read divil's tutorial on CollectionControl, it's great. I do have a question, if the controls are inherited from built-in controls, in my case an inherited RadioButton (inherited to add a RadioValue property), how do I get it to draw itself in the designer? and at runtime?
 
I'm getting there... Calling InvokePaint on each of the contained controls seems to work for one, but now it makes me realize that either only one is being added or it's dropping them on top of each other. Still searching...
 
What behaviour do you want the radio buttons to have? You should be able to host them on the design surface if you've created them with a call to CreateComponent on IDesignerHost. You can add them to your control with Controls.Add.
 
I want the radio buttons to have a Value attribute that can be set at design time. Then I can take the RadioCollectionControl and bind to it and have its Value make the correct selection on the contained radio buttons. It relates to the question I asked the other day
http://www.xtremedotnettalk.com/showthread.php?s=&threadid=70264
... then I saw your article and figured this would be a good generic way to solve the problem instead of having to create individual UserControls for each situation.

For now, it paints the first one fine but I think it's setting every one after that on top of the first. I'm trying to better understand the CalculateLayout 'cause I suspect it's somewhere in there. Any ideas, let me know.
 
Since these are real controls you are hosting, a great deal of my article doesn't apply. All the CalculateLayout function need do in your case is to set the position of the radiobutton controls once you've added them with Controls.Add.

By default, the radiobuttons will have a ControlDesigner associated with them, so they will be selectable and you'll be able to edit their properties in the propertygrid. However you probably won't see the selection rectangle because your parent control designer won't inherit from ParentControlDesigner.
 
Thanks, finally got it, now I'm trying to find a place to force the main control to repaint itself. I tried putting it after the commit in OnAddButton() but that doesn't work, I'll keep trying. I'm getting close though. Right now I have to resize the control in the designer to get all the radiobuttons to show.

btw. my problem was that i was still going at your Buttons property instead of directly adding to the Controls property.
 
Beautiful!!! asking it to repaint itself wasn't enough, since I'm no longer going through Buttons.Add(), I had to make a call to CalculateLayout() to both reposition and repaint. Now I need to figure out a way to get the selection border back.
 
When you originally posted this thread I had a quick go at doing what you're doing, and to get the selection border I had to do the following:

- Listen for the SelectionChanged event from ISelectionService (you're probably already doing so)
- Force any radiobutton that should (or shouldn't anymore) have a selection rectangle to repaint itself
- In your RadioButton designer, override OnPaintAdornments. Then use ControlPaint.DrawSelectionFrame to draw the selection frame on top of the control's normal graphics.
 
Back
Top