lineto和moveto in c# [英] lineto and moveto in c#
问题描述
嗨,,, lineto和moveto是c和c ++在graphics.h库中的图形方法,,,我想在ac#中使用这些方法,请帮帮我
,,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
推荐答案
请参阅 控制台.SetCursorPosition() [ ^ ]。 除此之外,您需要使用Console.Write()来编写行的每个字符。
对于Windows窗体,使用 Graphics.DrawLine() [< a href =http://msdn.microsoft.com/en-us/library/system.drawing.graphics.drawline(v=vs.90).aspxtarget =_ blanktitle =New Window> ^ ]
/ ravi
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
使用基于使用Paint事件的C#本机绘图工具的替代方法,是获取Visual Basic PowerPacks线和形状控件:[ ^ ]。
使用这些工具,您无需明确关注笔,画笔,图形对象等。 />
这里有一个关于如何使用它们的教程:[ ^ ]。
这是C#中使用VB PowerPack LineShape的代码示例使用Microsoft.VisualBasic.PowerPacks绘制一条红色对角线,宽度为4像素,宽度为4像素,从左到右,形状为900,600:
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;
通过定义Click EventHandler:
By defining a Click EventHandler:
private void aLine_Click(object sender, EventArgs e)
{
MessageBox.Show("aLine clicked");
}
我们现在有一条可点击的行,如果有必要,你可以通过一些技巧(通常用于在表格上制作其他控件的技术)完全适用于线条和形状对象)。
请注意,Line总是在后面的上绘制所有其他控件:调用BringToFront()就不会导致错误,但不会产生任何影响。
在CodeProject上发表声明表示你无法成功继承Form或UserControl具有使用VB PowerPack工具创建的线条或形状,并使线条或形状起作用。我已经验证你确实可以使用VB工具从UserControl继承,并且继承控件中的行和形状工作。
你可能会采取如果您希望深入研究.NET中的绘图形状,请查看Erdal Halici 2013年关于CP的文章:[ ^ ]。
是否使用VB工具的成本(内存,性能)在你的C#应用程序中绘图是可接受的是你可以决定的东西。
我会选择只在我想持久的时候使用VB工具用户可以在运行时与交互的图形对象。
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.
这篇关于lineto和moveto in c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!