internal GrabHandleGlyph(Rectangle controlBounds, GrabHandleGlyphType type, System.Windows.Forms.Design.Behavior.Behavior behavior, bool primarySelection) : base(behavior) { this.isPrimary = primarySelection; base.hitTestCursor = Cursors.Default; base.rules = SelectionRules.None; switch (type) { case GrabHandleGlyphType.UpperLeft: base.bounds = new Rectangle((controlBounds.X + DesignerUtils.HANDLEOVERLAP) - DesignerUtils.HANDLESIZE, (controlBounds.Y + DesignerUtils.HANDLEOVERLAP) - DesignerUtils.HANDLESIZE, DesignerUtils.HANDLESIZE, DesignerUtils.HANDLESIZE); base.hitTestCursor = Cursors.SizeNWSE; base.rules = SelectionRules.LeftSizeable | SelectionRules.TopSizeable; break; case GrabHandleGlyphType.UpperRight: base.bounds = new Rectangle(controlBounds.Right - DesignerUtils.HANDLEOVERLAP, (controlBounds.Y + DesignerUtils.HANDLEOVERLAP) - DesignerUtils.HANDLESIZE, DesignerUtils.HANDLESIZE, DesignerUtils.HANDLESIZE); base.hitTestCursor = Cursors.SizeNESW; base.rules = SelectionRules.RightSizeable | SelectionRules.TopSizeable; break; case GrabHandleGlyphType.LowerLeft: base.bounds = new Rectangle((controlBounds.X + DesignerUtils.HANDLEOVERLAP) - DesignerUtils.HANDLESIZE, controlBounds.Bottom - DesignerUtils.HANDLEOVERLAP, DesignerUtils.HANDLESIZE, DesignerUtils.HANDLESIZE); base.hitTestCursor = Cursors.SizeNESW; base.rules = SelectionRules.LeftSizeable | SelectionRules.BottomSizeable; break; case GrabHandleGlyphType.LowerRight: base.bounds = new Rectangle(controlBounds.Right - DesignerUtils.HANDLEOVERLAP, controlBounds.Bottom - DesignerUtils.HANDLEOVERLAP, DesignerUtils.HANDLESIZE, DesignerUtils.HANDLESIZE); base.hitTestCursor = Cursors.SizeNWSE; base.rules = SelectionRules.RightSizeable | SelectionRules.BottomSizeable; break; case GrabHandleGlyphType.MiddleTop: if (controlBounds.Width >= ((2 * DesignerUtils.HANDLEOVERLAP) + (2 * DesignerUtils.HANDLESIZE))) { base.bounds = new Rectangle((controlBounds.X + (controlBounds.Width / 2)) - (DesignerUtils.HANDLESIZE / 2), (controlBounds.Y + DesignerUtils.HANDLEOVERLAP) - DesignerUtils.HANDLESIZE, DesignerUtils.HANDLESIZE, DesignerUtils.HANDLESIZE); base.hitTestCursor = Cursors.SizeNS; base.rules = SelectionRules.TopSizeable; } break; case GrabHandleGlyphType.MiddleBottom: if (controlBounds.Width >= ((2 * DesignerUtils.HANDLEOVERLAP) + (2 * DesignerUtils.HANDLESIZE))) { base.bounds = new Rectangle((controlBounds.X + (controlBounds.Width / 2)) - (DesignerUtils.HANDLESIZE / 2), controlBounds.Bottom - DesignerUtils.HANDLEOVERLAP, DesignerUtils.HANDLESIZE, DesignerUtils.HANDLESIZE); base.hitTestCursor = Cursors.SizeNS; base.rules = SelectionRules.BottomSizeable; } break; case GrabHandleGlyphType.MiddleLeft: if (controlBounds.Height >= ((2 * DesignerUtils.HANDLEOVERLAP) + (2 * DesignerUtils.HANDLESIZE))) { base.bounds = new Rectangle((controlBounds.X + DesignerUtils.HANDLEOVERLAP) - DesignerUtils.HANDLESIZE, (controlBounds.Y + (controlBounds.Height / 2)) - (DesignerUtils.HANDLESIZE / 2), DesignerUtils.HANDLESIZE, DesignerUtils.HANDLESIZE); base.hitTestCursor = Cursors.SizeWE; base.rules = SelectionRules.LeftSizeable; } break; case GrabHandleGlyphType.MiddleRight: if (controlBounds.Height >= ((2 * DesignerUtils.HANDLEOVERLAP) + (2 * DesignerUtils.HANDLESIZE))) { base.bounds = new Rectangle(controlBounds.Right - DesignerUtils.HANDLEOVERLAP, (controlBounds.Y + (controlBounds.Height / 2)) - (DesignerUtils.HANDLESIZE / 2), DesignerUtils.HANDLESIZE, DesignerUtils.HANDLESIZE); base.hitTestCursor = Cursors.SizeWE; base.rules = SelectionRules.RightSizeable; } break; } base.hitBounds = base.bounds; }
/// <summary> /// GrabHandleGlyph's constructor takes additional parameters: 'type' and 'primary selection'. /// Also, we create/cache our pen and brush here to avoid this action with every paint message. /// </summary> internal GrabHandleGlyph(Rectangle controlBounds, GrabHandleGlyphType type, Behavior behavior, bool primarySelection) : base(behavior) { _isPrimary = primarySelection; hitTestCursor = Cursors.Default; rules = SelectionRules.None; // We +/- DesignerUtils.HANDLEOVERLAP because we want each GrabHandle to overlap the control by DesignerUtils.HANDLEOVERLAP pixels switch (type) { case GrabHandleGlyphType.UpperLeft: bounds = new Rectangle((controlBounds.X + DesignerUtils.HANDLEOVERLAP) - DesignerUtils.HANDLESIZE, (controlBounds.Y + DesignerUtils.HANDLEOVERLAP) - DesignerUtils.HANDLESIZE, DesignerUtils.HANDLESIZE, DesignerUtils.HANDLESIZE); hitTestCursor = Cursors.SizeNWSE; rules = SelectionRules.TopSizeable | SelectionRules.LeftSizeable; break; case GrabHandleGlyphType.UpperRight: bounds = new Rectangle(controlBounds.Right - DesignerUtils.HANDLEOVERLAP, (controlBounds.Y + DesignerUtils.HANDLEOVERLAP) - DesignerUtils.HANDLESIZE, DesignerUtils.HANDLESIZE, DesignerUtils.HANDLESIZE); hitTestCursor = Cursors.SizeNESW; rules = SelectionRules.TopSizeable | SelectionRules.RightSizeable; break; case GrabHandleGlyphType.LowerRight: bounds = new Rectangle(controlBounds.Right - DesignerUtils.HANDLEOVERLAP, controlBounds.Bottom - DesignerUtils.HANDLEOVERLAP, DesignerUtils.HANDLESIZE, DesignerUtils.HANDLESIZE); hitTestCursor = Cursors.SizeNWSE; rules = SelectionRules.BottomSizeable | SelectionRules.RightSizeable; break; case GrabHandleGlyphType.LowerLeft: bounds = new Rectangle((controlBounds.X + DesignerUtils.HANDLEOVERLAP) - DesignerUtils.HANDLESIZE, controlBounds.Bottom - DesignerUtils.HANDLEOVERLAP, DesignerUtils.HANDLESIZE, DesignerUtils.HANDLESIZE); hitTestCursor = Cursors.SizeNESW; rules = SelectionRules.BottomSizeable | SelectionRules.LeftSizeable; break; case GrabHandleGlyphType.MiddleTop: // Only add this one if there's room enough. Room is enough is as follows: 2*HANDLEOVERLAP for UpperLeft and UpperRight handles, 1 HANDLESIZE for the MiddleTop handle, 1 HANDLESIZE for padding if (controlBounds.Width >= (2 * DesignerUtils.HANDLEOVERLAP) + (2 * DesignerUtils.HANDLESIZE)) { bounds = new Rectangle(controlBounds.X + (controlBounds.Width / 2) - (DesignerUtils.HANDLESIZE / 2), (controlBounds.Y + DesignerUtils.HANDLEOVERLAP) - DesignerUtils.HANDLESIZE, DesignerUtils.HANDLESIZE, DesignerUtils.HANDLESIZE); hitTestCursor = Cursors.SizeNS; rules = SelectionRules.TopSizeable; } break; case GrabHandleGlyphType.MiddleBottom: // Only add this one if there's room enough. Room is enough is as follows: 2*HANDLEOVERLAP for LowerLeft and LowerRight handles, 1 HANDLESIZE for the MiddleBottom handle, 1 HANDLESIZE for padding if (controlBounds.Width >= (2 * DesignerUtils.HANDLEOVERLAP) + (2 * DesignerUtils.HANDLESIZE)) { bounds = new Rectangle(controlBounds.X + (controlBounds.Width / 2) - (DesignerUtils.HANDLESIZE / 2), controlBounds.Bottom - DesignerUtils.HANDLEOVERLAP, DesignerUtils.HANDLESIZE, DesignerUtils.HANDLESIZE); hitTestCursor = Cursors.SizeNS; rules = SelectionRules.BottomSizeable; } break; case GrabHandleGlyphType.MiddleLeft: // Only add this one if there's room enough. Room is enough is as follows: 2*HANDLEOVERLAP for UpperLeft and LowerLeft handles, 1 HANDLESIZE for the MiddleLeft handle, 1 HANDLESIZE for padding if (controlBounds.Height >= (2 * DesignerUtils.HANDLEOVERLAP) + (2 * DesignerUtils.HANDLESIZE)) { bounds = new Rectangle((controlBounds.X + DesignerUtils.HANDLEOVERLAP) - DesignerUtils.HANDLESIZE, controlBounds.Y + (controlBounds.Height / 2) - (DesignerUtils.HANDLESIZE / 2), DesignerUtils.HANDLESIZE, DesignerUtils.HANDLESIZE); hitTestCursor = Cursors.SizeWE; rules = SelectionRules.LeftSizeable; } break; case GrabHandleGlyphType.MiddleRight: // Only add this one if there's room enough. Room is enough is as follows: 2*HANDLEOVERLAP for UpperRight and LowerRight handles, 1 HANDLESIZE for the MiddleRight handle, 1 HANDLESIZE for padding if (controlBounds.Height >= (2 * DesignerUtils.HANDLEOVERLAP) + (2 * DesignerUtils.HANDLESIZE)) { bounds = new Rectangle(controlBounds.Right - DesignerUtils.HANDLEOVERLAP, controlBounds.Y + (controlBounds.Height / 2) - (DesignerUtils.HANDLESIZE / 2), DesignerUtils.HANDLESIZE, DesignerUtils.HANDLESIZE); hitTestCursor = Cursors.SizeWE; rules = SelectionRules.RightSizeable; } break; default: Debug.Assert(false, "GrabHandleGlyph was called with a bad GrapHandleGlyphType."); break; } hitBounds = bounds; }