We help IT Professionals succeed at work.

How can I create a shape (oval) over a picture box and see both of them ?

novologik
novologik asked
on
Medium Priority
2,466 Views
Last Modified: 2008-03-06
I create two picture box one over the other. I want to add a shape (Oval) over them but I want to see every thing at the same time.

Depending of the user choice, each picture box or shape can be visible or invisible. When I try to put the shape over the picture box ... it always go behind ...... I would like to be able to draw someting over a picture box .....

Please help me....

Thanks in advance !!!!
Comment
Watch Question

Commented:
You can use the Picture1.Circle method to draw an oval.

.Circle [Step] (x, y), radius, [color, start, end, aspect]


Picture1.Circle (3000, 3000), 1000, vbBlue, , , 0.5

Open in new window

The reason your shape control is disappearing behind the picturebox is because the picturebox control is a container with an opaque background.  When you draw your shape on the form, draw it onto the picturebox rather than the form and then resize it.

If you want to actually draw the elipse on the picturebox at runtime rather than using a control then you can do that too using the examples below.  The first two parameters (in brackets) are the x and y co-ordinates of the elipse.  The next parameter is the radius followed by the colour of the line.  You don't need the next two to draw an elipse and the final parameter is the aspect ratio.  An aspect ratio of 1 is a circle.  An aspect ratio less than 1 will make the elipse wider than it is tall and an aspect ratio greater than 1 will make it taller than it is wide.
'Perfect Circle
Picture1.Circle (x, y), 20, vbRed, , , 1
 
'Elipse twice as wide as high
Picture1.Circle (x, y), 20, vbRed, , , .5
 
'Elipse twice as high as wide
Picture1.Circle (x, y), 20, vbRed, , , 1.5

Open in new window

Author

Commented:
Thank for your comment, but it's not what I need. The Oval should be over the picturebox not inside, it should be bigger than the picturebox..... It's why I try with a shape component .....
 
Do you mean the elipse should be kind of around the picturebox control but the corners of the picturebox are outside of the elipse?

Is there any reason you can't use an imagebox control instead of picturebox?

Author

Commented:
Yes it's what I mean.

Wiith a imagebox it works....

The only reason why I don't want to use an imagebox, it's because I will have to change around 90 control in two different form, reposition them, etc.... Do you know an easy way to change them?
There is another way of doing this but I'm trying to figure out the maths involved!  Basically, draw your shape around the picturebox and then draw an elipse with the same dimensions in the picturebox.

Alternatively, if changing to image controls won't cause any other problems you can change them in bulk by editing your .frm file in notepad.

A picturebox control in your form will look like this:

   Begin VB.PictureBox Picture1
      Height          =   2295
      Left            =   360
      ScaleHeight     =   2235
      ScaleWidth      =   3435
      TabIndex        =   0
      Top             =   360
      Width           =   3495
   End

An image control on your form will look like this:

   Begin VB.Image Image1
      Height          =   2415
      Left            =   4080
      Top             =   480
      Width           =   3135
   End

You might have some extra properties in there depending on what properties you've set at design time.  BACK UP your .frm file and then do a find and replace VB.PictureBox with VB.Image.  Save your .frm file and open your project.  When displaying your modified form for the first time you will get a message saying there are errors - this is because of the extra properties that the picturebox control has that don't exist in the image control.  Just click ok and save the form.  The unsupported properties will disappear and all your pictureboxes will have been replaced with image controls.

Author

Commented:
Thank you very much, every thing works, and it was very fast to change.... Thank you