Windows Develop Bookmark and Share   
 index > Windows Forms Designer > Somewhat simple question
 

Somewhat simple question

I am new to winforms development, but have been developing netforms for a while now, and had one quick quesiton.  I am developing an app (win forms) where I want only certian controls displayed at runtime depending on the user logged in.  Now, I know it can be done like so:

------------------------------

if userloggedIn = admin then
   control.visible = true
else
   control.visible = false

------------------

Or even have a function/sub that you pass the users credentials and control into and there set its properties, but there must be a better (I mean less typing) way to do this without developing two forms for every one.

Any ideas or examples?

Thx in Advance,

JS
MigrationUser 1  Tuesday, January 06, 2004 5:36 PM
Here's one way of doing it. It's not exactly less typing, but it hooks very nicely into your authentication scheme. You'll need to authenticate users using the System.Security namespace, but hopefully you're doing that anyway.

Dim user As Security.Principal.IPrincipal
user = Thread.CurrentPrincipal

'Enable top level menus that aren't enabled at startup
mnuTools.Enabled = user.Identity.IsAuthenticated
mnuToolsDatabaseMaint.Enabled = user.IsInRole("WxAdmin")
mnuToolsAdmin.Enabled = user.IsInRole("WxAdmin")
... and so on.

Here I'm enabling menu items, but the same thing holds for controls.

Don
MigrationUser 1  Tuesday, January 06, 2004 8:00 PM
thanks for the quick reply.  I think that will do it, becuase I am using win auth with the system and grouping users by AD groups.

JS
MigrationUser 1  Wednesday, January 07, 2004 12:21 AM

You can use google to search for other answers

Custom Search

More Threads

• Understanding ZOrder
• Separate the generated code for MyItem from that for custom control containing a MyItemCollection property
• Databindings on a UserControl
• Inexplicable design-time exception
• Control-wide events for custom user controls
• Serializing an user control in designer
• custom control for what
• How can I hide from grid "(name)" property of my control?
• self created icons
• TreeView bug? [modified]