Can I Cover Controls on a Form with a Rectangle/Image/Something Else ? (1 Viewer)

cblaine99

Registered User.
Local time
Today, 01:50
Joined
Mar 10, 2016
Messages
29
Hello,

I have a form with quite a few controls. I may want to hide these controls based on the security level of the user.
Rather than set the visible property of each control to False, I would like to cover the controls with a rectangle
or some graphic so the controls won't be seen. Is this possible? I have drawn a large rectangle over the area
where the controls sit. In the rectangle's properties box I chose "Bring to Front". In Design Mode I don't see the controls
because they are covered by the rectangle. But in Form View the controls come to the front, and I can see the
rectangle's border.

It may not be "good practice" to hide controls this way. I simply want to know if they can be covered up or hidden
in some way other than setting the visible property to False.

Thank you.
 

isladogs

MVP / VIP
Local time
Today, 08:50
Joined
Jan 14, 2017
Messages
18,186
Well you could do it by setting the visible property of the rectangle to true/false as appropriate.😉
Check your rectangle fill isn't transparent.

However, I think you are making work for yourself unnecessarily
You can easily show / hide a group of controls at once using the Tag property with one line of code
See Set Controls - Mendip Data Systems (isladogs.co.uk)

EDIT: 15/12/2021 Updated link above
 
Last edited:

cblaine99

Registered User.
Local time
Today, 01:50
Joined
Mar 10, 2016
Messages
29
Well you could do it by setting the visible property of the rectangle to true/false as appropriate.😉
Check your rectangle fill isn't transparent.

However, I think you are making work for yourself unnecessarily
You can easily show / hide a group of controls at once using the Tag property with one line of code
See Set Controls

The visible property of the rectangle is true, and the fill color is gray. But when I go to Form View
the rectangle still appears behind the other controls.
Using the Tag property is a thought. But I am simply experimenting and wanted to see
if the controls could be covered up (as opposed to setting visible to False).

Thanks.
 

isladogs

MVP / VIP
Local time
Today, 08:50
Joined
Jan 14, 2017
Messages
18,186
Why spend time reinventing the wheel when a simple solution already exists?

EDIT
BTW if the textbox has focus it will always appear 'through' a rectangle placed over the top.
If you move the focus to another object, the rectangle would stay at the top.
However, in my opinion its a 'clunky' solution which can be done far better without the rectangles being used
 
Last edited:

cblaine99

Registered User.
Local time
Today, 01:50
Joined
Mar 10, 2016
Messages
29
Why spend time reinventing the wheel when a simple solution already exists?

EDIT
BTW if the textbox has focus it will always appear 'through' a rectangle placed over the top.
If you move the focus to another object, the rectangle would stay at the top.
However, in my opinion its a 'clunky' solution which can be done far better without the rectangles being used
I am experimenting and trying to find out how to cover controls so they aren't seen. It doesn't have to be a rectangle.
It could be something else - an image. So far the only solution I have found is to cover the controls with a very large command button.
The button has the same color as the form background, no caption, and has no macro to handle a click. The only disadvantage is that if the user clicks the command button the border is shown. To make the other controls visible again I change the visible property of the overlaying
command button to False.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 16:50
Joined
May 7, 2009
Messages
19,169
if you still insist on doing this, see the code behind
the Button of Form1.
see also the code on Load event of SampleForm..
 

Attachments

  • hideControls.zip
    31.6 KB · Views: 223

CJ_London

Super Moderator
Staff member
Local time
Today, 08:50
Joined
Feb 19, 2013
Messages
16,553
But when I go to Form View
the rectangle still appears behind the other controls.
presume you have set the rectangle to 'front' but certain controls will always be on top - subforms for example
 

isladogs

MVP / VIP
Local time
Today, 08:50
Joined
Jan 14, 2017
Messages
18,186
Did you look at my SetControls example app? Much easier approach than your experiments
 

GK in the UK

Registered User.
Local time
Today, 08:50
Joined
Dec 20, 2017
Messages
274
You can put a tab control on the form without the actual tabs and format it without borders etc so there's no indication it's actually there.

Put different controls on each tab page. Then set whichever tab page you want to be visible, all the controls will become visible.
 

cblaine99

Registered User.
Local time
Today, 01:50
Joined
Mar 10, 2016
Messages
29
if you still insist on doing this, see the code behind
the Button of Form1.
see also the code on Load event of SampleForm..
Hi, Sorry for the delay in replying.
Thanks for sending the sample code. It works fine. I noticed that the controls named Field1, etc. are textboxes. I was curious to see if the rectangle would also cover a command button. So I replaced Field1 with a command button. Then I ran it and selected a user with level=1. The command button was hidden by the rectangle.
But I am confused because I have a form with a command button and a rectangle positioned on top of it. When I run it the command button appears on top of the rectangle. Before running I right clicked the rectangle and set the Position property to "Bring to Front" and set BackStyle to Normal. For the command button I set the Position property to "Send to Back".
Do know what property to use to get the rectangle to cover up the command button? Does it depend on which was
drawn first?
Thanks!
 

cblaine99

Registered User.
Local time
Today, 01:50
Joined
Mar 10, 2016
Messages
29
Did you look at my SetControls example app? Much easier approach than your experiments
Yes I did. And your approach is the one I would recommend to others. But I am simply playing in a sandbox,
seeing what works and what doesn't; seeking alternative ways of accomplishing things; hacking you might say. I am not searching for an optimal soln.
Thx.
 

cblaine99

Registered User.
Local time
Today, 01:50
Joined
Mar 10, 2016
Messages
29
You can put a tab control on the form without the actual tabs and format it without borders etc so there's no indication it's actually there.

Put different controls on each tab page. Then set whichever tab page you want to be visible, all the controls will become visible.
Perfect solution. Thank you.
 

Users who are viewing this thread

Top Bottom