Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
2.33/5 (2 votes)
See more:
hi,,,lineto and moveto are a graphical method in c and c++ in graphics.h library,,,i wanna to use these methods in a c#,,,please help me
Posted
Comments
ali_vampire 5-Nov-13 15:55pm    
i need these methods in windows form
Sergey Alexandrovich Kryukov 5-Nov-13 18:46pm    
Then add a tag: "WinForms". You always need to tag application type or UI library/framework as soon as UI is concerned.
—SA

See Console.SetCursorPosition()[^].  Other than that you'll need to use Console.Write() to write each character of your line.

For Windows Forms, use Graphics.DrawLine()[^]

/ravi
 
Share this answer
 
v3
Comments
ali_vampire 5-Nov-13 15:56pm    
i need these methods in windows form
Ravi Bhavnani 5-Nov-13 16:02pm    
That vital piece of information was missing from your original question. See my updated solution.
ali_vampire 5-Nov-13 16:09pm    
thanks bro,,,drawline use instead of lineto i think,,,please help me about moveto method,,,
Ravi Bhavnani 5-Nov-13 16:20pm    
Did you read the documentation on Graphics.DrawLine() in my updated solution?
ali_vampire 5-Nov-13 16:26pm    
yeah,,,,a just know drawline is instead of lineto,,,this is my code in c,,,please translate moveto method for me to c#
void Circle(int xc,int yc,int R)
{
moveto(xc+R,yc);
for(int teta=0;teta <360;teta++)
{
x=R*cos(teta * 3.14 /180);
y=R*sin(teta * 3.14 /180);
lineto(xc+x,yc,y);
}
}
An alternative to using C#'s native drawing facility which is based on using the Paint Event, is to get the Visual Basic PowerPacks "Line and Shape" controls: [^].

Using those tools, you do not need to explicitly concern yourself with pens, brushes, graphic objects, etc.

There's a tutorial on how to use them here: [^].

Here's an example of code in C# that uses the VB PowerPack LineShape facility to draw a red diagonal line 4 pixels in width from the top, left to bottom, right of a Form of size 900,600:
// required
using Microsoft.VisualBasic.PowerPacks;
//
// somewhere in your code ...
ShapeContainer canvas = new ShapeContainer();
canvas.Parent = this;
LineShape aLine = new LineShape(0, 0, 900, 600);
aLine.Parent = canvas;
aLine.BorderStyle = System.Drawing.Drawing2D.DashStyle.Solid;
aLine.BorderWidth = 4;
aLine.BorderColor = Color.Red;
aLine.Click += aLine_Click;
By defining a Click EventHandler:
C#
private void aLine_Click(object sender, EventArgs e)
{
    MessageBox.Show("aLine clicked");
}
We now have a "clickable" line, and a line you could, if necessary, make movable by some trickery (the techniques commonly used to make other Controls on a Form movable don't quite work with the line and shape objects).

Note that the Line is always drawn on the Form behind all other Controls: calling BringToFront() on it will not cause an error, but will have no effect.

Statements have been made on CodeProject that you cannot successfully inherit from a Form or UserControl which has lines, or shapes, created with the VB PowerPack Tools, and have the lines, or shapes, "work." I have verified that you can, indeed, inherit from a UserControl using the VB Tools, and the lines and shapes "work" in the inheriting Control.

You might take a look at Erdal Halici's 2013 article here on CP if you wish to go deeply into drawing shapes in .NET: [^].

Whether the "cost" (memory, performance) of using the VB tools for drawing in your C# application is acceptable is something only you can decide.

I would choose to use the VB Tools only when I wanted persistent graphic objects the user could interact with at run-time.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900