Hiding a button in another form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Justin88
    New Member
    • Jun 2010
    • 2

    Hiding a button in another form

    I know how to make the button hidden and visible, What I am trying to do is to tell the button to hide when a specific person logs in.

    So what I have is one database now with all the logins stored in it with a column called Security Level.

    At login the user will type their ID Password and their Security Level(Administr ator, Project Manager, Employee).

    What I'm not exactly sure how to do is to pull that SecurityLvl_txt .Text over to the button's so they know what level is being accessed and to tell them when and when not to hide.

    I know I need an if:

    if(SecurityLvl = Administrator)
    {
    button.visible = true
    }
    else
    {
    button.visible = false
    }

    Just a little confused on how to pull the input over into the other form I guess.
  • GaryTexmo
    Recognized Expert Top Contributor
    • Jul 2009
    • 1501

    #2
    You'll need to expose a property on the other form, perhaps the security level itself. In the set method of that property you can hide/show whatever you need.

    Here's a link to a tutorial on properties if you don't know what they are.

    Comment

    • tlhintoq
      Recognized Expert Specialist
      • Mar 2008
      • 3532

      #3
      Remember that in Object Oriented, event driven, coding the basic concept is that each class/form/object is responsible only for itself. There should be as little direct coding of Form2 inside Form1, as possible. You should try to code a lot of little black boxes that are ignorant of each other.

      If you have Form1, Form2, Form3, Form4, Class7 and so on... they should all subscribe to a custom "UserLogged In" event in your SecurityClass.

      When someone logs in, raise an event with a PrivledgesArgs. That argument tells all the subscribing forms/classes what privileges the new user has. Then it is up to the listening form/class to react to that.

      In other words, its not the job of Form1 to turn off controls of Form2. Let Form2 turn off its own controls, in response to the permissions of the new logged in user.

      Here is a tutorial that I wrote for events and one form reacting to events from another form.

      Comment

      Working...