• Welcome to PlanetSquires Forums.

Background Images on Forms

Started by Petrus Vorster, October 19, 2023, 06:57:43 AM

Previous topic - Next topic

Petrus Vorster

Hi All

I saw an app my Wife uses from her employer and was stunned by just how professional and modern it looks.

A lot of Bells and Whistles that does not really do anything other than brighten up the display, gives a modern feeling and make it really pleasant to work work with.
(It was also immensely well written software with lots of functions)

I am also looking into perking up some of my stuff and it should be easily done with a few TECH backgrounds, creatings a menu like area with a background and buttons on top and things like that.

How do one place a backfround on a for on which you can place other controls?
Or perhaps an anchored Picture control, but it will not allow controls over it.

ANyone have a few ideas on how to incormorate backgrounds on forms, picture boxes or some means to put controls over images and so forth?




Hi Peter,

Here's a minimal example with a little help (OK, a lot of help) from José's templates. You might want to put some work into scaling the picture when the window is resized.

Enable the Form.Allevents event and don't forget to #include "afx\cgdiplus\cgdiplus.inc".

' frmMain form code file
'Normally this would be in the myprogram.bas file:
#include once "afx\cgdiplus\cgdiplus.inc"   

dim shared as paintstruct ps

Function frmMain_Button1_Click( ByRef sender As wfxButton, ByRef e As EventArgs ) As LRESULT
   print "click button1"
   Function = 0
End Function

Function frmMain_AllEvents( ByRef sender As wfxForm, ByRef e As EventArgs ) As LRESULT
   dim as hdc mhdc
   if e.Message = wm_paint then     
      mhdc = BeginPaint(frmmain.hWindow, @ps)     
         ' // Create a graphics object from the window device context
         DIM graphics AS CGpGraphics = mhdc
         ' // Get the DPI scaling ratio
         DIM rxRatio AS SINGLE = graphics.GetDpiX / 96
         DIM ryRatio AS SINGLE = graphics.GetDpiY / 96
         ' // Set the scale transform
         graphics.ScaleTransform(rxRatio, ryRatio)

         DIM pImage AS CGpImage = "D:\Safe\nestling.jpg"
         graphics.DrawImage(@pImage, 0, 0)
      EndPaint frmmain.hWindow, @ps

   end if
   Function = 0
End Function

You cannot view this attachment.

It's a start.


Petrus Vorster

Hi Phil

I think this is what I am looking for, thank you.

I want to create a "floating menu bar" using a child form and I think this will do the trick.

Thanks mate