Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

C# Line Control with Rotate Option

0.00/5 (No votes)
14 May 2007 1  
An article on line control in .NET

Screenshot - bitLineControlSnap.jpg

Introduction

I decided to write this line control in C# when I was unable to find a suitable solution on the Internet. My scenario was to draw straight and curved lines to highlight pathways to a destination. Here, the line region is automatically controlled in the bitLineControl class.

Using the code

Using the code is not difficult; you just have to add the reference bitLineControl in your project. Declare and initialize the class variable and, while calling the constructor, just pass two points to draw a line between them:

//--------------------------------------------------------------------------

//  Variable Declaration

//--------------------------------------------------------------------------

    bitLineControl varbitLine;
    
//--------------------------------------------------------------------------

//  calling the constructor

//--------------------------------------------------------------------------

    Point firstPoint = new Point( x1, y1);
    Point secondPoint = new Point(x2, y2 );
    varbitLine = new bitLineControl(firstPoint, secondPoint);
    this.Controls.Add(varbitLine);
//--------------------------------------------------------------------------

You can also rotate the line by calling the rotateByAngle(angle) method of the class. For example, the following code will rotate the line 10 degrees from its current location:

varbitLine.rotateByAngle(10);

You can also supply a negative value to rotate it back.

Points of interest

The main problem faced here was setting the region for the line control. Because it can be a rotated line or the user can rotate the line whenever required, the coordinates can go into the negative when rotated.

History

  • May 14, 2007 - Original version posted

License

This article has no explicit license attached to it but may contain 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