C # rect Tracker

Source: Internet
Author: User

This article from http://www.codeproject.com/KB/miscctrl/CSharpRectTracker.aspx

 

    • Download source code-18.7 KB

Introduction

Ever tried to find that object that allows Visual Studio to move and resize controls? Well, I didn't find it in C # But in C ++. Well, here it is in C #

Background

The project I was working on required me to createFormS in run-time, so I needed something to edit controls-recttracker.

In C ++ there is an object calledCrecttracker, But in C # There isn' t, so I tried to clone it, It doesn' t do what the Visual Studio tracker does, but it does the job on resizing and moving controls onForm.

Methodology

It's made ofUsercontrol Because doing it usingFormGraphics object creates ordering problems (a control is "above" the tracker), so making it a control itself, allows me to play with Z-order and set the control to front.

I used region transparenting to create a place for the control I want to move/resize.

Using the code Collapse | Copy code
Somecontrol. bringtofront (); somecontrol. Capture =False;If(This. Controls. Contains (csharptracker ))This. Controls. Remove (csharptracker); csharptracker =NewRecttracker (somecontrol );This. Controls. Add (csharptracker); csharptracker. bringtofront (); csharptracker. Draw ();

Control moving Collapse | Copy code
 Public   Void Mouse_move ( Object Sender, system. Windows.Form S. mouseeventargs e ){ //  Minimum size for the control is 8x8  If (Currentcontrol. height < 8 ) {Currentcontrol. Height = 8 ; Return ;} Else   If (Currentcontrol. width < 8 ) {Currentcontrol. width = 8 ; Return ;}Switch ( This . Currborder ){ Case Resize_border.rb_top: currentcontrol. Height = currentcontrol. Height-E. Y + prevleftclick. Y; If (Currentcontrol. Height> 8 ) Currentcontrol. Top = currentcontrol. Top + E. Y-prevleftclick. Y; Break ; Case Resize_border.rb_topleft: currentcontrol. Height = currentcontrol. Height-E. Y + prevleftclick. Y; If (Currentcontrol. Height> 8 ) Currentcontrol. Top = currentcontrol. Top + E. Y-prevleftclick. Y; currentcontrol. width = currentcontrol. Width-E. x + prevleftclick. X; If (Currentcontrol. width> 8 ) Currentcontrol. Left = currentcontrol. Left + E. X-prevleftclick. X; Break ; Case Resize_border.rb_topright: currentcontrol. Height = currentcontrol. Height-E. Y + prevleftclick. Y; If (Currentcontrol. Height> 8 ) Currentcontrol. Top = currentcontrol. Top + E. Y-prevleftclick. Y; currentcontrol. width = currentcontrol. Width + E. X-prevleftclick. X; Break ;Case Resize_border.rb_right: currentcontrol. width = currentcontrol. Width + E. X-prevleftclick. X; Break ; Case Resize_border.rb_bottom: currentcontrol. Height = currentcontrol. height + E. Y-prevleftclick. Y; Break ; Case Resize_border.rb_bottomleft: currentcontrol. Height = currentcontrol. height + E. Y-prevleftclick. Y; currentcontrol. width = currentcontrol. Width-E. x + prevleftclick. X; If (Currentcontrol. width> 8 ) Currentcontrol. Left = currentcontrol. Left + E. X-prevleftclick. X; Break ; Case Resize_border.rb_bottomright: currentcontrol. Height = currentcontrol. height + E. Y-prevleftclick. Y; currentcontrol. width = currentcontrol. Width + E. X-prevleftclick. X; Break ; Case Resize_border.rb_left: currentcontrol. width = currentcontrol. Width-E. x + prevleftclick. X; If (Currentcontrol. width> 8 ) Currentcontrol. Left = currentcontrol. Left + E. X-prevleftclick. X; Break ; Case Resize_border.rb_none: currentcontrol. Location = New Point (currentcontrol. Location. x + E. X-prevleftclick. X, currentcontrol. Location. Y + E. Y-prevleftclick. y ); Break ;}}
Conclusion

ThisSharprecttrackerControl is a clone ofCrecttracker, And it allows a user to move and resizeFormObjects (control) in run-time, this control can be further enhanced to allow multiple object move/resize (using selection) and to do selectable resize (for an object that only the width can be changed ).

License

This article has no explicit license attached to it but may contain in usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

 

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.