?
Solved

How to group controls on form with bmp background

Posted on 2000-01-12
12
Medium Priority
?
167 Views
Last Modified: 2010-05-02
I have a form with a bmp backround that I need to center my controls on it when the screen is maximized or resized.

I can't center each control individually, as there are about 30 total, including text.

I wanted to group them in a frame, but the frame background can not be made transparent.

I found two messages on the exchange, one told me how to make the frame transparent, but it also make the controls inside it transparent.

The other mentioned MS Forms 2.0 Library.  Although there are some controls there that can be made transparent, none will accept pasting controls inside it and using the frame as a grouping tool.

How can I group my controls so all I need to do on form resize is center them ?

Thanks
0
Comment
Question by:supprog
  • 5
  • 4
  • 2
  • +1
12 Comments
 
LVL 32

Expert Comment

by:Erick37
ID: 2345496
Use a PictureBox as the container, set the .AutoRedraw True, and .BorderStyle to None. Then paint the background picture on the PictureBox to make it "seem" transparent.

Private Sub Form_Load()
    Picture1.AutoRedraw = True
End Sub

Private Sub Form_Resize()
    With Picture1
    .PaintPicture Form1.Picture, 0, 0, , , .Left, .Top
    End With
End Sub
0
 

Author Comment

by:supprog
ID: 2345577
Although this may work, the bmp I have is not the complete size of the form.

I have to use code to tile the bmp across the form.

Unless I would have to tile the bmp across the picture box.

But, then if the bmp inside picture box doesn't line up properly with the frame background, I do not know if it would look right.
0
 
LVL 32

Expert Comment

by:Erick37
ID: 2345634
Try:

Form1.Picture = Form1.Image
With Picture1
..PaintPicture Form1.Picture, 0, 0, , , .Left, .Top
End With
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 

Author Comment

by:supprog
ID: 2345805
All this does is make the background of the picture box, the same color as the underlying form, and does not use the tiled picture.

In this case, my form background, in design mode, is grey.  I placed a picture on it that I am using to tile.

All this does is make the picturebox grey.
0
 
LVL 32

Accepted Solution

by:
Erick37 earned 200 total points
ID: 2346030
This works:

Option Explicit

Private pic As StdPicture
Private dx As Integer, dy As Integer

Private Sub Form_Load()
    Set pic = LoadPicture("c:\windows\bubbles.bmp")
    Form1.AutoRedraw = False
    Picture1.AutoRedraw = False
    dx = ScaleX(pic.Width, vbHimetric, vbTwips)
    dy = ScaleX(pic.Height, vbHimetric, vbTwips)
End Sub

Private Sub Form_Paint()
    'tile the image on form
    Dim h As Integer, w As Integer
   
    For w = 0 To Form1.Width Step dx
    For h = 0 To Form1.Height Step dy
    Form1.PaintPicture pic, w, h
    Next
    Next
End Sub

Private Sub Picture1_Paint()
    'tile the image on pic box
    Dim h As Integer, w As Integer
   
    For w = 0 To Form1.Width Step dx
    For h = 0 To Form1.Height Step dy
    Picture1.PaintPicture pic, w - Picture1.Left, h - Picture1.Top
    Next
    Next
End Sub
0
 
LVL 1

Expert Comment

by:vbyuval
ID: 2346075
Leave the frame :
If you want three objects in a row -

Dim ObjName as Object
Dim ObjNumber as Integer,intTop as Integer,intLeft as Integer
Dim ObjLeft as Integer

'With this values you can place the group
intTop=int(Me.height/2)
intLeft=int(Me.Width/2)

'Controls is the collection of all the object in the form
For each ObjName in Controls
  ObjNumber=ObjNumber +1
'Each 4th object will be in the next line
  If (ObjNumber Mod 4)=0 then
    intTop=intTop+ObjName.Height
    ObjLeft=intLeft
  Else
    ObjLeft=ObjLeft+ObjName.Width
  End If
  ObjNumber.Left=ObjLeft
  ObjNumber.Top=intTop
Next

I didn't checked it cause I don't have a VB on this computer
but I think it's OK .

                                                             Enjoy
                                                         Yuval Amir
0
 

Author Comment

by:supprog
ID: 2346294
This will not work as some rows contain more than other row's.

Plus, my program is constantly changing, and the control's may change position.

That is why I need to group them, so I can change their positionany time I need to.
0
 

Author Comment

by:supprog
ID: 2346402
Erick27:

Major problem with your idea.  When I paste command buttons inside a picture box, they no longer accept user input.

You can no longer click on them.
0
 
LVL 32

Expert Comment

by:Erick37
ID: 2346514
This is not so in VB5; works fine for me.
0
 

Author Comment

by:supprog
ID: 2346560
This works great.  Although selecting items inside a picture box can be a pain.

Would have been nice if Microsoft added support for something like this.  Would make things a lot easier.

Thanks for the help
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2346629
Check out this question and answer:

http://www.experts-exchange.com/Q.10171899 


Cheers!
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2346631
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

589 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question