创建图像查看器窗口控件 [英] Creating a image viewer window controll

查看:85
本文介绍了创建图像查看器窗口控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习GDI +,正在尝试创建带有滚动条的显示窗口(因此我一次只能看到部分图像,并且可以在其中滚动).我已经从几本书中通读了GDI +的基础知识,但是我没有在网上找到任何好的教程,也没有在我的书籍中找到有关做类似这样的更高级操作的信息.

关于指南的任何建议或有关如何执行此操作的示例代码?

这是我到目前为止所拥有的

protected override void OnPaint(PaintEventArgs e)
{
    base.OnPaint(e);
    if (Label != null)
    {
        using (Bitmap drawnLabel = new Bitmap(Label.LabelHeight, Label.LableLength, System.Drawing.Imaging.PixelFormat.Format1bppIndexed))
        using (Graphics drawBuffer = Graphics.FromImage(drawnLabel))
        {
            drawBuffer.ScaleTransform(_ImageScaleFactor, _ImageScaleFactor);
            foreach (Epl2.IDrawableCommand cmd in Label.Collection)
            {
                cmd.Paint(drawBuffer);
            }
            drawBuffer.ResetTransform();
        }
    }
}

我想将此内容绘制到 PictureBox 我控制并控制 HScrollBar ,但我不知道该怎么做.

P.S. 标签是我在命名空间中拥有的一个自定义类,它是一个对象,代表您将从标签打印机打印的标签.

解决方案

您需要做的是:

  • 在窗体上(或在UserControl中重用)托管面板控件
  • 将面板AutoScroll"属性设置为True
  • 使PictureBox控件成为Panel的子控件
  • 将PictureBox控件的大小调整为运行时包含的图像的大小

Panel控件将根据需要显示垂直和水平滚动条,为您提供所需的确切功能.

要进行自己的缩放,您可能实际上放弃了PictureBox控件.请按照上述步骤操作,但要在父面板中托管另一个Panel,而不是PictureBox,请根据需要调整其大小并处理其Paint事件以进行缩放.

I am learning GDI+ and I am trying to make a display window with scroll bars (so I can only see part of the image at a time and I can scroll around it). I have read through the basics of GDI+ from several books but I have not found any good tutorials online or in books available to me about doing more advanced things like this.

Any recommendations on guides or example code on how do do this?

Here is what I have so far

protected override void OnPaint(PaintEventArgs e)
{
    base.OnPaint(e);
    if (Label != null)
    {
        using (Bitmap drawnLabel = new Bitmap(Label.LabelHeight, Label.LableLength, System.Drawing.Imaging.PixelFormat.Format1bppIndexed))
        using (Graphics drawBuffer = Graphics.FromImage(drawnLabel))
        {
            drawBuffer.ScaleTransform(_ImageScaleFactor, _ImageScaleFactor);
            foreach (Epl2.IDrawableCommand cmd in Label.Collection)
            {
                cmd.Paint(drawBuffer);
            }
            drawBuffer.ResetTransform();
        }
    }
}

I would like to paint this in to a PictureBox I have on the control and control what is shown by a VScrollBar and HScrollBar but I don't know how to do that step.

P.S. Label is a custom class that I have in my namespace, it is a object that represents a label you would print from a label printer.

解决方案

What you need to do is:

  • Host a Panel control on a Form (or in a UserControl for reuse)
  • Set the Panel AutoScroll property to True
  • Make a PictureBox control a child of the Panel
  • Resize the PictureBox control to the size of the image it contains at runtime

The Panel control will show the vertical and horizontal scroll bars as needed giving you exactly the functionality you're looking for.

To do your own zooming you might actually forgo the PictureBox control. Follow the above steps but instead of a PictureBox, host another Panel inside the parent panel, size it as you need and handle its Paint event for the zooming.

这篇关于创建图像查看器窗口控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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