如何绘制这些静态或动态图形? [英] How to Draw Static or Dynamic graphs like those?

查看:142
本文介绍了如何绘制这些静态或动态图形?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从这个网站学了很长时间,但这实际上是我第一次出现在这里,这是我的第一个问题,我是一个土木工程师,我正在编写一个设计挡土墙的软件,我需要绘制如下所示的图形,使其成为静态或动态的(我的意思是通过动态可以通过上下数字工具更改图形的尺寸,并且更改在图形中可见),这些应该是准备好的形式来帮助用户进入降级。在哪里我可以找到一个来源来学习这个?
i知道我可能是在处理最聪明的人在编程,所以请注意,编程不是我的专业,我不是那么好,把我当作初学者..非常感谢你

解决方案

以下是您需要将图纸添加到程序中的简短介绍: Winforms WPF ?对于你的图形类型 WinForms 会做;对于3D和动画 WFP 来说是更好的选择,但是以更陡的学习曲线为代价。

1 - 了解Winforms中的基本图形模型:




  • 必须将绘制到控件绘画事件中绘制,或从那里触发


  • Windows会小心刷新绘图时,外部事件有例如覆盖它。


  • 无论何时更改数据,用户都应该能够触发paint事件。添加一个包含 sketchPanel.Invalidate(); 作为代码的刷新按钮。




2 - 添加一个控件来绘制表单,然后按照您的喜好添加 anchor dock 。使用面板进行绘图,给它一个不错的名称,比如剪接板并创建它的 Paint 事件(通过在事件属性窗格中双击它)



3 - 所有绘图操作发生在 Graphics 目的。在 Paint 事件中,它被提供为 e.Graphics 。如果您更愿意绘制自己的函数,例如public drawMyWall(Graphics G),则可以在Paint事件中调用它并传入e.Graphics对象。



<4> - 使用的方法是


  • DrawLine 用于创建行

  • DrawString 用于编写测量标签
  • FillPolygon 用于绘制彩色墙或地球或水体

  • DrawPolygon



所有坐标均以像素为单位,相对于 sketchPanel ;因为您的用户输入将以米或毫米为单位,您必须转换这些数字。计算外墙的尺寸并将它们缩放到面板的尺寸!

Draw- / FillPloygon方法也期望一个点数组

要创建它,你应该首先声明一个 List< Point> wallpoints = new List< Point>(); ,然后添加您需要的每个点: wallpoints.Add(new Point(someX,someY));
这两个顺序都必须遵循(CW CCW),并且每个的坐标必须根据每个的输入测量计算点。一个简单的重力墙将只有4点,但更复杂的墙壁将有一打或更多..



当您的列表完成后,您可以使用例如FillPolygon方法是这样的:

pre $ e $ g $ e $ g $ e $ e $ G $ e $ G ephics.FillPolygon(Brushes.Orange,wallpoints.ToArray());

由于您计算输入测量值的所有点,绘图将完全动态。



您可能首先要忽略标签等。此外,您可能需要为计算的点添加偏移量,以便将绘图移动到面板上或多或少居中的位置。



我希望这有助于......


I have been learning from this site for really long time, but this is actually my first appearance here, that is my first question, I am a civil Engineer and i am writing a software for the design of Retaining Walls, I need to draw figures like these shown below ,to be static or dynamic , (i mean by dynamic that i can change the dimensions of the graph via up-down numeric tool and the changes are visible at the graph,), these should be a ready forms to help the user entering the demotions.where i can find a source to learn this? i know i may be dealing with the smartest people in programing so please note that programing is not my major , i am not that good , consider me as a beginner ..thank you so much

解决方案

Here is a short introduction to the things you need to add drawings to your program:

0 - Decide on the platform: Winforms or WPF? For your kind of graphics WinForms will do; for 3D and animation WFP would be the better choice but at the cost of a steeper learning curve.

1 - Understand the basic graphics model in Winforms:

  • All things drawn onto a control must be drawn in the paint event or be triggered from there

  • Windows will take care of refreshing the drawing whenever outside events have e.g. covered it.

  • The user should be able to trigger the paint event by invalidating the control whenever he has changed the data. Add a refresh button with sketchPanel.Invalidate(); as its code.

2 - Add a control to draw on to the form and anchor or dock it as you like. Use a panel for drawing on, give it a nice name, say sketchPanel and create its Paint event ( by doubleclicking it in the event properties pane)

3 - All drawing operations happen on a Graphics object. In the Paint event it is provided as e.Graphics. If you would rather draw in a function of its own, say public drawMyWall(Graphics G) you can call it in the Paint event and pass in the e.Graphics object.

4 - The methods to use are

  • DrawLine for creating lines
  • DrawString for writing the measurement labels
  • FillPolygon for drawing a colored wall or the earth or water bodies
  • DrawPolygon for drawing an outline of the wall

All will take coordinates in pixel units relative to the sketchPanel; as your user input will be in meters or millimeters you will have to convert the numbers. Calculate the outer wall dimensions and scale them to the panel's size!

The Draw-/FillPloygon methods also expect an array of Points.

To create it you should first declare a List<Point> wallpoints = new List<Point>(); and then add each point you need: wallpoints.Add(new Point(someX, someY) ); Here both the order must be followed (CW or CCW) and the coordinates must each be calculated from the input measurements for each Point. A simple Gravity Wall will have only 4 points but the more complicated walls will have a dozen or more..

When your List is complete you can use in in e.g. the FillPolygon method like this:

e.Graphics.FillPolygon(Brushes.Orange, wallpoints.ToArray() );

Since you calculate all points from the input measurements the drawing will be completely dynamic.

You may want to leave out labels etc. at first. Also you may want to add an offset to the points you calculate to move the drawing to a more or less centered position on the panel.

I hope that helps..

这篇关于如何绘制这些静态或动态图形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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