Control | Control development source file: Http://ded.nuaa.edu.cn/download/Windows%20Extended%20Controls.rar
Sample code: Http://ded.nuaa.edu.cn/download/WindowsApplication6.rar
A recent image acquisition requires a graphical selection control, but there is no shape control in. NET similar to VB, so consider writing a control yourself.
I'm going to create the control from scratch, which is mainly used to select the rectangle of the graphic, with a few properties color bordercolor: Border color, color BackColor: Background color, bool resizeble: whether removable, Rectangle selectrectangle: Select the area.
Open vs2003 (this version I use), create a new C # Control Library, OK, and copy the following code into your code.
Using System;
Using System.Collections;
Using System.ComponentModel;
Using System.Drawing;
Using System.Data;
Using System.Windows.Forms;
Namespace Windowsextendedcontrols
{
<summary>
Control
</summary>
public class ShapeEx:System.Windows.Forms.Control
{
<summary>
The required designer variable.
</summary>
///
Private color _bordercolor=new color ();
Private color _backcolor=new color ();
private bool _resizeble;
Private point _selflocation=new Point ();
Private point _mouselocation=new Point ();
private int _selfwidth;
private int _selfheight;
private int _selectselctedindex;//0-8,0:sizeall
Private Rectangle _rectleftselector=new Rectangle ();
Private Rectangle _recttopselector=new Rectangle ();
Private Rectangle _rectrightselector=new Rectangle ();
Private Rectangle _rectbottomselector=new Rectangle ();
Private Rectangle _rectlefttopselector=new Rectangle ();
Private Rectangle _rectrighttopselector=new Rectangle ();
Private Rectangle _rectrightbottomselector=new Rectangle ();
Private Rectangle _rectleftbottomselector=new Rectangle ();
Private System.ComponentModel.Container components = null;
Public Shapeex ()
{
This call is required for the Windows.Forms form designer.
InitializeComponent ();
TODO: Add any initialization after the initcomponent call
}
[DefaultValue ("Black"), Description ("Border Color"), Category ("appearance")]
Public Color BorderColor
{
Get
{
Insert code here.
return _bordercolor;
}
Set
{
_bordercolor=value;
This. Invalidate ();
}
}
[DefaultValue ("Control"), Description ("Background color"), Category ("appearance")]
public override Color BackColor
{
Get
{
Insert code here.
return _backcolor;
}
Set
{
_backcolor=value;
This. Invalidate ();
}
}
[DefaultValue (False), Description ("control size can be dragged and edited in Run"), Category ("Behavior")]
public bool Resizeble
{
Get
{
Insert code here.
return _resizeble;
}
Set
{
_resizeble=value;
This. Invalidate ();
}
}
[Description ("Control selection Area"), Category ("Behavior")]
Public Rectangle Selectrectangle
{
Get
{
Rectangle selectrectangler=new Rectangle ();
Selectrectangler.x = this. location.x+7;
Selectrectangler.y = this. location.y+7;
Selectrectangler.height = this. Height-15;
Selectrectangler.width = this. Width-15;
return selectrectangler;
}
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.