Resize有三种状态,一种是Min,一种是Normal,一种是Max,你必须要注意的是,在系统Resize后的状态为Max和Min时是不能修改它的Width和height的,所以,你应该首先判断Myform.WindowState是否为0,否则,就不要修改窗体的尺寸,我猜测,这也是为什么你要在Form_Resize事件中加On Error Resume Next的原因吧?On Error Resume Next是投机取巧的办法,除非你的软件处于发行阶段,在开发阶段最好不要加这个冬冬

解决方案 »

  1.   

    不会吧,我有一个子程序也没有你的现象啊。
    程序如下:
    Dim sql As String, con As Long, re As BooleanPrivate Sub My_Stat()
    Adodc2.RecordSource = "select * from userlist where " & sql & "": Adodc2.Refresh
    If Not (Adodc2.Recordset.BOF Or Adodc2.Recordset.EOF) Then
    Dim money As Long, money1 As Long
    Dim sun As Long, sun1 As Long
    money = 0: sun = Adodc2.Recordset.RecordCount: Label3.Caption = "共 有 卡:" + Trim(CStr(sun)) + " 张": Adodc2.Recordset.MoveFirst
    For i = 1 To sun Step 1
    money = money + Adodc2.Recordset.Fields("remain"): Adodc2.Recordset.MoveNext
    Next
    Label4.Caption = "总 金 额:" + Trim(CStr(money)) + " 元": List1.Clear: money = 0: Adodc2.RecordSource = "select * from userlist where " & sql & "and zhekou=98": Adodc2.Refresh
    If Not (Adodc2.Recordset.BOF Or Adodc2.Recordset.EOF) Then
    sun = Adodc2.Recordset.RecordCount
    For i = 1 To sun Step 1
    money = money + Adodc2.Recordset.Fields("remain"): Adodc2.Recordset.MoveNext
    Next
    List1.AddItem ("共充值:" + CStr(sun) + " 张" + Space(7 - Len(CStr(sun))) + "累计金额:" + CStr(money) + " 元")
    End If
    money = 0: Adodc2.RecordSource = "select * from userlist where " & sql & "and zhekou=99": Adodc2.Refresh
    If Not (Adodc2.Recordset.BOF Or Adodc2.Recordset.EOF) Then
    sun = Adodc2.Recordset.RecordCount
    For i = 1 To sun Step 1
    money = money + Adodc2.Recordset.Fields("remain"): Adodc2.Recordset.MoveNext
    Next
    List1.AddItem ("充值卡:" + CStr(sun) + " 张" + Space(7 - Len(CStr(sun))) + "累计金额:" + CStr(money) + " 元")
    End If
    Adodc3.RecordSource = "select * from caid where tongzhi='0'": Adodc3.Refresh
    If Not (Adodc3.Recordset.BOF Or Adodc3.Recordset.EOF) Then
    sun1 = Adodc3.Recordset.RecordCount
    For i = 1 To sun1 Step 1
    money = 0: money1 = Adodc3.Recordset.Fields("money"): Adodc2.RecordSource = "select * from userlist where " & sql & "and remain=" & money1 & "and zhekou=100": Adodc2.Refresh
    If Not (Adodc2.Recordset.BOF Or Adodc2.Recordset.EOF) Then
    sun = Adodc2.Recordset.RecordCount
    For j = 1 To sun Step 1
    money = money + Adodc2.Recordset.Fields("remain"): Adodc2.Recordset.MoveNext
    Next
    If money1 > 9 Then
    List1.AddItem ("" & money1 & "元卡:" + CStr(sun) + " 张" + Space(7 - Len(CStr(sun))) + "累计金额:" + CStr(money) + " 元")
    Else
    List1.AddItem ("" & money1 & " 元卡:" + CStr(sun) + " 张" + Space(7 - Len(CStr(sun))) + "累计金额:" + CStr(money) + " 元")
    End If
    End If
    Adodc3.Recordset.MoveNext
    Next
    End If
    End If
    End SubPrivate Sub Command1_Click()
    sql = "False"
    If Check1.Value = 1 And Check2.Value = 0 Then
    sql = "jingban ='" & Trim(Combo1.Text) & "'"
    End If
    If Check1.Value = 0 And Check2.Value = 1 Then
    sql = "AccountDate >= cdate('" & DTPicker1.Value & "') And AccountDate <= CDate('" & DTPicker2.Value & "')"
    End If
    If Check1.Value = 1 And Check2.Value = 1 Then
    sql = "jingban ='" & Trim(Combo1.Text) & "'and AccountDate >= cdate('" & DTPicker1.Value & "') And AccountDate <= CDate('" & DTPicker2.Value & "')"
    End If
    If DTPicker1.Value > DTPicker2.Value Then '1
    MsgBox " 开始时间不能大于结束时间   ", 16, "Message"
    Else
    Adodc1.RecordSource = "select * from userlist where " & sql & " order by cardid": Adodc1.Refresh
    If Adodc1.Recordset.BOF Or Adodc1.Recordset.EOF Then '0
    MsgBox " 没有符合条件的记录   ", 48, "Message"
    Else
    Call My_Stat: re = True: Check1.Visible = False: Check2.Visible = False: Combo1.Visible = False: Label1.Visible = False: Command1.Visible = False: Command2.Visible = False: DTPicker1.Visible = False: DTPicker2.Visible = False
    If Me.Width < Screen.Width And Me.Height < Screen.Height Then '2
    Me.Width = Screen.Width * 0.6: Me.Height = Screen.Height * 0.85: Me.Move (Screen.Width - Me.Width) / 2, (Screen.Height - Me.Height) / 2
    End If
    DataGrid1.Left = 20: DataGrid1.Top = 50: DataGrid1.Height = Me.Height * 0.7: DataGrid1.Width = Me.Width - 150: Combo1.Left = 500: Combo1.Top = DataGrid1.Height + 80: Label2.Caption = "显示               从                   到": Label2.Left = 50: Label2.Top = DataGrid1.Height + 120: Label3.Left = 4600: Label3.Top = DataGrid1.Height + 600: Label4.Left = 4600: Label4.Top = DataGrid1.Height + 900: DTPicker1.Left = 2300: DTPicker1.Top = DataGrid1.Height + 80: DTPicker2.Left = 4500: DTPicker2.Top = DataGrid1.Height + 80: Command4.Left = 6410: Command4.Top = DataGrid1.Height + 80: Command2.Left = 6000
    Command2.Top = DataGrid1.Height + 1300: Command3.Left = 4500: Command3.Top = DataGrid1.Height + 1300: Frame1.Left = 150: Frame1.Top = DataGrid1.Height + 500: Frame1.Visible = True: Label2.Visible = True: Label3.Visible = True: Label4.Visible = True: DataGrid1.Visible = True: Combo1.Visible = True: DTPicker1.Visible = True: DTPicker2.Visible = True: Command2.Visible = True: Command3.Visible = True: Command4.Visible = True: Command3.SetFocus
    End If
    End If
    End SubPrivate Sub Command2_Click()
    Unload Me
    End SubPrivate Sub Command4_Click()
    sql = "jingban ='" & Trim(Combo1.Text) & "'and AccountDate >= cdate('" & DTPicker1.Value & "') And AccountDate <= CDate('" & DTPicker2.Value & "')"
    If Combo1.Text = "" Then '0
    MsgBox " 请选择经办人      ", 16, "Message"
    Else '0
    If DTPicker1.Value > DTPicker2.Value Then '1
    MsgBox " 开始时间不能大于结束时间   ", 16, "Message"
    Else
    Adodc1.RecordSource = "select * from userlist where " & sql & " order by cardid": Adodc1.Refresh
    If Adodc1.Recordset.BOF Or Adodc1.Recordset.EOF Then
    MsgBox " 没有符合条件的记录   ", 48, "Message": Label3.Caption = "共 有 卡:" + "0" + " 张": Label4.Caption = "总 金 额:" + "0" + " 元": List1.Clear
    Else
    Call My_Stat
    End If
    End If
    End If
    End SubPrivate Sub Form_Load()
    Check1.Left = 300: Check1.Top = 390: Combo1.Left = 1290: Combo1.Top = 330: Check2.Left = 300: Check2.Top = 900: DTPicker1.Left = 2310: DTPicker1.Top = 870: DTPicker2.Left = 2310: DTPicker2.Top = 1290: Label1.Left = 2040: Label1.Top = 1350: Command1.Left = 2730: Command1.Top = 1890: Command2.Left = 4080: Command2.Top = 1890: re = False: Combo1.AddItem ("早班"): Combo1.AddItem ("中班"): Combo1.AddItem ("夜班"): Me.Caption = "统计---" + user: RetVal = SetWindowPos(Me.hWnd, -1, Me.Left \ Screen.TwipsPerPixelX, Me.Top \ Screen.TwipsPerPixelY, 360, 190, SWP_SHOWWINDOWS): DTPicker1.Value = Date: DTPicker2.Value = Date: Combo1.Text = user
    End SubPrivate Sub Form_Resize()
    If WindowState <> 1 Then
    If re Then
    Me.Width = Screen.Width * 0.6: Me.Height = Screen.Height * 0.85
    Else
    RetVal = SetWindowPos(Me.hWnd, -1, Me.Left \ Screen.TwipsPerPixelX, Me.Top \ Screen.TwipsPerPixelY, 360, 190, SWP_SHOWWINDOWS)
    End If
    End If
    End Sub
    Dim sql As String, con As Long, re As BooleanPrivate Sub My_Stat()
    Adodc2.RecordSource = "select * from userlist where " & sql & "": Adodc2.Refresh
    If Not (Adodc2.Recordset.BOF Or Adodc2.Recordset.EOF) Then
    Dim money As Long, money1 As Long
    Dim sun As Long, sun1 As Long
    money = 0: sun = Adodc2.Recordset.RecordCount: Label3.Caption = "共 有 卡:" + Trim(CStr(sun)) + " 张": Adodc2.Recordset.MoveFirst
    For i = 1 To sun Step 1
    money = money + Adodc2.Recordset.Fields("remain"): Adodc2.Recordset.MoveNext
    Next
    Label4.Caption = "总 金 额:" + Trim(CStr(money)) + " 元": List1.Clear: money = 0: Adodc2.RecordSource = "select * from userlist where " & sql & "and zhekou=98": Adodc2.Refresh
    If Not (Adodc2.Recordset.BOF Or Adodc2.Recordset.EOF) Then
    sun = Adodc2.Recordset.RecordCount
    For i = 1 To sun Step 1
    money = money + Adodc2.Recordset.Fields("remain"): Adodc2.Recordset.MoveNext
    Next
    List1.AddItem ("共充值:" + CStr(sun) + " 张" + Space(7 - Len(CStr(sun))) + "累计金额:" + CStr(money) + " 元")
    End If
    money = 0: Adodc2.RecordSource = "select * from userlist where " & sql & "and zhekou=99": Adodc2.Refresh
    If Not (Adodc2.Recordset.BOF Or Adodc2.Recordset.EOF) Then
    sun = Adodc2.Recordset.RecordCount
    For i = 1 To sun Step 1
    money = money + Adodc2.Recordset.Fields("remain"): Adodc2.Recordset.MoveNext
    Next
    List1.AddItem ("充值卡:" + CStr(sun) + " 张" + Space(7 - Len(CStr(sun))) + "累计金额:" + CStr(money) + " 元")
    End If
    Adodc3.RecordSource = "select * from caid where tongzhi='0'": Adodc3.Refresh
    If Not (Adodc3.Recordset.BOF Or Adodc3.Recordset.EOF) Then
    sun1 = Adodc3.Recordset.RecordCount
    For i = 1 To sun1 Step 1
    money = 0: money1 = Adodc3.Recordset.Fields("money"): Adodc2.RecordSource = "select * from userlist where " & sql & "and remain=" & money1 & "and zhekou=100": Adodc2.Refresh
    If Not (Adodc2.Recordset.BOF Or Adodc2.Recordset.EOF) Then
    sun = Adodc2.Recordset.RecordCount
    For j = 1 To sun Step 1
    money = money + Adodc2.Recordset.Fields("remain"): Adodc2.Recordset.MoveNext
    Next
    If money1 > 9 Then
    List1.AddItem ("" & money1 & "元卡:" + CStr(sun) + " 张" + Space(7 - Len(CStr(sun))) + "累计金额:" + CStr(money) + " 元")
    Else
    List1.AddItem ("" & money1 & " 元卡:" + CStr(sun) + " 张" + Space(7 - Len(CStr(sun))) + "累计金额:" + CStr(money) + " 元")
    End If
    End If
    Adodc3.Recordset.MoveNext
    Next
    End If
    End If
    End SubPrivate Sub Command1_Click()
    sql = "False"
    If Check1.Value = 1 And Check2.Value = 0 Then
    sql = "jingban ='" & Trim(Combo1.Text) & "'"
    End If
    If Check1.Value = 0 And Check2.Value = 1 Then
    sql = "AccountDate >= cdate('" & DTPicker1.Value & "') And AccountDate <= CDate('" & DTPicker2.Value & "')"
    End If
    If Check1.Value = 1 And Check2.Value = 1 Then
    sql = "jingban ='" & Trim(Combo1.Text) & "'and AccountDate >= cdate('" & DTPicker1.Value & "') And AccountDate <= CDate('" & DTPicker2.Value & "')"
    End If
    If DTPicker1.Value > DTPicker2.Value Then '1
    MsgBox " 开始时间不能大于结束时间   ", 16, "Message"
    Else
    Adodc1.RecordSource = "select * from userlist where " & sql & " order by cardid": Adodc1.Refresh
    If Adodc1.Recordset.BOF Or Adodc1.Recordset.EOF Then '0
    MsgBox " 没有符合条件的记录   ", 48, "Message"
    Else
    Call My_Stat: re = True: Check1.Visible = False: Check2.Visible = False: Combo1.Visible = False: Label1.Visible = False: Command1.Visible = False: Command2.Visible = False: DTPicker1.Visible = False: DTPicker2.Visible = False
    If Me.Width < Screen.Width And Me.Height < Screen.Height Then '2
    Me.Width = Screen.Width * 0.6: Me.Height = Screen.Height * 0.85: Me.Move (Screen.Width - Me.Width) / 2, (Screen.Height - Me.Height) / 2
    End If
    DataGrid1.Left = 20: DataGrid1.Top = 50: DataGrid1.Height = Me.Height * 0.7: DataGrid1.Width = Me.Width - 150: Combo1.Left = 500: Combo1.Top = DataGrid1.Height + 80: Label2.Caption = "显示               从                   到": Label2.Left = 50: Label2.Top = DataGrid1.Height + 120: Label3.Left = 4600: Label3.Top = DataGrid1.Height + 600: Label4.Left = 4600: Label4.Top = DataGrid1.Height + 900: DTPicker1.Left = 2300: DTPicker1.Top = DataGrid1.Height + 80: DTPicker2.Left = 4500: DTPicker2.Top = DataGrid1.Height + 80: Command4.Left = 6410: Command4.Top = DataGrid1.Height + 80: Command2.Left = 6000
    Command2.Top = DataGrid1.Height + 1300: Command3.Left = 4500: Command3.Top = DataGrid1.Height + 1300: Frame1.Left = 150: Frame1.Top = DataGrid1.Height + 500: Frame1.Visible = True: Label2.Visible = True: Label3.Visible = True: Label4.Visible = True: DataGrid1.Visible = True: Combo1.Visible = True: DTPicker1.Visible = True: DTPicker2.Visible = True: Command2.Visible = True: Command3.Visible = True: Command4.Visible = True: Command3.SetFocus
    End If
    End If
    End SubPrivate Sub Command2_Click()
    Unload Me
    End SubPrivate Sub Command4_Click()
    sql = "jingban ='" & Trim(Combo1.Text) & "'and AccountDate >= cdate('" & DTPicker1.Value & "') And AccountDate <= CDate('" & DTPicker2.Value & "')"
    If Combo1.Text = "" Then '0
    MsgBox " 请选择经办人      ", 16, "Message"
    Else '0
    If DTPicker1.Value > DTPicker2.Value Then '1
    MsgBox " 开始时间不能大于结束时间   ", 16, "Message"
    Else
    Adodc1.RecordSource = "select * from userlist where " & sql & " order by cardid": Adodc1.Refresh
    If Adodc1.Recordset.BOF Or Adodc1.Recordset.EOF Then
    MsgBox " 没有符合条件的记录   ", 48, "Message": Label3.Caption = "共 有 卡:" + "0" + " 张": Label4.Caption = "总 金 额:" + "0" + " 元": List1.Clear
    Else
    Call My_Stat
    End If
    End If
    End If
    End SubPrivate Sub Form_Load()
    Check1.Left = 300: Check1.Top = 390: Combo1.Left = 1290: Combo1.Top = 330: Check2.Left = 300: Check2.Top = 900: DTPicker1.Left = 2310: DTPicker1.Top = 870: DTPicker2.Left = 2310: DTPicker2.Top = 1290: Label1.Left = 2040: Label1.Top = 1350: Command1.Left = 2730: Command1.Top = 1890: Command2.Left = 4080: Command2.Top = 1890: re = False: Combo1.AddItem ("早班"): Combo1.AddItem ("中班"): Combo1.AddItem ("夜班"): Me.Caption = "统计---" + user: RetVal = SetWindowPos(Me.hWnd, -1, Me.Left \ Screen.TwipsPerPixelX, Me.Top \ Screen.TwipsPerPixelY, 360, 190, SWP_SHOWWINDOWS): DTPicker1.Value = Date: DTPicker2.Value = Date: Combo1.Text = user
    End SubPrivate Sub Form_Resize()
    If WindowState <> 1 Then
    If re Then
    Me.Width = Screen.Width * 0.6: Me.Height = Screen.Height * 0.85
    Else
    RetVal = SetWindowPos(Me.hWnd, -1, Me.Left \ Screen.TwipsPerPixelX, Me.Top \ Screen.TwipsPerPixelY, 360, 190, SWP_SHOWWINDOWS)
    End If
    End If
    End Sub
      

  2.   

    当调用If Me.Width < 8070 Then Me.Width = 8070时,会产生另一次Resize事件,而窗体的大小单位为Twip时(vb默认),你指定的值不一定就是精确的匹配,所以Me.Width = 8070不一定使宽度变为8070,如果改变后的值小于8070那么,此程序将无限循环,所以屏幕闪动特别厉害!!
      

  3.   

    关注一下
    http://www.csdn.net/expert/topic/438/438407.shtm
    希望看看
      

  4.   

     保证你设定的height和width的值是15的倍数!!!!!!!
      

  5.   

    各位还有什么好的方法!!如金山词霸中一样,拖动窗体右下角的三角型调整窗体,当达到
    最少指定大小后,与用VB做的Form比较一下,有很大的区别!!
      

  6.   

    你的问题,并不是由Form产生的,应该是你窗体内控件过多。或程序相关触发太多造成的。
    再有可真是你机器的问题了。
      

  7.   

    以下代码在 .bas 中Option Explicit
    Public OldWindowProc As Long
    Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
    Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDest As Any, pSource As Any, ByVal ByteLen As Long)
    Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As LongPublic Const WM_GETMINMAXINFO = &H24Type POINTAPI
         x As Long
         y As Long
    End TypeType MINMAXINFO
            ptReserved As POINTAPI
            ptMaxSize As POINTAPI
            ptMaxPosition As POINTAPI
            ptMinTrackSize As POINTAPI
            ptMaxTrackSize As POINTAPI
    End Type
    Public Function SubClass1_WndMessage(ByVal hwnd As Long, ByVal Msg As Long, ByVal wp As Long, ByVal lp As Long) As Long
        
        If Msg = WM_GETMINMAXINFO Then        Dim MinMax As MINMAXINFO
            CopyMemory MinMax, ByVal lp, Len(MinMax)
            MinMax.ptMinTrackSize.x = 800
            MinMax.ptMinTrackSize.y = 600
            MinMax.ptMaxTrackSize.x = 1024
            MinMax.ptMaxTrackSize.y = 768
            CopyMemory ByVal lp, MinMax, Len(MinMax)
            SubClass1_WndMessage = 1
            Exit Function
        End If
        SubClass1_WndMessage = CallWindowProc(OldWindowProc, hwnd, Msg, wp, lp)
            
    End Function
    以下代码在 .frm 中:Option ExplicitPrivate Const GWL_WNDPROC = (-4)
    Private Sub Form_Load()
        
        OldWindowProc = GetWindowLong(Me.hwnd, GWL_WNDPROC)
        
        Call SetWindowLong(Me.hwnd, GWL_WNDPROC, AddressOf SubClass1_WndMessage)
        
    End Sub
    Private Sub Form_Unload(Cancel As Integer)
        
        Call SetWindowLong(Me.hwnd, GWL_WNDPROC, OldWindowProc)End SubPrivate Sub Form_Resize()    On Error Resume Next
            ListView1.Width = Me.Width - 90        ListView1.Height = Me.Height - (SBar1.Height + 460)End Sub
      

  8.   

    http://ygyuan.go.163.com/
    http://ygyuan.3322.net/