绘制成矩形。 [英] Drawing to a rectangle.

查看:142
本文介绍了绘制成矩形。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将动态创建的图像绘制到矩形,但它似乎继续将其绘制到表单中。任何建议都会很棒。



I am trying to draw a dynamically created image to a rectangle but it seems to keep drawing it to the form. Any advice would be great.

Private Sub BGMap_Paint(sender As Object, e As PaintEventArgs) Handles BGMap.Paint
    'System Rectangle drawn in design time.
    Dim g As Graphics
    For X = 0 To 9
        For Y = 0 To 7
            If genArr(X, Y) = 2 Then
                lRect = New Rectangle(0, 0, 64, 64)
                dLRect = New Rectangle(X * 64, Y * 64, 64, 64)
                g.DrawImage(lBMP, dLRect, lRect, GraphicsUnit.Pixel)
            ElseIf genArr(X, Y) = 1 Or genArr(X, Y) = 0 Then
                lRect = New Rectangle(64, 0, 64, 64)
                dLRect = New Rectangle(X * 64, Y * 64, 64, 64)
                g.DrawImage(lBMP, dLRect, lRect, GraphicsUnit.Pixel)
            End If
        Next
    Next
End Sub





我使矩形onLoad无效,这是数组所在的位置从中填充图像。



I invalidate the rectangle onLoad which is where the array that the image is drawn from is populated.

推荐答案

首先,此代码应抛出未设置为对象实例的对象异常,因为您从未设置过值 g 。你的代码应该这样开始:

First, this code should be throwing a "Object not set to an instance of an object" exception because you never set the value of g. Your code should begin like this:
Private Sub BGMap_Paint(sender As Object, e As PaintEventArgs) Handles BGMap.Paint
    ''System Rectangle drawn in design time.
    Dim g As Graphics = e.Graphics







接下来,你是什么意思它一直把它绘制成形式?您的代码应该随时准备重绘表单的内容,因为Windows将根据需要重新绘制表单,由Windows确定。




Next, what do you mean by "It keeps drawing it to the form"?? Your code SHOULD be prepared to redraw the contents of the form at any time as Windows will repaint your form on an as-needed basis, determined by Windows.


这篇关于绘制成矩形。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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