Click here to Skip to main content
Licence CPOL
First Posted 14 May 2007
Views 28,151
Downloads 878
Bookmarked 12 times

C# Line Control with Rotate Option

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

About the Author

mamirbalouch

Software Developer (Senior)
Business Intelligence Technologies 360
Pakistan Pakistan

Member

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.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralMy vote of 5 Pinmembermanoj kumar choubey0:12 22 Feb '12  
QuestionRotate around one point Pinmemberkingofkings202922:32 14 Sep '11  
GeneralThank you! PinmemberOrlament20:39 23 Jan '11  
GeneralGreat Stuff! 2 Questions PinmemberDerek Leuridan20:13 9 Aug '10  
GeneralQuestion PinmemberJason Tepe9:45 17 Apr '08  
GeneralRe: Question Pinmembermamirbalouch21:22 23 Apr '08  
QuestionC# Line Control with Rotate option Pinmemberdenson8:44 22 May '07  
AnswerRe: C# Line Control with Rotate option Pinmembermamirbalouch4:57 23 May '07  
QuestionRe: C# Line Control with Rotate option Pinmemberdenson6:57 23 May '07  
AnswerRe: C# Line Control with Rotate option Pinmembermamirbalouch21:14 24 May '07  

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

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

Permalink | Advertise | Privacy | Mobile
Web03 | 2.5.120517.1 | Last Updated 14 May 2007
Article Copyright 2007 by mamirbalouch
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid