画线c# [英] drawing lines c#

查看:64
本文介绍了画线c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想分享Windows窗体页面上的行。两条连续线之间的距离相等。我怎么做?。水平和垂直lines.thanks

I want to share the lines on the page of the windows form. the distance between two successive lines is equal. how i can??.horizontal and vertical lines.thanks

推荐答案

处理表单Paint事件并绘制它们 - 你可以使用PaintEventArgs参数的Graphics属性来绘制on。

然后:

Handle the form Paint event and draw them - you can use the Graphics property of the PaintEventArgs parameter to draw on.
Then:
Graphics g = e.Graphics;
int spacing = 25;
for (int x = spacing; x < Width; x += spacing)
   {
   g.DrawLine(Pens.Black, x, 0, x, Height);
   }
for (int y = spacing; y < Height; y += spacing)
   {
   g.DrawLine(Pens.Black, 0, y, Width, y);
   }


使用Paint Event绘制在屏幕上的绘图线,然后有绘图线对象(向量),可以点击,移动等的行。



OriginalGriff向您展示了如何使用Paint事件;对于line-as-objects,你可以使用VB.NET的'Shape Controls,它易于在C#中使用。



在这种情况下,它听起来像您可能想要模拟一种网格,您可以在其中放置内容或控件。如果这是正确的,那么您可能希望查看WinForms中的TableLayoutPanel控件(在VS ToolBox的容器选项卡中)。但是,这不会给你(轻松)没有左边垂直边框的效果。



如果你多说一下你将要做什么到/用线,如何使用它们,你可以获得更有针对性的建议。



是否有可能只是放一个背景图片您的网格在表格或面板上会满足您的需求吗?具有透明度的高分辨率.png图形(如果您愿意)对于这种类型的图形来说尺寸非常小。



例如,我可以创建一个1024x768 24位.png文件,网格由数百行组成,并保存透明度,大小不超过5k字节(在PhotoShop CS6中:其他绘图程序应该给出可比较的结果)。
There's drawing lines in the sense of drawing onto the screen by using the Paint Event, and, then, there is drawing lines that are "objects" (vectors), lines that could be clicked-on, moved, etc.

OriginalGriff has shown you how to use the Paint event; for lines-as-objects, you'd could use VB.NET's 'Shape Controls, which are easy to use in C#.

In this case, it sounds like you may be wanting to simulate a kind of a grid into which you will place content, or Controls. If that's correct, then you might want to look at the TableLayoutPanel Control in WinForms (in the 'Containers Tab in the VS ToolBox). That would, however, not give you (easily) the effect of having no left vertical border.

If you say a little more about what you are going to do to/with the lines, how you will use them, you can get more focused advice.

Is it possible that just putting a background image of your grid on a Form, or Panel would meet your needs ? A high-resolution .png graphic with transparency (if you wish) would be very small in size for this type of graphic.

For example, I can create a 1024x768 24-bit .png file with a grid composed of several hundred lines, and save it with transparency, for under 5k bytes in size (in PhotoShop CS6: other drawing programs should give comparable results).


这篇关于画线c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆