已测试Dim XStart As Single, YStart As Single Dim XOld As Single, YOld As SinglePrivate Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button <> 1 Then Exit Sub XOld = XStart XOld = YStart XStart = X YStart = Y DrawMode = 7 End SubPrivate Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button <> 1 Then Exit Sub Line (XStart, YStart)-(XOld, YOld) Line (XStart, YStart)-(X, Y) XOld = X YOld = Y End SubPrivate Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button <> 1 Then Exit Sub DrawMode = 13 Line (XStart, YStart)-(XOld, YOld) Line (XStart, YStart)-(X, Y) End Sub
这样: Option Explicit '显式声明模块中的所有变量 Dim mx As Single, my As Single, flag As Integer'mx,my为线段的起点位置(x,y) Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) mx = X my = Y flag = 1 Form1.MousePointer = 2 '定义鼠标指针为十字型指针 End SubPrivate Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) If flag = 1 Then Form1.Cls Line (mx, my)-(X, Y) 'X,Y为线段的移动光标位置(X,Y) End If End SubPrivate Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) Me.AutoRedraw = True flag = 0 Line (mx, my)-(X, Y) Set Me.Picture = Me.Image Form1.MousePointer = 0 Me.AutoRedraw = False End Sub
//这是画线吧画矩形的话,就改成这样: Option Explicit '显式声明模块中的所有变量 Dim mx As Single, my As Single, flag As Integer'mx,my为线段的起点位置(x,y) Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) mx = X my = Y flag = 1 Form1.MousePointer = 2 '定义鼠标指针为十字型指针 End SubPrivate Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) If flag = 1 Then Form1.Cls Line (mx, my)-(X, Y), , B 'X,Y为线段的移动光标位置(X,Y) End If End SubPrivate Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) Me.AutoRedraw = True flag = 0 Line (mx, my)-(X, Y), , B Set Me.Picture = Me.Image Form1.MousePointer = 0 Me.AutoRedraw = False End Sub
Dim XOld As Single, YOld As SinglePrivate Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button <> 1 Then Exit Sub
XOld = XStart
XOld = YStart
XStart = X
YStart = Y DrawMode = 7
End SubPrivate Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button <> 1 Then Exit Sub
Line (XStart, YStart)-(XOld, YOld)
Line (XStart, YStart)-(X, Y)
XOld = X
YOld = Y
End SubPrivate Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button <> 1 Then Exit Sub
DrawMode = 13
Line (XStart, YStart)-(XOld, YOld)
Line (XStart, YStart)-(X, Y)
End Sub
Option Explicit
'显式声明模块中的所有变量
Dim mx As Single, my As Single, flag As Integer'mx,my为线段的起点位置(x,y)
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
mx = X
my = Y
flag = 1
Form1.MousePointer = 2
'定义鼠标指针为十字型指针
End SubPrivate Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If flag = 1 Then
Form1.Cls
Line (mx, my)-(X, Y)
'X,Y为线段的移动光标位置(X,Y)
End If
End SubPrivate Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Me.AutoRedraw = True
flag = 0
Line (mx, my)-(X, Y)
Set Me.Picture = Me.Image
Form1.MousePointer = 0
Me.AutoRedraw = False
End Sub
Option Explicit
'显式声明模块中的所有变量
Dim mx As Single, my As Single, flag As Integer'mx,my为线段的起点位置(x,y)
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
mx = X
my = Y
flag = 1
Form1.MousePointer = 2
'定义鼠标指针为十字型指针
End SubPrivate Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If flag = 1 Then
Form1.Cls
Line (mx, my)-(X, Y), , B
'X,Y为线段的移动光标位置(X,Y)
End If
End SubPrivate Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Me.AutoRedraw = True
flag = 0
Line (mx, my)-(X, Y), , B
Set Me.Picture = Me.Image
Form1.MousePointer = 0
Me.AutoRedraw = False
End Sub
第一步:建立自己的位图CreateBitmap。
第二步:SetWindowLong,建立自己的窗体消息泵。
第三步:获得鼠标状态,如按键和位置,鼠标消息可以在自己的消息泵中处理,也可使用VB默认的过程来处理。。
第四步:根据鼠标状态绘制图形,MoveToEx,LineTo...
第五步:将绘制结果显示到窗体中BitBlt。
用API后,图形完全没有闪烁,由于我的机器上未装VB,所以不能给你全部代码,感兴趣可以再谈。