Results 1 to 3 of 3

Thread: [RESOLVED] Form Repainting not Working

  1. #1

    Thread Starter
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Resolved [RESOLVED] Form Repainting not Working

    Hi
    In the folloing code I am populating a multiselect listbox "LBox_Varied" based on a passed Range object "MyRange". This runs when the User form in opened.
    At the end of the code I am trying to resize the listbox to fit the number of records.
    ----.Height = .ListCount * RowHeight----

    My problem is that the form will not normally repaint, but if I include a msgbox command (commented out in the attached) it does repaint.

    Any ideas?

    Thanks
    Declan



    VB Code:
    1. Private Sub UserForm_Initialize()
    2.     Dim DimName As String
    3.     Dim RowHeight As Integer
    4.    
    5.     DimName = MyRange.Worksheet.Name
    6.     DimName = Right(DimName, Len(DimName) - 1)
    7.     DimName = Replace(DimName, "_", " ")
    8.     Me.Caption = "Select " & DimName
    9.    
    10.     RowHeight = 14
    11.    
    12.     With Me.LBox_Varied
    13.         .List = MyRange.Value
    14.            
    15.         For MyItem = 1 To .ListCount
    16.             .Selected(MyItem - 1) = .List(MyItem - 1, 1)
    17.         Next MyItem
    18.        
    19.         .Height = .ListCount * RowHeight
    20.        
    21.     End With
    22.    
    23.     Me.Repaint
    24.     'msgbox "anything"
    25. End Sub

  2. #2
    Fanatic Member dannymking's Avatar
    Join Date
    Jul 2005
    Location
    Darlington, North East UK
    Posts
    677

    Re: Form Repainting not Working

    Have you tried DoEvents after the repaint??
    Danny

    Never Think Impossible

    If you find my answer helpful then please add to my reputation

  3. #3

    Thread Starter
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: Form Repainting not Working

    Great, that worked.
    Just for my education, do you know why I needed to do this?

    Per the VB help file it would appear that the repaint method on its on should work.
    Quote:
    "The Repaint method is useful if the contents or appearance of an object changes significantly, and you don't want to wait until the system automatically repaints the area."

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width