Hi everyone, is there a possible way in moving the position of a picturebox anywhere inside an MDI form?


I tried to use the picturebox's left and top property through code but when the mdi form is loaded, the picture box is still aligned at the top, or at the left...(during the design time, VB doesn't allow in setting the align property of the picturebox to Align-None)

Though I haven't tried using any API, because i don't know what API should I use...any suggestions, or advise?

sample codes would be useful...

thank you very much..:)

Dani AI

Generated

Short version: this is VB/MDI behavior, not a buggy PictureBox. In VB6 the MDI parent is a special window — only controls that support an Align/Dock-style property can be attached to the MDI frame and controls placed there act like toolbars/menus rather than free-floating client content. That is why setting PictureBox.Left/Top on the MDI parent looks ignored. Putting an image into the MDIForm.Picture gives you a static background, but it does not let you freely place a PictureBox in the client area. (flylib.com)

Practical solution (what described, expanded): make a small MDI child form and use that as the “floating” picture container. Steps: create frmTool, set its MDIChild property to True (design time), set BorderStyle = 0 (None), Caption = "" and ControlBox/MaxButton/MinButton = False. Put your PictureBox on frmTool. From the MDI parent create and show the child, position it with Move (use ScaleX/ScaleY when you think in pixels) and adjust its z-order. Example (MDI parent code):

' in MDIForm (module-level)
Dim ft As frmTool

Private Sub Form_Load()
  Set ft = New frmTool
  ft.Show
  ' position at (100,50) pixels inside client area
  ft.Move ScaleX(100, vbPixels, vbTwips), ScaleY(50, vbPixels, vbTwips)
  ft.ZOrder vbSendToBack   ' vbBringToFront to make it float above children
End Sub

Using an MDI child like this is the usual pattern. (experts-exchange.com)

Extras & tips: keep a module-level reference to the toolbox form so you can re-center it on MDI resize:

Private Sub MDIForm_Resize()
  If Not ft Is Nothing Then
    ft.Left = (Me.ScaleWidth - ft.Width) \ 2
    ft.Top  = (Me.ScaleHeight - ft.Height) \ 2
  End If
End Sub

Use the ZOrder method to move the child behind or in front of other children. If you want the borderless child to be draggable add the standard ReleaseCapture/SendMessage trick in the child’s MouseDown handler. (vb-helper.com)

If the project is WinForms (VB.NET) instead of VB6: don’t add controls directly to the parent form — set the MdiClient background image (or set its BackgroundImageLayout) so the image sits in the MDI client area rather than in front of child forms. The MdiClient approach is the correct .NET equivalent. (vbmigration.com)

Notes: watch unit conversions (VB6 uses twips by default), and be aware an extra MDI child used as a background/toolbox may appear in the Window menu unless you filter it out.

Recommended Answers

All 5 Replies

Hi everyone, is there a possible way in moving the position of a picturebox anywhere inside an MDI form? [ATTACH]16691[/ATTACH]

I tried to use the picturebox's left and top property through code but when the mdi form is loaded, the picture box is still aligned at the top, or at the left...(during the design time, VB doesn't allow in setting the align property of the picturebox to Align-None)

Though I haven't tried using any API, because i don't know what API should I use...any suggestions, or advise?

sample codes would be useful...

thank you very much..:)

You may have just one picture inside the MDIForm. Under properties select a Bitmap picture. Try to write for eg. the Picture1.Left = 500 and Picture1.Top = 1000 inside the MDIForm Load and see... But, I doubt it'll work. The only way is just to fixing 1 picture throughout the MDIForm as I mentioned firstly.

commented: thank you for your quick response... +2

@Aslam Mansoor: You have an idea...but placing picture box all over the mdi form might cover up my mdichild forms and thus, not allowing my mdichild forms to show up...(that's vb's default behavior regarding the picture box and the mdi child forms)

But anyway....thank you for your response....I greatly appreciate it...:D

As you have found out, since the PB is a container control, you can have the PB anchored to any side of the MDIParent form but it cannot be free floating. However, you can make it look like it is free floating by using a MDI child with no caption and no toolbox with a borderstyle of none. Then you could size your PB to the size of the form...

Good Luck

commented: Tnank you for your help! +2

: Hey! Great idea!, I haven't try that....Now I can continue in creating a floating toolbox in my MDIForm! Thank you! :)

@Aslam Mansoor: You have an idea...but placing picture box all over the mdi form might cover up my mdichild forms and thus, not allowing my mdichild forms to show up...(that's vb's default behavior regarding the picture box and the mdi child forms)

But anyway....thank you for your response....I greatly appreciate it...:D

Dear Poisoned Heart
Open the MDIForm1 and under Properties you'll find Picture, there select a piture you like. And under Properties WindowState = Maximized. Here you'll get the picture all over the MDIForm.

Don't worry, your child forms will not be covered by the picture of the MDIForm.
Try and seeeeeeeeee. It should work...

Aslam

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.