c# - How to move rectangle with mouse -


I want to move a rectangle on the screen. This is the code for this time:

  Internal category GraphicContainer: Control {// --------------------- METHODS - ------------------- Public Graphic Container (Control Control, String Text, Inte Left, Input): Base (Control, Text, Left, Top, 400, 200) Secure Override Zero OnPaint (PaintEventArgs pe) {// call the OnPaint method of base class. Base.OnPaint (PE); // Announce and open a new pen. Pen pens = new pen (color. Fuscia, 15); Solidbrish MyBrush = New System Drawing. Solidbrush (color hotpunk); // Draw an aqua rectangle in the rectangle represented by the control. //pe.Graphics.DrawRectangle (open, new rectangle (this. Location, this.Size)); Rectangle blublublu = new rectangle (this. Location, shape - new size (25, 25)); Pe.Graphics.DrawRectangle (pen, blublublu); Pe.Graphics.FillRectangle (myBrush, blublublu); Safe Override Zero OnMouseMove (MouseEventArgs E) {} Safe Override Zero OnClick (EventArgs e) {}} I have searched a lot and I do not know what code should be written in "OnMouseMove" And in order to move the mouse to "onclick"   

Ryan Reynolds!

Make a field blublublu you can see MouseMove , MouseUp , MouseDown :

  rectangle Blublublu = new rectangle (.. must be used); // OnMouseDown (MouseEventArgs e) Probably protected protected override {if (e.button == MouseButtons.Left) {capture = true; _x = e.x; // Remember Corus _y = e.Y; } Base.OnMouseDown (E); } Secure Override Zero OnMouseUp (MouseEventArgs e) {capture = false; Base.OnMouseUp (E); } Secure Override Zero OnMouseMove (MouseEventArgs e) {if (e.button == MouseButtons.Left) {blublublu.x + = _x - e.x; // Do not check, maybe use rectangular. Offset or create a new rectangle blubblu. Y + = _y - e.Y; Invalid (); }}  

When the mouse goes down, you capture it (remember to get mousemove events even when the mouse is out of control) and remember the coordinates. During mouse movement, you change the current coordinates of the Blubblue by the difference (decrease the position of the mouse is saved from the current) and call invalid .


Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -