如何在不使用PictureBox的情况下显示图像? [英] How to display Image without using PictureBox?

查看:107
本文介绍了如何在不使用PictureBox的情况下显示图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在不使用PictureBox的情况下显示图像?...是否有任何工具...这里我必须在c#中使用光栅类...应该怎么可能...任何想法...或任何其他工具...

How to display Image without using PictureBox?....is there any tool......Here i have to use raster class in c#...How it should it possible ...any idea ...or any other tool...

推荐答案

好主意!许多不认识谁在GDI +和System.Windows.Drawing表格中绘制图形的人经常滥用PictureBox类. PictureBox只是一个惰性"控件,旨在显示简单的静态图片.在做动画之类的任何事情或任何交互式PictureBox的尝试中,都是没有用的:它只会吃掉额外的资源,性能和开发时间,而没有提供有用的功能.

该怎么做呢?我在过去的解决方案中对此进行了解释:我清除了旧图纸中的面板 [
Good idea! The class PictureBox is often heavily abused by many who do not realize who graphics is done in Forms GDI+ and System.Windows.Drawing. The PictureBox is just a "lazy" control designed to show simple static picture. In all attempts to do anything like animation or anything interactive PictureBox is useless: it only eats up extra resources, performance and development time without offering and useful functionality.

What to do instead? I explain it in my past solution: How do I clear a panel from old drawing[^].

—SA


进行任何所需的控制,例如Panel并派生您的画布".然后在OnPaint事件期间绘制图像.
Take any control you want, e.g. Panel and derive your "canvas" thereof. Then paint the image during OnPaint event.
public class Canvas : System.Windows.Forms.Panel
{
    private System.Drawing.Image _image = null;


    public Canvas(System.Drawing.Image image)
    {
        _image = image;
    }


    protected override void OnPaint(PaintEventArgs e)
    {
        e.Graphics.DrawImage(_image, this.ClientRectangle);
    }
}


这篇关于如何在不使用PictureBox的情况下显示图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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