Graphics in VBA on a User form

squasher

New Member
Joined
May 1, 2004
Messages
2
Hi,

Does anyone know how to use VB commands like PSET.
circle, etc. on a user form in VBA.

I can't get the WINAPI commands to work because apparently
a user form in VBA doesn't have a hDC.

help please !!!

any 3rd party addins that give this functionality ?

thanks in advance
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
What exactly are you wanting to do? Based on your subject line, all you'd need to do is place an Image control on the userform and place the graphic (gif, jpg, bmp, etc) on the Image control. Or maybe you knew that and the issue is more complex? Post back with more details to increase the chances of suggestions you can use, if it's more than an Image control that's required.
 
Upvote 0
squasher said:
Hi,

Does anyone know how to use VB commands like PSET.
circle, etc. on a user form in VBA.

I can't get the WINAPI commands to work because apparently
a user form in VBA doesn't have a hDC.

help please !!!

any 3rd party addins that give this functionality ?

thanks in advance

Hi squasher, welcome to the board.
Yes, what exactly are you trying to achieve?
A Userform does have a hDC, but you will have to program that in to get it
as it is not an avail property of the FM20.dll
 
Upvote 0
Hi squasher

Welcome to the board

To get a userforms device context try this code:

Code:
Option Explicit

Private Declare Function GetForegroundWindow Lib "user32" () As Long
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Private Sub CommandButton1_Click()
Dim ret As Long
'get the handle of the foreground window which will be our form
ret = GetForegroundWindow()
'or search for it by it's classname and EXACT title, a much better way in my view, change classname to suit your version of Excel (I use 2002)
'ret = FindWindow("ThunderDFrame", "UserForm1")

'get the forms dc
ret = GetDC(ret)

End Sub

However, like the two posters above, maybe an image control would be easier

HTH
 
Upvote 0

Forum statistics

Threads
1,215,494
Messages
6,125,137
Members
449,207
Latest member
VictorSiwiide

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