关于在可视C#中制作形状 [英] Regarding making shapes in visual C#

查看:128
本文介绍了关于在可视C#中制作形状的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,

我正在用Visual C#制作桌面应用程序,而该应用程序是Blister Inspection System.我想根据画框上的水泡制作图纸.为此,我必须根据用户输入绘制多个矩形,用户输入就像行和列的数量一样,如果假设用户输入2和3,则矩形应以2 * 3的方式绘制.我也想保持每个绘制的矩形之间的关系.有人可以帮助我吗?

谢谢

我尝试过的事情:

hey,

I am making a desktop application in visual c# and that application is Blister Inspection System. I want to make drawings as per the blister on picturebox. for that , i have to draw multiple rectangles based on the user input,user input is such like number of rows and columns, if suppose user enter 2 and 3 so that rectangles should be drawn as 2*3 manner.and i also want to maintain the relationship between each of the rectangles drawn.Would anyone can help me out regarding this?

Thank You

What I have tried:

public List<rectangle> listRec = new List<rectangle>();
        Graphics g;

  
        private void button1_Click(object sender, EventArgs e)
        {
            Rectangle rect = new Rectangle();
            rect.Size = new Size(80, 60);
            for (int x = 0; x < 2; x++)
            {
                rect.X = x * rect.Width;
                for (int y = 0; y <3 ; y++)
                {
                    rect.Y = y * rect.Height;
                    listRec.Add(rect);
                }
            }

            foreach (Rectangle rec in listRec)
            {
                g = pictureBox1.CreateGraphics();
                Pen p = new Pen(Color.Blue);
                g.DrawRectangle(p, rec);
            }




我已经尝试了上面的代码,但并不是按照我的要求,矩形被绘制成没有间距,它被绘制为表格或网格.




i''ve tried the above code ,but it is not as per my requirement,rectangles are drawn without spacing between them,it is drawn as table or grid.

推荐答案

如果要在它们之间留出空间,则必须添加它:
If you want space between them, you have to add it:
rect.X = x * (rect.Width + amountIWantBetweenThemHoriziontally);
...
rect.Y = y * (rect.Height + amountIWantBetweenThemVertically);


这篇关于关于在可视C#中制作形状的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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