Windows Develop Bookmark and Share   
 index > Windows Forms Designer > Glyph and Adorner Assistance
 

Glyph and Adorner Assistance

Ok this one should be a challenge.

I have a control with a custom designer. The control is basically a Poly-Line object which draws multiple lines at different angles chosen by the user at design time.

In design time when the user selects the control I place a Glyph at each of the points where the line changes direction. to get the idea, the character below would be two lines with a glyph at 3 points. One at each line end and one at the intersection.

>

The purpose of the glyphs is to give the user the ability to re-shape the poly line object. They will basically drag one of the glyphs to another position in the designer, and that will be the new position of the associated point, and the control will re-draw itself.

I've got this working sort of, but I'm not happy with how it is working. There is a lot of flicker.

What I have done is in the behavior service of the glyph I have over-ridden the mouse down, mouse up and mouse move handlers. When I press the mouse down, I keep track of the point, then if the mouse moves and the button is still down, I move the glyph with the mouse and invalidate the adorner (flicker)

Tthen when the mouse button goes up I fire an event (that I created in my glyph) that says the gliph has changed its location, then I redraw the control.

And the QUESTION is: Is there a better method of doing this?

Ken_Bussell  Wednesday, July 12, 2006 4:09 PM

Hey,

Well, you might want to try what we do when you drag-drop controls in the designer:

1. You disable the adorners you don't need.

2. As you are dragging, rather than invalidating the adorner, you draw a bitmap of your glyph at the right location.

When you drag a control, we disable the adorners,take a snapshot (bitmap) of the control, hide the dragged control(s), and then draw the bitmap at the right spot as the drag is going on. As we drag we don't invalidate the entire region previously occupied by the bitmap. We calculate the region that need to be invalidated and then call theBehaviorService to invalidate just that region. We then calculate the new rect for the bitmap, call SetClip on the graphics object, and redraw the dragimage in the new spot.

I found it useful to do something like:

#if DEBUG_REGIONS

System.Threading.Thread.Sleep(750);
g.FillRegion(Brushes.Red, invalidRegion);
System.Threading.Thread.Sleep(750);
g.FillRectangle(Brushes.Blue, newLocationRect);
System.Threading.Thread.Sleep(750);

#endif

to better see what regions are getting invalidated/painted and what optimizations could be done.

Let me know if this helps.

Martin

Martin Thorsen - MSFT  Wednesday, July 12, 2006 8:00 PM

Hey,

Well, you might want to try what we do when you drag-drop controls in the designer:

1. You disable the adorners you don't need.

2. As you are dragging, rather than invalidating the adorner, you draw a bitmap of your glyph at the right location.

When you drag a control, we disable the adorners,take a snapshot (bitmap) of the control, hide the dragged control(s), and then draw the bitmap at the right spot as the drag is going on. As we drag we don't invalidate the entire region previously occupied by the bitmap. We calculate the region that need to be invalidated and then call theBehaviorService to invalidate just that region. We then calculate the new rect for the bitmap, call SetClip on the graphics object, and redraw the dragimage in the new spot.

I found it useful to do something like:

#if DEBUG_REGIONS

System.Threading.Thread.Sleep(750);
g.FillRegion(Brushes.Red, invalidRegion);
System.Threading.Thread.Sleep(750);
g.FillRectangle(Brushes.Blue, newLocationRect);
System.Threading.Thread.Sleep(750);

#endif

to better see what regions are getting invalidated/painted and what optimizations could be done.

Let me know if this helps.

Martin

Martin Thorsen - MSFT  Wednesday, July 12, 2006 8:00 PM

This was extremely helpful and exactly what I was looking for.

Thank you very much Martin.

By the way,

The new desgner classes are extremely useful once you figure them out. Which was the hard part, but not too difficult. I have eliminated thousands of lines of code by utilizing them and my designer is much more functional and proffessional looking.

Pat everyone on the back that had something to do with this for me (not that they would care or even know who I was)

Ken

Ken_Bussell  Wednesday, July 12, 2006 8:21 PM

Glad to be able to help, and really exicted to hear that you were able to save thousands of lines of code.

I did forward your feedback, and trust me, people do care - a lot!

Martin

Martin Thorsen - MSFT  Wednesday, July 12, 2006 8:29 PM

Hey Martin.

I agree with Ken - the model is rather nice, very extensible and helps us to delete a lot of code.

HOWEVER - I'd kill for some more documentation. I personally work on building Component designers, and cannot rely on the existing ControlDesigner, so I gotta implement a lot myself. Hard, to say the least. WHITE PAPER NEEDED.

(no more uppercase letters from this point on)

i got to this post from the exact same problem ken encountered. your answer helped a lot. thanks.

ariel

Ariel Raunstien  Monday, July 24, 2006 7:12 AM

You can use google to search for other answers

Custom Search

More Threads

• Anchor controls on Inherited forms
• Why does my run-time form not look like my design-time form?
• Autoscroll issues in tabControl
• re: NT authentication from excel?
• Accented characters in MyForm.designer.vb not loaded correctly by VS!?
• Custom control cannot be moved in VS.NET designer
• Can I use a wizard without a form?
• Display Smart tag at runtime
• Unable to maintain Viewstate when child controls events are fired
• Embedd froms and design-time issues