Link to home
Start Free TrialLog in
Avatar of glenn_r
glenn_r

asked on

vb.net 2005 how to grey out all controls on the main form

I have an app thats mdi and has a few 3rd party panel controls. I need to implement a 'lock application' feature where the user would click a button, the the entire app would appear disabled, and a unlock dialog box requesting password to unlock the app would display.

Currently I'm simulating the disabled app by opening a form, settings its opacity to 50%, removing its titlebar, and sizing/placing it in the main apps client area. I choose a form for my initial proof of concept as it has an opacity setting.

Questions:

2. I'm having a bit of trouble with the form as it seems to mess up the taskbar and the modality of the password dialog. Without the transparent form if you invoke a showdialog on the password form I can toggle between apps and the app/password dialog activate together. If I add the transparent form and toggle between apps the app sometimes displays without the password dialog even those its modal. Any ideas how to fix this?

1. Is there a better way then using a transparent form? Is it possible to use a panel or something and set its transparency. I can't get a panel to be transparent with vb.2005. Tried a bunch of suggestions I found while googling but can't get it to work.
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

See my answer here for a different approach:
https://www.experts-exchange.com/questions/27632423/VB-net-when-groupbox-is-visible-everything-in-the-back-darkens.html

It takes a screen shot of the form and then overlays a semi-transparent rectangle to get the disabled look.  Next it uses that composite image as the background of a panel that takes up the entire form.  You can display the login "dialog" inside that panel using containers (a groupbox in the example).
Avatar of glenn_r
glenn_r

ASKER

Sounds like an alternative, not sure if it will work if the form has toolbars, might not cover them in the client area.
Can't you just disable the form and display the login via ShowDialog()?  You pass in the owner to showdialog like this:  *simplified*
Public Class Form1

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Me.Enabled = False

        Dim f As New Form
        f.ShowDialog(Me)

        Me.Enabled = True
    End Sub

End Class

Open in new window

You can recursively lock (disable) all controls on the form.  Check the below link.  May be you could use it.

http://www.codeproject.com/Articles/37576/Extending-Forms-Control-Lock-and-Unlock
Why do you need to dis-able the main form? Calling a modal dialog with ShowDialog() rather than Show() would anyway render the main form in-accessible until you dispose of the modal. All youhave to do is ensure that the modal dialog only closes when a correct password has been entered (or closes the entire program should the user decide to cancel).
Avatar of glenn_r

ASKER

Customers specification is to grey out all the controls. For now I'm disabling the main form but depending on the control it does not look very good. For example when you disable the main form with a treeview control each node gets its label background turned grey, which looks terrible.
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial