Click here to Skip to main content
15,867,488 members
Articles / Multimedia / GDI+
Article

C# Line Control with Rotate Option

Rate me:
Please Sign up or sign in to vote.
3.06/5 (12 votes)
14 May 2007CPOL 80.8K   3.1K   14   11
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:

C#
//--------------------------------------------------------------------------
//  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:

C#
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Business Intelligence Technologies 360
Pakistan Pakistan
I have a Masters Degree in Information Technology, supported by a Bachelors Degree in Information Technology. I am working as a software developer for five years. I have a good experience in developing business applications including Accounting, Payroll, Inventory and Student Information systems. I have also developed an application name Virtual Reception. Which is a Artificial Intelligence based, interactive application.

Comments and Discussions

 
Questionrotate a complete 360 degrees Pin
jeff gonzales29-Oct-12 7:37
jeff gonzales29-Oct-12 7:37 
GeneralMy vote of 5 Pin
Manoj Kumar Choubey22-Feb-12 0:12
professionalManoj Kumar Choubey22-Feb-12 0:12 
QuestionRotate around one point Pin
kingofkings202914-Sep-11 22:32
kingofkings202914-Sep-11 22:32 
GeneralThank you! Pin
Orlament23-Jan-11 20:39
Orlament23-Jan-11 20:39 
GeneralGreat Stuff! 2 Questions Pin
Derek Leuridan9-Aug-10 20:13
Derek Leuridan9-Aug-10 20:13 
GeneralQuestion Pin
Jason Tepe17-Apr-08 9:45
Jason Tepe17-Apr-08 9:45 
GeneralRe: Question Pin
mamirbalouch23-Apr-08 21:22
mamirbalouch23-Apr-08 21:22 
QuestionC# Line Control with Rotate option Pin
denson22-May-07 8:44
denson22-May-07 8:44 
AnswerRe: C# Line Control with Rotate option Pin
mamirbalouch23-May-07 4:57
mamirbalouch23-May-07 4:57 
QuestionRe: C# Line Control with Rotate option Pin
denson23-May-07 6:57
denson23-May-07 6:57 
AnswerRe: C# Line Control with Rotate option Pin
mamirbalouch24-May-07 21:14
mamirbalouch24-May-07 21:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.