返回列表 上一主題 發帖

UserForm顯示問題

UserForm顯示問題

各位前輩
小的設定一個UserForm,執行時會根據,輸入的資料大小,而改變視窗的相對應大小,會先計算資料的筆數,再設定好視窗大小,才執行Show,但是有時會很正常的呈現,有時又會沒有照我設定的去改變大小
造成有些控制項不見,要是我用F8一步步的執行,就都正常,這個有解決的方法嗎?
clio

各位前輩,我後來試著很多次,在我的程式中加入DoEvents,而且是加在那一個位置上,就可以了,但是我也不清楚為什麼,要是有清楚的前輩,能否幫我解疑,感謝您

With UFLB
   
        .Caption = UFListBox_Caption
        .ListBox1.ListStyle = fmListStyleOption         '讓前端有一個勾選的框,可以更清楚是否有被選取
        .ListBox1.MultiSelect = LB_MultiSelect_Lng
        .ListBox1.List = LB_List_AR_Str
        
        'UserForm1的InsideHeight , 與InsideWidth,都為唯讀,不能改變其數值,這二個數值是指,UserForm的內部空間大小,因為UserForm還有抱括標頭與邊線,所以要取出其差距,再來加上InsideHeight,來設定Height;加上InsideWidth來設定Width。
        HeightGap_Sng = .Height - .InsideHeight
        WidthGap_Sng = .Width - .InsideWidth
   
        .ListBox1.Height = LB_Height_Sng
        .ListBox1.Width = LB_Width_Sng
        '上面二值要決定ListBox1的大小
        
        DoEvents                '需要加這一行,要不然有時下方的二個控制項OK與Cancel會無法顯示出來
        
        .OK.Height = OKC_Height_Sng
        .OK.Width = OKC_Width_Sng
        '上面二值要決定OK的大小
     
        .Cancel.Height = CancelC_Height_Sng
        .Cancel.Width = CancelC_Width_Sng
        '上面二值要決定Cancel的大小
     
        .ListBox1.Top = 0
        .ListBox1.Left = 0
        .OK.Top = .ListBox1.Top + .ListBox1.Height
        .OK.Left = 0
        .Cancel.Top = .OK.Top
        .Cancel.Left = .OK.Left + .OK.Width
        '上述是決定這三個控制項的排列位置
        
        .Height = .ListBox1.Height + .OK.Height + HeightGap_Sng
        .Width = .ListBox1.Width + WidthGap_Sng
        '設定UFListBox的呈現大小
        
        .ListBox1.ListIndex = -1
        '初始化ListBox1為無任何勾選
        
        .Show                                           'Initialize在前面「Set UFLB = New UFListBox」執行過了,所以這邊Show不會再執行
   
    End With
clio

TOP

原本 Height 的設定在 ListStyle = fmListStyleOption   之後      
        .ListBox1.ListStyle = fmListStyleOption         
        .ListBox1.MultiSelect = LB_MultiSelect_Lng
        .ListBox1.List = LB_List_AR_Str
......
        .ListBox1.Height = LB_Height_Sng
        .ListBox1.Width = LB_Width_Sng

把他改成 在 ListStyle = fmListStyleOption   之前      
變成
        .ListBox1.Height = LB_Height_Sng
        .ListBox1.Width = LB_Width_Sng

        .ListBox1.ListStyle = fmListStyleOption         
        .ListBox1.MultiSelect = LB_MultiSelect_Lng
        .ListBox1.List = LB_List_AR_Str

然後拿掉 Doevents
是否ok?

TOP

回復 3# jackyq


   感謝前輩,照妳這樣改就可以耶,是不是有什麼規定,要先設控制項的大小,再設定他的一些參數值,才能正常動作?
clio

TOP

(1)
listbox 會自動縮放 height
Private Sub CommandButton1_Click()
  ListBox1.ListStyle = fmListStylePlain
  ListBox1.ListStyle = fmListStyleOption
End Sub

(2)
listbox 有瑕疵
連按很多次 CommandButton1 後, 你會看到瑕疵
瑕疵出現後, 移動一下 Form
Private Sub CommandButton1_Click()
  h = ListBox1.Height
  ListBox1.ListStyle = fmListStylePlain
  ListBox1.ListStyle = fmListStyleOption
  ListBox1.Height = h
End Sub

TOP

回復 5# jackyq


    感謝前輩的解說…
clio

TOP

        靜思自在 : 能付出愛心就是福,能消除煩惱就是慧。
返回列表 上一主題