Drag Picture on Userform

AlexanderBB

Well-known Member
Joined
Jul 1, 2009
Messages
2,097
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
Is it possible to have a Picture on a UserForm and have its size change with the Form as you drag the bottom right corner ?
I have this working on some other platfoms (Access, VB6) but can't seem to manage it in Excel - or the Picture flashes
white bars while moving.
Any help much appreciated.
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Something quickly cobbled together worked first time for me. This is what I did, which I suggest you simply replicate for your first test:

1. Create a userform in a new workbook
2. Manuallly amend userform's Picture Size Mode property to 1-fmPictureSizeModeStretch
3. Insert picture directly onto the userform ( click on Picture property \ click box with 3 dots to browse to folder \ select a file )
4. Insert code as instructed below
5. Run the userform and drag right corner

Caveat
Leith's code may need updating if you are running 64-bit version of Excel
- if unable to do that yourself, then I suggest you start a new thread specifically asking for the code to be modified to handle both 32 & 64 bit

Credit for the code @Leith Ross
Here is the link https://www.mrexcel.com/forum/excel-questions/485489-resize-userform.html


In a Module
Code:
[COLOR=#006400]'Written: August 02, 2010                   Author:  Leith Ross
'Summary: Makes the UserForm resizable by dragging one of the sides. Place a call
'         to the macro MakeFormResizable in the UserForm's Activate event.[/COLOR]

Private Declare Function SetLastError _
   Lib "kernel32.dll" (ByVal dwErrCode As Long) As Long
   
Public Declare Function GetActiveWindow Lib "user32.dll" () As Long

Private Declare Function GetWindowLong Lib "user32.dll" Alias "GetWindowLongA" _
     (ByVal hWnd As Long, ByVal nIndex As Long) As Long
               
Private Declare Function SetWindowLong Lib "user32.dll" Alias "SetWindowLongA" _
     (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

Public Sub MakeFormResizable()
    Dim lStyle As Long, hWnd As Long, RetVal
    Const WS_THICKFRAME = &H40000, GWL_STYLE As Long = (-16)
  
    hWnd = GetActiveWindow
'Get the basic window style
    lStyle = GetWindowLong(hWnd, GWL_STYLE) Or WS_THICKFRAME
'Set the basic window styles
    RetVal = SetWindowLong(hWnd, GWL_STYLE, lStyle)
'Clear any previous API error codes
    SetLastError 0
'Did the style change?
    If RetVal = 0 Then MsgBox "Unable to make UserForm Resizable."
End Sub

In Userform code
Code:
Private Sub UserForm_Activate()
    MakeFormResizable
End Sub
 
Last edited:
Upvote 0
Thanks very much Yongle. I like that code, but like I had, the image falls apart with nasty white flashes when moved.
Is this expected/normal, or something weird happening here ?
 
Upvote 0
:confused: On my screen the image is perfect when dragged
- the image does not fall apart
- there are no nasty white flashes when moved
 
Upvote 0
Thanks very much Yongle. I like that code, but like I had, the image falls apart with nasty white flashes when moved.
Is this expected/normal, or something weird happening here ?

Can you show us the code you are using ? Maybe if you could upload here a simplified test userform workbook so we can reproduce the issue you are describing
 
Last edited:
Upvote 0
The code is exactly as posted by Yongle. But he doesn't have the problem.. I do but on XP using Excel 2010. Maybe that's part of it?
I do have a win10/Excel 2019 machine but there's a change there and no Windows drag anymore, just the outline and the image / picture
goes away until mouse up. I do not have the problem when that happens.
I have made a recording of the effect and would you like you and Yongle to see it, but AFAIK you can't upload a file here?
 
Upvote 0

Forum statistics

Threads
1,224,819
Messages
6,181,153
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top