Let's talk about how the control works, first by writing his attributes, and by overriding his attributes,
Private color _bordercolor=new color ();
[DefaultValue ("Black"), Description ("Border Color"), Category ("appearance")]
Public Color BorderColor
{
Get
{
Insert code here.
return _bordercolor;
}
Set
{
_bordercolor=value;
This. Invalidate ();
}
}
DefaultValue: Set default value, Description: Description, is the description of the attribute, Category: attribute classification. The other same thing.
When you set a property, you should rewrite his drawing process, which is
protected override void OnPaint (PaintEventArgs pe)
{
Calling the base class OnPaint
Base. OnPaint (PE);
Redrawcontrol (PE. Graphics);
}
private void Redrawcontrol (Graphics Graphics)
{
The rectangle (rectangle) is defined in Redrawcontrol, so that the rectangle is filled with a rectangular border: graphics. DrawRectangle (Borderpen, rectborder); Here's what you're going to say. There is also an edit box outside the border, so the size is not the size of the control. Drawselector is to draw 8 selection boxes, basic and draw the border almost, even if the definition of good coordinates. Don't forget to release the resource after you've done it: graphics. Dispose ();
Selectrectangle: The rectangle that the control chooses, it's the end of it.
OK, so a basic thing came out, and here we're going to write his move and resize functions, add the event first:
This. Resize + = new System.EventHandler (this. Shapeex_resize);
This. MouseUp + = new System.Windows.Forms.MouseEventHandler (this. Shapeex_mouseup);
This. MouseMove + = new System.Windows.Forms.MouseEventHandler (this. Shapeex_mousemove);
This. MouseLeave + = new System.EventHandler (this. Shapeex_mouseleave);
This. MouseDown + = new System.Windows.Forms.MouseEventHandler (this. Shapeex_mousedown);
Principle: When the mouse clicks this. MouseDown, record the position of the mouse, the original position and size of the control, determine the location: _rectleftbottomselector.contains (E.X,E.Y): Click on the left, set the mouse, record status this._ Selectselctedindex: Judge clicks on the selection box, takes a value of 0-8:0 means to move the entire control, 1 is to move the top right, 2-8 clockwise index selection box. This. MouseMove How to change the size and position of a control
Case 0://only Move position
This. Location=new Point (cursor.position.x-(_mouselocation.x-_selflocation.x), cursor.position.y-(_MouseLocation.Y-_ SELFLOCATION.Y));
Break
1,5 not only move the position, but also change the size, 2,3,4,6,7,8 only change the size
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.