Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Visibility change causes menu items to scroll
Message
De
28/07/2008 16:37:09
 
 
À
25/07/2008 14:14:53
Information générale
Forum:
ASP.NET
Catégorie:
Formulaires
Versions des environnements
Environment:
C# 3.0
OS:
Vista
Divers
Thread ID:
01333256
Message ID:
01334694
Vues:
17
Andrus,

I don't have time to play with this right now, but I think you could probably have a recursive method that "walks down" through the menuitems to copy the sub-items if they exist.

~~Bonnie



>>If you figure out a workaround before I do, let us know.
>
>I have 250 item winforms menu system designed using Windows forms designer in MDI parent form.
>Some menu items should not be visible to user who logs in.
>
>I have also command "Login as different user" in this MDI parent form which allows other user to log in without exiting main form.
>For this command I need to make some other menu items visible.
>
>The workaround may be to clone whole menu tree and remove items which should be not visible.
>
>I tried code below but CopyTo() copies only top level menu items. Child items are not copied. So child items are destroyed in Load and not restored if new user logs in.
>
>
>
partial class MainForm : Form {
>
>    ToolStripItem[] Copy;
>
>    protected override void OnLoad(EventArgs e) {
>        Copy = new ToolStripItem[MainMenuStrip.Items.Count];
>        MainMenuStrip.Items.CopyTo(Copy, 0);
>        SetVisibility(MainMenuStrip.Items);
>}
>
>    void NewUser_Click(object sender, EventArgs e) {
>        MainMenuStrip.Items.Clear();
>        MainMenuStrip.Items.AddRange(Copy);
>        // create copy again for next user
>        Copy = new ToolStripItem[MainMenuStrip.Items.Count];
>        MainMenuStrip.Items.CopyTo(Copy, 0);    SetVisibility(MainMenuStrip.Items);
>    }
>
>    void SetVisibility(ToolStripItemCollection items)        {
>        foreach (ToolStripItem item in new IsolatorCollection(items))
>        {
>        if (item.Tag != null)
>            if ( CurrentUserShoundNotSeeThis(item.Tag))
>                items.Remove(item);
>            // enumerate sub-items (if could have them)
>            ToolStripDropDownItem dropItem = item as ToolStripDropDownItem;
>            if (dropItem != null)
>                SetVisibility(dropItem.DropDownItems);
>        }
>}
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform