Dynamic MDI Menus?

  • Thread starter Thread starter Matthew Speed
  • Start date Start date
M

Matthew Speed

I am developing an MDI database access app that will be used by people
with varying access rights. Is it possible to make menu items show or
be hidden based upon the authority of the user? BTW...the user's
access level is stored in the db and stored as a public variable upon
successful authentication.
 
* Matthew Speed said:
I am developing an MDI database access app that will be used by people
with varying access rights. Is it possible to make menu items show or
be hidden based upon the authority of the user? BTW...the user's
access level is stored in the db and stored as a public variable upon
successful authentication.

Yes, thia can be done. What's the problem?
 
Yes, thia can be done. What's the problem?

Okay, I have the MDI app set up. The first thing it does it open a
child window that asks the user for a login/password. In my _Load sub
for the MDI parent I have me.menu = nothing so that no menu will show.

I check against the DB. If they authenticate correctly I close the
login form and give control to the main MDI form. At this point I
want the menu to show. Additionally, the permissions for various
groups of people overlap so what people have access to varies.
Additionally, I would like to make it so that people who don't have
access to something don't even know that a particular action exists.
 
Hi Matthew,

Thanks for posting in the community.

From your description, you wants to know how to enable the menu item based
on the user.

The code line below will tell you who is the current logon user.
System.Security.Principal.WindowsIdentity.GetCurrent().Name
Also you can show a form to let the user login into, and you can
authenticated what access level the user will get and then show the MDI
Menu, by generating its menu item dynamically.

Here is some example for dynamically generating the menu.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfsystemwindowsformsmenuclassgetmainmenutopic.asp


Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi Matthew,


After reading your second reply, I think a dynamical MainMenu will be a
solution.
In the Form_Load event if MDI form, you can hide the menu item so that it
will not be found.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
' Create the MainMenu and the menu items to add.
Dim mainMenu1 As New MainMenu

Dim menuItem1 As New MenuItem
Dim menuItem2 As New MenuItem

Dim subMenuItem1 As New MenuItem

' Set the caption for the menu items.
menuItem1.Text = "File"
menuItem2.Text = "Edit"

'Add an subMenuItem and add its event handler
subMenuItem1.Text = "Test"
AddHandler subMenuItem1.Click, AddressOf m_Click


' Add 3 menu items to the MainMenu for displaying.
mainMenu1.MenuItems.Add(menuItem1)
mainMenu1.MenuItems.Add(menuItem2)

menuItem1.MenuItems.Add(subMenuItem1)

' Assign mainMenu1 to the form.
Menu = mainMenu1

'So that the sencond menu item will not found in the menu bar.
Menu.MenuItems(1).Visible = False
End Sub

Private Sub m_Click(ByVal sender As Object, ByVal e As System.EventArgs)
MsgBox("hello")
End Sub


If you have any concern on this issue, please feel free to post here.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top