VB2008中用GDI+画图的问题
用以下代码在PictureBoxTemperature001中绘图,怎么会没有显示?语法没有任何错误。控件PictureBoxTemperature001位于窗体Form...
用以下代码在PictureBoxTemperature001中绘图,怎么会没有显示?语法没有任何错误。
控件PictureBoxTemperature001位于窗体Form1中的一个控件 TabControl 上
若PictureBoxTemperature001直接在窗体Form1中可以显示。
输入时Me. 后面自动出现的PictureBoxTemperature001
'图形显示
Dim graTemp001 As Graphics = Me.PictureBoxTemperature001.CreateGraphics
Dim intWidthAll, intHeightAll As Integer
intWidthAll = PictureBoxTemperature001.Width
intHeightAll = PictureBoxTemperature001.Height
'绘制矩形
Dim intX1, intY1, intWidth, intHeight, intWWW As Integer
intWWW = 10 '矩形到Picture边界的距离
intX1 = intWWW : intY1 = intWWW
intWidth = intWidthAll - 2 * intWWW : intHeight = intHeightAll - 2 * intWWW
Dim MyPen As New Pen(Color.BlueViolet, 2)
Dim MyPen1 As New Pen(Color.Red, 3)
Dim rect As New Rectangle(intX1, intY1, intWidth, intHeight)
'左上角位于 (intX1, intY1) 的矩形。该矩形的宽度为 intWidth,高度为intHeight
graTemp001.DrawRectangle(MyPen, rect) 展开
控件PictureBoxTemperature001位于窗体Form1中的一个控件 TabControl 上
若PictureBoxTemperature001直接在窗体Form1中可以显示。
输入时Me. 后面自动出现的PictureBoxTemperature001
'图形显示
Dim graTemp001 As Graphics = Me.PictureBoxTemperature001.CreateGraphics
Dim intWidthAll, intHeightAll As Integer
intWidthAll = PictureBoxTemperature001.Width
intHeightAll = PictureBoxTemperature001.Height
'绘制矩形
Dim intX1, intY1, intWidth, intHeight, intWWW As Integer
intWWW = 10 '矩形到Picture边界的距离
intX1 = intWWW : intY1 = intWWW
intWidth = intWidthAll - 2 * intWWW : intHeight = intHeightAll - 2 * intWWW
Dim MyPen As New Pen(Color.BlueViolet, 2)
Dim MyPen1 As New Pen(Color.Red, 3)
Dim rect As New Rectangle(intX1, intY1, intWidth, intHeight)
'左上角位于 (intX1, intY1) 的矩形。该矩形的宽度为 intWidth,高度为intHeight
graTemp001.DrawRectangle(MyPen, rect) 展开
1个回答
展开全部
因为一刷新图就消失了,控件 TabControl上会自动刷新,在Form1_Paint中绘制可避免
或者改成下面的代码
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
PictureBoxTemperature001.Image = Nothing
Dim intWidthAll, intHeightAll As Integer
intWidthAll = PictureBoxTemperature001.Width
intHeightAll = PictureBoxTemperature001.Height
Dim bm As New Bitmap(intWidthAll, intHeightAll)
Dim graTemp001 As Graphics = Graphics.FromImage(bm)
'绘制矩形
Dim intX1, intY1, intWidth, intHeight, intWWW As Integer
intWWW = 10 '矩形到Picture边界的距离
intX1 = intWWW : intY1 = intWWW
intWidth = intWidthAll - 2 * intWWW : intHeight = intHeightAll - 2 * intWWW
Dim MyPen As New Pen(Color.BlueViolet, 2)
Dim MyPen1 As New Pen(Color.Red, 3)
Dim rect As New Rectangle(intX1, intY1, intWidth, intHeight)
'左上角位于 (intX1, intY1) 的矩形。该矩形的宽度为 intWidth,高度为intHeight
graTemp001.DrawRectangle(MyPen, rect)
PictureBoxTemperature001.Image = bm
PictureBoxTemperature001.Refresh()
graTemp001.Dispose()
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询