
McSmartGrip<T> class is used. This class contains several variants of the constructor with different lists of parameters, as well as event handlers that are generated depending on user actions:MoveGrip - called when moving the handle,MouseMove - called when you move the knob of the interactive type,GetContextMenu - called when clicking on a handle with type GripType.PopupMenu ,OnCommand - called when clicking on the handle with the type GripType.Button or the context menu item obtained from GetContextMenu . var simpleGrip = new McSmartGrip<ObjectRefEntity>(position, (obj, g, offset) => { obj.TryModify(); obj._pnt += offset; } MoveGrip delegate, which we did with the help of lambda expressions ( http://msdn.microsoft.com/ru-ru/library/bb397687.aspx ), namely, shifted the position of the object by the value offset .AppendGrip() method of the AppendGrip() class: public void AppendGrip(Multicad.CustomObjectBase.McBaseGrip grip); GetGripPoints() method, which is called to get pens each time an object is displayed: public virtual bool GetGripPoints(Multicad.CustomObjectBase.GripPointsInfo info);  public override bool GetGripPoints(GripPointsInfo info) { info.AppendGrip(new McSmartGrip<ObjectRefEntity>(_pnt, (obj, g, offset) => { obj.TryModify(); obj._pnt += offset; })); } Simple is a simple pen. Handle handle processing, implemented in MoveGrip .PopupMenu - the handle, on click on which pop-up menus are displayed. Event handling is implemented in OnCommand .Button is a pen-button, when clicked, the actions described in OnCommand are performed.Interactive is a type similar to Simple , but allows you to work with object snapping. Unlike simple handles, event handling is implemented in MouseMove .McBaseGrip.GripAppearance listing. Here are some of them:
GripColors class, or you can determine the color in the standard way using System.Drawing.Color .TextInBox primitive we TextInBox , described in this article, and create for it several intelligent pens of various types. info.AppendGrip(new McSmartGrip<ObjectRefEntity>(_pnt, (obj, g, offset) => { obj.TryModify(); obj._pnt += offset; })); 
McBaseGrip.GripType.Button pen and the base color. The _show_frame button handler changes the value of the _show_frame frame drawing indicator to the opposite. For the created knob-button, we define the appearance of "on", which will change to "off" when pressed, and back. var OnOffGrip = new McSmartGrip<TextInBox>(McBaseGrip.GripType.Button, 1, _pnt + stepVector, McBaseGrip.GripAppearance.SwitchOn, 0, "Hide Frame", GripColors.Base); OnOffGrip.Tag = "OnOffGrip"; if (_show_frame == false) OnOffGrip.SetAppearanceAndText(McBaseGrip.GripAppearance.SwitchOff, "Show frame"); OnOffGrip.OnCommand = (obj, commandId, grip) => { obj.TryModify(); obj._show_frame = !obj._show_frame;}; info.AppendGrip(OnOffGrip); 
 var cmdGrip = new McSmartGrip<TextInBox>( McBaseGrip.GripType.Button, 1, _pnt + 2 * stepVector, McBaseGrip.GripAppearance.Circle, 0, "button", GripColors.Base); cmdGrip.Tag="cmd"; cmdGrip.OnCommand = (obj, commandId, grip) => { McContext.ExecuteCommand(grip.Tag.ToString()); }; McBaseGrip.GripType.PopupMenu and the appearance defined by the value of McBaseGrip.GripAppearance.PopupMenu . To work with the context menu, you need to implement two delegates:GetContextMenu - call the menu when you press the handle,OnCommand - call actions when selecting items var ctxGrip = new McSmartGrip<TextInBox>(McBaseGrip.GripType.PopupMenu, 2, _pnt + 2 * stepVector, McBaseGrip.GripAppearance.PopupMenu, 0, "Select menu", System.Drawing.Color.Lime); ctxGrip.GetContextMenu = (obj, items) => { items.Add(new ContextMenuItem("Command 1", "none", 1)); }; ctxGrip.OnCommand = (obj, commandId, grip) => { if (grip.Id == 2) { switch (commandId) { case 1: { MessageBox.Show("Command 1 is selected"); break; } } } }; info.AppendGrip(ctxGrip); 
GripColors.Base , when you hover over the parent object, the color will change to Color.Red , to any other object that supports the binding to Color.Green .McBaseGrip.GripType.Interactive , and the pen is implemented in the MouseMove delegate (as opposed to simple pens using MoveGrip ). var interactiveGrip = new McSmartGrip<TextInBox>(McBaseGrip.GripType.Interactive, 3, _pnt + 3 * stepVector, McBaseGrip.GripAppearance.Arrow, 0, "interactive", GripColors.Base); interactiveGrip.IsMovable = true; interactiveGrip.MouseMove = (obj, entInfo, grip, offset) => { grip.Color = GripColors.Base; if (!entInfo.SnapedObjectId.IsNull) { if (ID == entInfo.SnapedObjectId) { grip.Color = Color.Red; } else { grip.Color = Color.Green; obj.TryModify(); obj.Text = (entInfo.SnapedObjectId.GetObject().GetType().ToString()); } } }; info.AppendGrip(interactiveGrip); 
Source: https://habr.com/ru/post/234181/
All Articles