如何纠正图片框问题 [英] How Do I Correct a Picture Box Problem
问题描述
大家好,
我使用以下代码在Visual Basic中构建双温度刻度。
我在带有按钮的容器中构建了图片框在一个单独的单元格中,当我调试按钮时,直到您实际移动表单才会出现。如果我删除它的按钮就好了。
如果我删除底部的代码pictherm1.Image = bmp1它很好,但规模不建。
如果我构建没有容器的表单,它也可以正常使用按钮构建。
请任何人都可以帮助
提前谢谢
Nevjc
Hi All,
I am using the following code to build a dual temperature scale in Visual Basic.
I have built the picture box in a container with a button in a separate cell and when I debug the button does not appear until you physically move the form. If I remove the button its fine.
If I remove the code at the bottom pictherm1.Image = bmp1 its fine but the scale does not build.
If I build the form without containers its also fine and builds correctly with the button.
Please can anyone help
Thank you in advance
Nevjc
Imports System.Drawing.Drawing2D
Imports System.IO.Ports
Public Class Form1
Dim bmp1 As Bitmap = New Bitmap(165, 550)
Dim temperature1 As Double = 10
Dim temperature2 As Double = 10
Dim WithEvents sp As New SerialPort
Private Sub pictherm1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles pictherm1.Paint
Dim g As Graphics = Graphics.FromImage(bmp1)
g.Clear(Color.White)
' fill temperature1
If temperature1 > 100 Then temperature1 = 100
g.FillRectangle(Brushes.Green, 48, 525 - CInt(temperature1 * 5), 10, CInt(temperature1 * 5))
' fill temperature2
If temperature2 > 100 Then temperature2 = 100
g.FillRectangle(Brushes.Green, 108, 525 - CInt(temperature2 * 5), 10, CInt(temperature2 * 5))
'draw scale
g.DrawLine(Pens.Black, 60, 525, 60, 25)
g.DrawLine(Pens.Black, 105, 525, 105, 25)
' minor ticks
For i As Integer = 25 To 525 Step 5
g.DrawLine(Pens.Black, 50, i, 60, i)
g.DrawLine(Pens.Black, 105, i, 115, i)
Next
'major ticks
Dim f As Font = New Font("Verdana", 10, FontStyle.Regular)
Dim scale As Integer
For i As Integer = 525 To 25 Step -25
g.DrawLine(Pens.Black, 45, i, 60, i)
g.DrawLine(Pens.Black, 105, i, 120, i)
scale = (525 - i) / 5
g.DrawString(Str(scale), f, Brushes.Black, 65, i - 8)
Next
pictherm1.Image = bmp1
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
End Sub
End Class
推荐答案
Dim g As Graphics = Graphics.FromImage(bmp1)
为什么?正确的 Graphics
对象是
Why? The correct Graphics
object is part of
ByVal e As System.Windows.Forms.PaintEventArgs
即
I.e.
Dim g As Graphics = e.Graphics
你不需要 pictherm1.Image = bmp1
行。
这篇关于如何纠正图片框问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!