3

Say, I have an Image control (which seems to be a window-less control) and I want to make sure that it is on top of a TextBox. No matter what I do, the Image control will not appear on top of the Text box.

Is there a way?

P.S. I know I can use a PictureBox, but it does not support transparency, thus I must have the Image control.

AngryHacker
  • 59,598
  • 102
  • 325
  • 594

5 Answers5

3

There is no way to place an image control over a normal textbox as they are drawn onto the form itself so will always be below any other windowed components.

If you have VB6 installation media there are drawn (windowless) versions of controls including a TextBox you can use that will (probably) do what you want; http://support.microsoft.com/kb/184687

A custom usercontrol of some kind if probably better .. what is it exactly you want to overlay the textbox with?

Alex K.
  • 171,639
  • 30
  • 264
  • 288
2

The Image Control is considered a graphical control, like shapes, so it is always inferior to text controls. If you really want a transparent image, you can use a Microsoft 2.0 Form instead(only if you have it). Images there can be on top of textboxes, and you can make it transparent by setting the Backstyle to Transparent(0).

  • 1
    The docs don't say anything about graphical controls and/or "inferior" controls. It does say that windowless controls are painted in the container's DC so can't possibly appear above any standard child control. Also, you cannot legally use Forms 2.0 library outside of MS Office, you certainly cannot ship it with your application -- i.e. MS Office has to be licensed separately on **client** machines to use Forms 2.0 in your VB6 application. – wqw Jun 21 '12 at 10:48
  • That all being said, I've used it in the past without problems, and it still works in that software today. Still, I agree in general with the other commenters that it is best to avoid if possible, – tcarvin Jun 21 '12 at 13:26
1

I've created a tranparent overlay control to add a kind of annotation layer on top of a VB6 app. I'll attempt to describe it from memory, and if that doesn't provide enough information then you can post back and I'll try to dig up the code.

First, add a new USerControl to you application. Give it a name like ImageEx, PictureEx, or TransparntImage. There are several properties that you will need to use. Ensure the control is Windowed, so it can sit on top of other windowed controls. Locate the MaskColor property and set it to Cyan (or whatever color you elect to use to indicate a tranparent area. There might be an addition property enable the masking behavior, just browse the properties. Set the control background color to that of the MaskColor. At this point you have an invisible control. In my control I painted on top of the surface for annotations, but you can PaintPicture or maybe even set the image property for a really simple approach.

Of course, to make this a re-usable control, you will want to code in your own properties that allow the MaskColor and image, etc to be set so that you can the drop one of these on any form you want.


Some links:

MaskColor Property

MackPicture Property

tcarvin
  • 10,715
  • 3
  • 31
  • 52
1

Completely different approach to my other answer (hence the seperate Answer), but you can set AutRedraw and ClipControls on your Form to false and it will allow the Image control to render on the same layer as a windowed control. You can get some flakey redrawing in some cases but for a quick solution you could try it.

http://msdn.microsoft.com/en-us/library/aa733621(v=vs.60)

tcarvin
  • 10,715
  • 3
  • 31
  • 52
0

1) Remove all your textboxes , labels and ... (But memorize their name and location in the form)

2) Go to (project > components) and mark the (Microsoft Forms 2.0 Object Library) then click ok

3) Now you can see new controls under your default controls in your toolbox...

4) Use its textbox and label controls instead of the default controls

5) Right click on your Image Control then click (Bring To Front)

Mahdi Jazini
  • 791
  • 9
  • 16