如何在控件上绘制,使绘图不消失? [英] How to draw on Control so drawing doesn't disappear?

查看:197
本文介绍了如何在控件上绘制,使绘图不消失?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要显示在PictureBox中的图形文件我有:

I want to display graphic file in PictureBox I have:

private void btnLoad_Click(object sender, EventArgs e)
{
    if (dgOpenFile.ShowDialog() == DialogResult.OK)
    {
        Bitmap img = new Bitmap(dgOpenFile.FileName);
        picture.Width = img.Height;
        picture.Height = img.Height;
        g.DrawImage(img, 0f, 0f);
    }
}

这是先按g

private void Form1_Load(object sender, EventArgs e)
{
    g = picture.CreateGraphics();
}



但是,当我把我的表我的图像消失在窗外。我该如何防止?

But when I move my Form outside the window my picture disappears. How can I prevent that?

推荐答案

您应该做的任何自定义绘制的的OnPaint 控件的事件,使之持久。这将导致图形被每次控制器绘时间重绘

You should do any custom drawing in the OnPaint event of the control to make it persistent. This causes your drawing to be redrawn every time the control is painted.

然而,在这种情况下,这将是更容易使用,因为它被设计图片框

However, in this case it would be easier to use the picture box as it was designed:

picture.Image = img;

这篇关于如何在控件上绘制,使绘图不消失?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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