Search code examples
excelvbauserform

Properly refresh frame picture


I have created a dashboard with the help of a userform. I've used a frame to load a background picture.

Userform

I want to create a button that will hide the menu on the right side, so the whole background picture can be seen. However, when I hide the menu (theyre labels and 1 multiform), a white square remains after the labels, so the picture cannot be seen.

Bug

I've tried various methods to fix this, however none of them worked so far. I use this to hide the menu:

Label23.Visible = False
Label20.Visible = False
Label22.Visible = False
Label24.Visible = False
Label51.Visible = False
MultiPage2.Visible = False

After these, I've tried to repaint the frame:

Frame1.Repaint

Tried to repaint the whole userform:

Me.Repaint

Tried to Reload the Picture:

Sub LoadSkin()
Dim Path As String
Path = ThisWorkbook.Path & "\Nechytat\Skins\" & Worksheets("Data").Range("R" & Worksheets("Data").Range("B4").Value).Value

        With ZZZDashboard.Frame1
            .Picture = LoadPicture(Path & ".bmp")
            .PictureSizeMode = fmPictureSizeModeStretch
            .Height = ZZZDashboard.Height
            .Width = ZZZDashboard.Width - ZZZDashboard.Frame2.Width
            .Left = ZZZDashboard.Frame2.Width
        End With
    End Sub

Tried the DoEvents, tried to call the userform_initialize again and even tried to combine these methods.

Private Sub CommandButton1_Click()
  Label23.Visible = False
  Label20.Visible = False
  Label22.Visible = False
  Label24.Visible = False
  Label51.Visible = False
  MultiPage2.Visible = False

  Frame1.Picture = LoadPicture("")
  DoEvents
  Frame1.Repaint
  Me.Repaint
  DoEvents
  Call LoadSkin
  Frame1.Repaint
  DoEvents
End Sub

None of them worked so far. This looks like an easy fix, but I just can't figure it out.


Solution

  • I suggest you create two pages in a multiPage. one has only the image for its background while the other has that image as well as the controls. The you control which page is visible by setting the value of the multiPage to the desired value. To hide the tabs that come with the multi page, position its top with a negative value on the form.