如何保持在PictureBox中绘制的图像 [英] How to keep the image Drawn in PictureBox

查看:110
本文介绍了如何保持在PictureBox中绘制的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,C#.Net中的一个新人.

我试图制作像Paint Ms这样的应用程序,当然要简单得多,而且我陷入了困境.

问题是这样.

在pictureBox中,我在PictureBox上绘制网格线,然后读取.map(一个Mapper3文件)并想绘制到网格线上,但是当我绘制地图时,网格线消失了. br/>
我认为问题是由于在绘制地图时PictureBox图像变为空.我该如何克服,有什么花招吗?

感谢您从现在开始的回复,也很抱歉我的英语不好...

我最好的问候...

Hey everyone, a new guy here in C#.Net.

I''m trying to make an application like Ms Paint, of course much simpler, and I''m stuck.

The problem is this.

In pictureBox, I''m drawing grid lines on the PictureBox, after that I''m reading a .map(A Mapper3 file) and want to draw onto grid lines, but When I draw the map, The grid lines disappers.

I think the problem is because of the PictureBox Image becomes null while I''m drawing the map. How can I overcome this, is there any tricks?

Thanks for the replies from now on, and sorry for my bad English...

My best Regards...

推荐答案

没有什么比图形编辑器项目更具破坏性的了,然后在PictureBox中进行绘制. 从不做!

在CodeProject上有很多关于使用PictureBox的弊端的答案,但是人们一次又一次地犯此错误.
请查看我对以下问题的回答:
图片框重新加载后会丢失图纸 [如何从旧图纸中清除面板 [ ^ ].

请勿使用PictureBox

—SA
There is nothing more destructive to the project of graphical editor then drawing in the PictureBox. Never do it!

There was a good deal of answers here at CodeProject about the evil of using PictureBox, but people do this mistake again and again.
Please see my answers to these questions:
Picture box lose drawing after reloading[^],
How do I clear a panel from old drawing[^].

Don''t use PictureBox!

—SA


发生这种情况的原因有很多.

如您所说,您可以将Image属性设置为null,这将重置图片.解决方案:不要将Image属性设置为null.

另一种可能性与绘制网格线的方式和位置以及映射器文件有关.

您是否在图片框的绘画"事件中绘制这些图形?如果不是,那么无论何时更改任何图片框属性,甚至只是最小化和还原应用程序时,它们都会消失.
There are a number of reasons why this could happen.

As you say, you could be setting the Image property to null, which would reset the picture. Solution: Don''t set the Image property to null.

The other possibility has to do with how and where you are drawing the grid lines, and the mapper file.

Are you drawing these in the Paint event of the picture box? If you aren''t, then they will disappear whenever you make a change to any picture box property, or even just when you minimize and restore your application.


感谢您的快速答复OriginalGriff .

让我敞开心your.

1)首先,我没有将属性设置为null.
2)我用这种方法绘制网格线.

Thanks for the quick reply OriginalGriff.

Let me make your aspect wide open.

1) Firstly, I''m not setting the property to null.
2) I''m drawing the grid lines with this method.

public void SanIzCiz(Image bmp, PictureBox pictureBox, int SanIzCoz, Graphics g)
        {

            ImOrtamCizdir.genelBmpNesnesi = bmp;
            Pen kalem = new Pen(Brushes.Yellow);

            for (int i = SanIzCoz; i <= ImOrtamCizdir.genelBmpNesnesi.Width; i += SanIzCoz)
            {
                g.DrawLine(kalem, i, 0, i, ImOrtamCizdir.genelBmpNesnesi.Height);
            }

            for (int j = SanIzCoz; j <= ImOrtamCizdir.genelBmpNesnesi.Width; j += SanIzCoz)
            {
                g.DrawLine(kalem, 0, j, ImOrtamCizdir.genelBmpNesnesi.Width, j);
            }

            for (int i = 0; i < ImOrtamCizdir.genelBmpNesnesi.Width; i += SanIzCoz)
            {
                for (int j = 0; j < ImOrtamCizdir.genelBmpNesnesi.Width; j += SanIzCoz)
               {
                   g.FillRectangle(Brushes.Violet, i-1 , j-1, 4, 4);
                }
            }
            pictureBox.Image = ImOrtamCizdir.genelBmpNesnesi;

        }




这是一个类的方法,
的名字叫IzgaraCozunurlugu(在英语中意为GridResolution.)

然后在menuStripButton中调用此类方法.




This is a class''s method,
which name is IzgaraCozunurlugu(Which means GridResolution in Eng.)

and I''m calling this class method in a menuStripButton.

private void CizdirToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Bitmap bmp = new Bitmap(p_box_map.Width, p_box_map.Height);
            Graphics g;
            g = Graphics.FromImage(bmp);
            IzgaraCozunurlugu SanalIzgara = new IzgaraCozunurlugu();
            // Get the measure of the grids. 
            SanalIzgara.izgaraCozunurluguOku();
            int SanalIzgaraCozunurlugu = SanalIzgara.SanalIzgaraCozunurlugu();
            // Draw the Grids.
            SanalIzgara.SanIzCiz(bmp, p_box_map, SanalIzgaraCozunurlugu, g);
        }



因此,正如您所说,我不会在PictureBox_Draw事件中进行绘制.所以,我该怎么办?
嵌套事件是否可能?
另一个事件中的事件[是胡说八道](例如Button_Click事件中的PictureBox_Paint事件)?



So, as you say, I''m not drawing in a PictureBox_Draw event. So, how can I do it?
Does nested event''s possible?
Event in another event[Which is nonsense](Such as PictureBox_Paint event in a Button_Click Event)?


这篇关于如何保持在PictureBox中绘制的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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