Custom Go Handle Shape

Hi All,

I want to make a custom go handle, i.e. when I select my Goobject the usual rectangle should not come but a line should appear around the object.
for ex.:
I have a group which is like the snapshot:
Now I want to select the group using a line, so the effect should be like this:
wherein the red dotted line shown shows my selection.
Thanks,
Vin


This gives you the basics for providing selection handles for a GoRectangle. It isn’t clear if your samples above are “zoomed in” or not, but the code below only starts to look like yours when you zoom in (and the dashes show up).



So, you may want to change the PenWidth and DashStyle of the handles, and you may want to play with the width (pw) that I’m offsetting the handles.





// class provides a rectangle with a selection highlight of an inner and outer red dotted line. <br /> // provided for http://www.nwoods.com/forum/forum_posts.asp?TID=3392 <br /> [Serializable] <br /> class RectangleSpecialSelection : GoRectangle { <br /> <br /> public override void AddSelectionHandles(GoSelection sel, GoObject selectedObj) { <br /> RemoveSelectionHandles(sel); <br /> if (!CanResize()) { <br /> Pen p = new System.Drawing.Pen(Color.Red); <br /> p.DashStyle = DashStyle.Dash; <br /> <br /> float pw = 1; <br /> GoShape selectedShape = selectedObj as GoShape; <br /> if (selectedShape != null) pw = selectedShape.PenWidth; <br /> if (pw > 2) pw = pw / 2; <br /> <br /> // Outside selection rect <br /> IGoHandle h1 = sel.CreateBoundingHandle(this, selectedObj); <br /> GoShape h1s = h1.GoObject as GoShape; <br /> if (h1s != null) { <br /> h1s.Pen = p; <br /> h1s.Bounds = new RectangleF(selectedObj.Position.X - pw , selectedObj.Position.Y - pw , selectedObj.Width + pw * 2, selectedObj.Height + pw * 2); <br /> } <br /> <br /> // Inside selection rect <br /> IGoHandle h2 = sel.CreateBoundingHandle(this, selectedObj); <br /> GoShape h2s = h2.GoObject as GoShape; <br /> if (h2s != null) { <br /> h2s.Pen = p; <br /> h2s.Bounds = new RectangleF(selectedObj.Position.X + pw, selectedObj.Position.Y + pw, selectedObj.Width - pw * 2, selectedObj.Height - pw * 2); <br /> } <br /> <br /> } <br /> else { <br /> base.AddSelectionHandles(sel, selectedObj); <br /> } <br /> } <br /> } <br /> <br />



Looks like this when zoomed in:



Hi Jake,

Thanks for the code snippet.
But my bad. I should have explained my requirements more.
Actually my GoGroup consists of 2 lines- as you can see 1 horizontal and 1 vertical.now I am able to draw a rectangle around my gogroup as shown in your code like below:
But requirement is to make only lines which should border my Gogroup, so visually I just want 2 lines bordering my Gogroup(or just 2 sides of the bordering rectangle.), not the entire rectangle.like this:
Thanks again for your help.
--Vin

The GoGroup is 2 separate GoStrokes?

try this.



<br /> [Serializable] <br /> class SpecialPathSelection : GoGroup { <br /> <br /> public override void AddSelectionHandles(GoSelection sel, GoObject selectedObj) { <br /> Pen p = new System.Drawing.Pen(Color.Red); <br /> p.DashStyle = DashStyle.Dash; <br /> p.Width = 8; <br /> <br /> foreach (GoObject o in this) { <br /> GoStroke s = o as GoStroke; <br /> if (s != null) { <br /> s.SkipsUndoManager = true; <br /> s.Highlight = true; <br /> s.HighlightPen = p; <br /> s.SkipsUndoManager = false; <br /> } <br /> } <br /> } <br /> <br /> public override void RemoveSelectionHandles(GoSelection sel) { <br /> foreach (GoObject o in this) { <br /> GoStroke s = o as GoStroke; <br /> if (s != null) { <br /> s.SkipsUndoManager = true; <br /> s.Highlight = false; <br /> s.HighlightPen = null; <br /> s.SkipsUndoManager = false; <br /> } <br /> } <br /> } <br /> } <br />

Hi Jake,
Sorry for late reply.

As for your question, the two lines can be 2 different GoDrawing objects in a single GoGroup.So Effectively I cannot use your above code as GoDrawing does not have highlight property.

Before I write anymore code you don’t need, maybe you could tell me more about what kind of GoDrawing objects you are using. Can there be a circle? What do you want the selection for that to look like?

Hi Jake,
The object will be of Line shape.It can be a straight line or a group of 2 lines in L shape only.

Thanks,
Vin

OK, one approach would be to override CreateBoundingHandle on your Line shape, and create a derived GoHandle that overrides MakePath (see DrawDemo for samples). Also override Paint with



public override void Paint(Graphics g, GoView view) {

PaintPath(g, view, GetPath());

}



(GoHandle also overrides Paint, but not in a way that helps you here.)



And you still need to do “AddSelectionHandles” like the first sample code above, but without setting the Pen and Bounds of the new handle.