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

vb 拖动窗体时,控件闪烁如何解决

2012-05-02 
vb 拖动窗体时,控件闪烁怎么解决问题1:拖动窗体时,怎么解决控件闪烁的问题问题2:控件随着窗体放大而放大,

vb 拖动窗体时,控件闪烁怎么解决
问题1:拖动窗体时,怎么解决控件闪烁的问题

问题2:控件随着窗体放大而放大,但是当窗体缩放时不想让mschart控件的宽度改变
Public Sub ResizeForm(FormName As Form)
  Dim Pos(4) As Double
  Dim i As Long, TempPos As Long, StartPos As Long
  Dim Obj As Control
  Dim ScaleX As Double, ScaleY As Double
  ScaleX = FormName.ScaleWidth / FormOldWidth
  '保存窗体宽度缩放比例
  ScaleY = FormName.ScaleHeight / FormOldHeight
  '保存窗体高度缩放比例
  On Error Resume Next
  For Each Obj In FormName
  StartPos = 1
  For i = 0 To 4
  '读取控件的原始位置与大小
  TempPos = InStr(StartPos, Obj.Tag, " ", vbTextCompare)
  If TempPos > 0 Then
  Pos(i) = Mid(Obj.Tag, StartPos, TempPos - StartPos)
  StartPos = TempPos + 1
  Else
  Pos(i) = 0
  End If
  '根据控件的原始位置及窗体改变大小的比例对控件重新定位与改变大小
  If Obj = Frame3 Or Obj = Label3 Or Obj = Label4 Or Obj = Label5 _
  Or Obj = Label6 Or Obj = Label7 Or Obj = Label8 Or Obj = Label9 Or Obj = Label10 Or Obj = Label11 Or Obj = Label12 Or Obj = Label13 _
  Or Obj = Label14 Then
  Obj.Move Pos(0) * ScaleX, Pos(1) * ScaleY, Pos(2) * ScaleX, Pos(3) * ScaleY
  End If
  'If Obj = MSChart1 Then
  ' Obj.Move Pos(0) * ScaleX, Pos(1), Pos(2), Pos(3)
  'End If
  If Obj = ListView1 Then
  Obj.Move Pos(0) * ScaleX, Pos(1) * ScaleY, Pos(2) * ScaleX, Pos(3) * ScaleY
  End If
  If Obj = Frame2 Or Obj = Option1 Or Obj = Option2 Then
  Obj.Move Pos(0) * ScaleX, Pos(1) * ScaleY, Pos(2) * ScaleX, Pos(3) * ScaleY
  End If
  If Obj = Combo1 Then
  Obj.Move Pos(0) * ScaleX, Pos(1) * ScaleY, Pos(2) * ScaleX
  End If
  If Obj = Command1 Or Obj = Command2 Then
  Obj.Move Pos(0) * ScaleX, Pos(1) * ScaleY, Pos(2) * ScaleX
  End If
  If Obj = Frame1 Or Obj = Label1 Or Obj = Label2 Then
  Obj.Move Pos(0) * ScaleX, Pos(1) * ScaleY, Pos(2) * ScaleX, Pos(3) * ScaleY
  End If
  If Obj = DTPicker1 Or Obj = DTPicker2 Or Obj = DTPicker3 Or Obj = DTPicker4 Then
  Obj.Move Pos(0) * ScaleX, Pos(1) * ScaleY, Pos(2) * ScaleX, Pos(3)
  End If
 
  Next i
  Next Obj
  On Error GoTo 0
End Sub

[解决办法]
我回答第一个问题:设置AutoRedraw=true,另外,拖动窗体时不要绘图形。
[解决办法]

弄到容器里,拖动时设置成不可见。

[解决办法]
用这个方法可以在改变窗体的大小的同时改变控件的大小,且不闪烁
[解决办法]
先将窗体锁定,等控件调整完成后再进行重绘。

VB code
Private Declare Function LockWindowUpdate Lib "user32" (ByVal hwndLock As Long) As LongPublic Sub ResizeForm(FormName As Form)    LockWindowUpdate FormName.hWnd    ...    LockWindowUpdate 0&End Sub 

热点排行