如何制作绘图字段? (就像CAD软件的草图环境一样) [英] How to make a drawing field? (Like sketching environment of CAD softwares)

查看:105
本文介绍了如何制作绘图字段? (就像CAD软件的草图环境一样)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好我是一名机械工程专业的学生。(所以我对编程知之甚少)

我想制作一个用理性Bezier绘制曲线的程序(我应该自己编写代码和不使用formGraphics.DrawBezier)。我最近开始学习c#,我对它很新。我已经搜索了很多而且非常困惑。



如何制作一个每次单击鼠标(在其中)返回一组(x)的字段,y)并在那里放一个点。选择一堆点(从3开始)后,它完成曲线(通过使用提供的有理bezier代码)。



问题看起来像我:

1.需要网格化字段。 (高分辨率)

2.该字段返回位置(x,y)。

3.该字段应获取一些输入并绘制它们。

4.该程序应该看起来像CAD软件的草图部分(只是在工作环境不是能力的情况下):D



我会很感激如果你告诉我,我应该学习上述内容。 :)

认为我对GUI几乎一无所知。



谢谢。



我尝试了什么:



搜索互联网并感到困惑! :D

Hi i am a mechanical engineering student.(so i don't know too much about programming)
I wanna make a program that draws curves with rational Bezier (I should write the code myself and not using formGraphics.DrawBezier). I've recently started learning c# and i am so new to it. I've searched alot and just got very confused.

How can i make a field that with each click of the mouse (within it) returns a set of (x , y) and puts a dot there. After choosing a bunch of points (starting with 3) it completes the curve (by using the provided rational bezier code).

The problem looks like to me as :
1. A gridded field is required. (with high resolution)
2. The field returns the position (x , y).
3. The field should get some inputs and draws them.
4. The program should look like the sketching part of the CAD softwares (just in case of working environment not the abilities) :D

I would appreciate if you tell me what should i learn to the above. :)
consider that I almost don't know anything about GUI.

thank you.

What I have tried:

searching the internet and getting confused !! :D

推荐答案

开始时非常简单:鼠标捕获的东西很简单。

在表单中添加一个面板 - 调用它myDrawing - 并为Panel处理两个事件:Paint和MouseClick。

在表单类中添加一个列表:

That's pretty simple to start with: the mouse capture stuff is trivial.
Add a Panel to a form - call it "myDrawing" - and handle two events for the Panel: Paint, and MouseClick.
Add a list to your form class:
private List<Point> points = new List<Point>();



现在,在MouseClick处理程序中,将位置添加到列表并使面板无效:


Now, in the MouseClick handler, add the location to the list and invalidate the panel:

private void myDrawing_MouseClick(object sender, MouseEventArgs e)
    {
    points.Add(e.Location);
    myDrawing.Invalidate();
    }



在Paint处理程序中,绘制点:


In the Paint handler, draw the points:

private void myDrawing_Paint(object sender, PaintEventArgs e)
    {
    Graphics g = e.Graphics;
    foreach (Point p in points)
        {
        g.FillEllipse(Brushes.Red, new Rectangle(p.X - 2, p.Y - 2, 4, 4));
        }
    }

对字段进行网格划分并不困难(这只是在保存位置之前舍入该位置并在Paint事件中绘制模糊线条的情况下需要他们)

这应该给你一个开始 - 画Bezier是一个复杂的位,但Wiki应该有所帮助:Bézier曲线 - 维基百科,免费的百科全书 [ ^ ]

不要指望这是第一次工作,并且不要指望它很容易 - 实施Bezier不是一项微不足道的练习!

查看图形类 [ ^ ],你会发现它有一个DrawPath方法,在绘制时可能对你有用实际曲线。

祝你好运!

Gridding the field isn't difficult (it's just a case of "rounding up" the location before you save it and drawing faint lines in the Paint event if you need them)
That should give you a start - to draw the Bezier is the complicated bit, but Wiki should help: Bézier curve - Wikipedia, the free encyclopedia[^]
Don't expect this to work first time, and don't expect it to be easy - implementing Bezier is not a trivial exercise!
Have a look at the Graphics class[^] and you see it has a DrawPath method whihc may be of use to you in drawing the actual curve.
Good luck!


这篇关于如何制作绘图字段? (就像CAD软件的草图环境一样)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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