使用OnPaint()方法 [英] using the OnPaint() method

查看:113
本文介绍了使用OnPaint()方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 https://qrcodenet.codeplex.com/wikipage?title=GraphicsRenderer&referringTitle=Renderer 将QRcode生成为WinForm应用程序,但我不知道我真的知道如何使用OnPaint()方法。



所以我有这个:

I am using https://qrcodenet.codeplex.com/wikipage?title=GraphicsRenderer&referringTitle=Renderer to generate QRcode into a WinForm application, but I don''t really know how to take use of the OnPaint() method.

So I have this:

public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
protected override void OnPaint(PaintEventArgs e)
        {
            QrEncoder encoder = new QrEncoder(ErrorCorrectionLevel.M);
            QrCode qrCode;
            encoder.TryEncode("link to some website", out qrCode);

            new GraphicsRenderer(
                new FixedCodeSize(200, QuietZoneModules.Two)).Draw(e.Graphics, qrCode.Matrix);

            base.OnPaint(e);
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            this.Invalidate();
        }
    }





我在表单中有一个简单的pictureBox,我只想生成QRcode图像在那里(如果可以在图片框中生成它)。



I have a simple pictureBox in the form and I just want to generate the QRcode image in there (if it is possible to generate it in a picturebox).

推荐答案

将代码从OnPaint方法移动到PictureBox.Paint事件,它应该工作为你期待。

虽然个人而言,我不会使用PictureBox - 我会选择一个Panel(如果你正在处理,你不需要PictureBox行李)画自己)
Move the code from the OnPaint method to the PictureBox.Paint event and it should work as you expect.
Though personally, I wouldn''t use a PictureBox for that - I''d go with a Panel instead (you don''t need the PictureBox "baggage" if you are handling the painting yourself)


这篇关于使用OnPaint()方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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