首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

Picture控件彩色框绘制及擦除有关问题

2012-01-11 
Picture控件彩色框绘制及擦除问题PrivateSubDisplay1_MouseDown(ButtonAsInteger,ShiftAsInteger,XAsSingl

Picture控件彩色框绘制及擦除问题
Private   Sub   Display1_MouseDown(Button   As   Integer,   Shift   As   Integer,   X   As   Single,   Y   As   Single)
        If   IsSettngRoi(0)   =   True   Then
              isMouseDown(0)   =   True
              Display1.MousePointer   =   2   'vbCross
              Display1.DrawMode   =   vbXorPen
              Display1.Line   (Box_X0(0),   Box_Y0(0))-(Old_X(0),   Old_Y(0)),   vbWhite,   B
     
              Old_X(0)   =   X
              Old_Y(0)   =   Y
              Box_X0(0)   =   X
              Box_Y0(0)   =   Y           '初始值
        End   If
End   Sub

Private   Sub   Display1_MouseMove(Button   As   Integer,   Shift   As   Integer,   X   As   Single,   Y   As   Single)
          If   IsSettngRoi(0)   =   True   Then
                If   isMouseDown(0)   =   True   Then
                      '拖动鼠标来定义矩形的另外一个顶点,此时擦除前一个矩形,绘制新的矩形
                      Display1.Line   (Box_X0(0),   Box_Y0(0))-(Old_X(0),   Old_Y(0)),   vbWhite,   B
                      Display1.Line   (Box_X0(0),   Box_Y0(0))-(X,   Y),   vbWhite,   B
                      Old_X(0)   =   X
                      Old_Y(0)   =   Y
              End   If
        End   If
End   Sub

Private   Sub   Display1_MouseUp(Button   As   Integer,   Shift   As   Integer,   X   As   Single,   Y   As   Single)
        If   IsSettngRoi(0)   =   True   Then
              isMouseDown(0)   =   False
              Display1.MousePointer   =   vbDefault
              Display1.DrawStyle   =   vbSolid
          '     Display1.DrawMode   =   vbCopyPen
              Display1.Line   (Box_X0(0),   Box_Y0(0))-(X,   Y),   vbBlack,   B
              Old_X(0)   =   X
              Old_Y(0)   =   Y         '保存矩形的位置
        End   If
End   Sub

这里mouseup中框最终不能够绘制成彩色的,只有黑白的才能擦掉,怎么办呢?


[解决办法]
换成相同的颜色,我将你的你码稍改了一下:
Dim old_X(1) As Single
Dim old_Y(1) As Single


Dim Box_X0(1) As Single
Dim Box_Y0(1) As Single
Dim d As Boolean
Dim myCol As Long
Private Sub Display1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
d = True
display1.MousePointer = 2 'vbCross
display1.DrawMode = vbXorPen
'display1.Line (Box_X0(0), Box_Y0(0))-(old_X(0), old_Y(0)), mycol, B

old_X(0) = X
old_Y(0) = Y
Box_X0(0) = X
Box_Y0(0) = Y '初始值

End Sub

Private Sub Display1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

If d = False Then Exit Sub
'拖动鼠标来定义矩形的另外一个顶点,此时擦除前一个矩形,绘制新的矩形
display1.Line (Box_X0(0), Box_Y0(0))-(old_X(0), old_Y(0)), myCol, B
display1.Line (Box_X0(0), Box_Y0(0))-(X, Y), myCol, B
old_X(0) = X
old_Y(0) = Y

End Sub

Private Sub Display1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)

display1.MousePointer = vbDefault
display1.DrawStyle = vbSolid
'display1.DrawMode = vbCopyPen
display1.Line (Box_X0(0), Box_Y0(0))-(X, Y), myCol, B
old_X(0) = X
old_Y(0) = Y '保存矩形的位置
d = False
End Sub

Private Sub Form_Load()
myCol = RGB(0, 255, 255)
End Sub

[解决办法]
这样啊,明白了,那就先定义一个StdPicture对象(模块级),用来保存picturebox的picture,需要擦除的时候,重设picturebox的picture为我们预先保存的StdPicture对象,如果需要保存picturebox上图象的改变,就重新为StdPicture对象赋值

热点排行