You need to implement a mouse-box-selected feature in your project, now share your code:
Train of thought: realize three mouse event mousedown,mousemove,mouseup, as to what function needs to implement after box is selected, can call in MouseUp
The complete code is as follows:
Create a new WinForm form program that modifies the behindcode of the form.
Using System;
Using System.Collections.Generic;
Using System.ComponentModel;
Using System.Data;
Using System.Drawing;
Using System.Linq;
Using System.Text;
Using System.Threading.Tasks;
Using System.Windows.Forms; namespace Winfrmmouseframeselect {public partial class Mframselctdemo:form {private bool Mouseisdown =
False
Private Rectangle mouserect = Rectangle.empty;
Public Mframselctdemo () {InitializeComponent (); } private void Mframselctdemo_mousedown (object sender, MouseEventArgs e) {Mouseisdown = True
;
Drawstart (e.location);
} private void Mframselctdemo_mousemove (object sender, MouseEventArgs e) {if (Mouseisdown)
Resizetorectangle (e.location);
} private void Mframselctdemo_mouseup (object sender, MouseEventArgs e) {Capture = false;
Cursor.clip = Rectangle.empty; Mouseisdown = false;
DrawRectangle ();
Mouserect = Rectangle.empty; ///<summary>///initialization selection box///</summary>///<param name= "StartPoint" >& lt;/param> private void Drawstart (point startpoint) {this.
Capture = true;
Specifies that the workspace is the entire control Cursor.clip = Rectangletoscreen (new Rectangle (0, 0, clientsize.width, clientsize.height));
Mouserect = new Rectangle (startpoint.x, startpoint.y, 0, 0); ///<summary>///Changes the size of the selection box when the mouse moves///</summary>///<param name= "P" > Mice
The marked position </param> private void Resizetorectangle (point P) {DrawRectangle ();
Mouserect.width = P.x-mouserect.left;
Mouserect.height = P.y-mouserect.top;
DrawRectangle (); ///<summary>///Draw selection box///</summary> private void DrawRectangle () {Rectangle rect = Rectangletoscreen (mouserect);
Controlpaint.drawreversibleframe (Rect, Color.White, framestyle.dashed);
}
}
}