Hello there,
I have used Rack/Self class to create a designer application. Created a class derived from GoGroup,IGoLabeledNode, this class is a group control consists of 1 rectangle, 1 Go Control, 1 GoText node.
Created collection of instance in the palette using this class. while dragging/dropping the instance object into the Rack grid, it is not snapping in. Also creating some duplication object in the corner of the grid… I am confused and not able to understand the issue. Appreciate your guidance on it.
Thanks,
Dinesh
Including source code.
Code to create an instance in the palette :
WinControl ctlRadioBtn = new WinControl();
ctlRadioBtn.ControlType = typeof(RadioButton);
ctlRadioBtn.Label.Text = “text”;
ctlRadioBtn.Editable = true;
ctlRadioBtn.Size = new SizeF(125, 25);
doc.Add(ctlRadioBtn)
Group Control Code.
public class WinControl : GoGroup,IGoLabeledNode
{
public const float UnitSize = 25;
public WinControl()
{
this.AutoRescales = false;
this.Resizable = true;
this.ResizesRealtime = true;
myBackground = new GoRectangle();
myBackground.Selectable = false;
myBackground.Brush = new HatchBrush(HatchStyle.Percent30, Color.DarkBlue, Color.White);
Add(myBackground);
myGoControl = new GoControl();
myGoControl.Selectable = false;
Add(myGoControl);
GoText label = new GoText();
label.Selectable = false;
label.Multiline = false;
label.StringTrimming = StringTrimming.EllipsisCharacter;
label.Wrapping = true;
label.FontSize = 9;
label.Alignment = GoObject.MiddleCenter;
//label.Text = "Control";
Add(label);
}
public GoText Label
{
get { return this[2] as GoText; }
}
public String Text
{
get
{
GoText lab = this.Label;
if (lab != null)
return lab.Text;
return null;
}
set
{
GoText lab = this.Label;
if (lab != null)
lab.Text = value;
}
}
protected override void CopyChildren(GoGroup newgroup, GoCopyDictionary env)
{
base.CopyChildren(newgroup, env);
WinControl cg = (WinControl)newgroup;
cg.myBackground = (GoShape)env[myBackground];
cg.myGoControl = (GoControl)env[myGoControl];
}
public override void Remove(GoObject obj)
{
base.Remove(obj);
if (obj == myBackground)
myBackground = null;
else if (obj == myGoControl)
myGoControl = null;
}
public override void LayoutChildren(GoObject childchanged)
{
RectangleF b = this.Bounds;
if (this.Background != null) this.Background.Bounds = b;
this.Background.Brush = Brushes.White;
if (myGoControl != null)
{
RectangleF r = b;
r.Inflate(-5, -5);
myGoControl.Bounds = r;
}
}
public GoShape Background
{
get { return myBackground; }
}
public GoControl GoControl
{
get { return myGoControl; }
}
public Type ControlType
{
get { return this.GoControl.ControlType; }
set
{
// force any existing Controls to be removed
this.GoControl.Visible = false;
this.GoControl.ControlType = value;
// cause any Controls to be re-created and shown
this.GoControl.Visible = true;
}
}
// An Item can be resized only in positive multiples of Item.UnitSize
public override RectangleF ComputeResize(RectangleF origRect, PointF newPoint, int handle, SizeF min, SizeF max, bool reshape)
{
RectangleF r = base.ComputeResize(origRect, newPoint, handle, min, max, reshape);
r.Width = Math.Max(1, (float)Math.Round(r.Width / UnitSize)) * UnitSize;
r.Height = Math.Max(1, (float)Math.Round(r.Height / UnitSize)) * UnitSize;
return r;
}
// change the natural Location to be the BottomLeft corner,
// so that Items will "fall" onto Shelves appropriately
public override PointF Location
{
get { return GetSpotLocation(BottomLeft); }
set { SetSpotLocation(BottomLeft, value); }
}
private GoShape myBackground;
private GoControl myGoControl;
}