Home Forums WinForms controls Other WinForms controls MdiList support in SmartMenuBar

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #18120 |

    Earlier I sent a post about MdiList support in the SmartMenuBar. The original post doesn’t seem to have made it to the forum for some reason. I also sent an email to support (see below) and received a message saying that the feature was not provided and that they did not have any plans on implementing it at this time.

    Has anyone out there dealt with this type of problem while using the SmartMenuBar? If so, could you please share your solution?

    Thanks.

    My Email
    ————
    I was wondering if the .Net SmartMenuBar supported the MdiList property that the standard MainMenu class in .Net provides? I looked at the documentation and in the support forums, but didn’t find anything that indicated support for this existed. If it does, could you please forward links to the documentation. Or if it doesn’t do you plan on adding it in the future?

    Response
    ————
    This feature is not supported by the control. As of now, we have no short term plans to add features to our Xceed SmartUI For .NET. The control might receive updates in the future however, I have not time frame to offer nor can I guarantee it.

    Imported from legacy forums. Posted by flahan (had 3501 views)

    User (Old forums)
    Member
    Post count: 23064

    We try to avoid having duplicates of the same question in our systems. If you require an answer from the community, I will gladly leave the message on the forum.

    Imported from legacy forums. Posted by Matt (had 215 views)

    User (Old forums)
    Member
    Post count: 23064

    Actually, I think I may have come up with a solution for my problem. If I get it working, I would be happy to share the solution, by posting the code back here.

    Imported from legacy forums. Posted by flahan (had 379 views)

    User (Old forums)
    Member
    Post count: 23064

    Below is a first cut of a menu item that basically replaces itself with the list of mdi children (or is invisible if no children). It takes a bit of a brut force approach and I think it could be optimized quite a bit. It does seem to work they way I want it to, but I am not completely happy with how it does the job though.

    Please let me know what you think or if you see any problems.

    <u>Usage</u>
    <pre>
    Forms.Controls.WindowMdiListMenuItem wmmi = new WindowsAuditor.Forms.Controls.WindowMdiListMenuItem();
    wmmi.MainForm = this;
    mmiWindow.Items.Add(wmmi);
    this.MdiChildActivate += new EventHandler(wmmi.MainForm_MdiChildActivate);
    </pre>

    <u>The Code</u>
    <pre>
    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Drawing;
    //using System.Windows.Forms;

    using Xceed.SmartUI.Controls.MenuBar;

    namespace Zabeda.Windows.Forms.Controls
    {
    /// <summary>
    /// This class renders a list of MdiChild MenuItems. The method it uses to render the list
    /// needs to be optimized, but it works in its current state.
    /// </summary>
    public class WindowMdiListMenuItem : Xceed.SmartUI.Controls.MenuBar.MenuItem
    {
    /// <summary>
    /// A SeparatorMenuItem that can be reused
    /// </summary>
    private SeparatorMenuItem m_smi = new SeparatorMenuItem();

    /// <summary>
    /// for maintaining order
    /// </summary>
    private ArrayList m_mdiItems = new ArrayList();
    /// <summary>
    /// for maintaining order
    /// </summary>
    private ArrayList m_menuItems = new ArrayList();
    /// <summary>
    /// to find the menuitem by form – used when a form closes
    /// </summary>
    private Hashtable m_menuItemsHash = new Hashtable();

    /// <summary>
    /// This is in a hack to get around the order of events problem. <br/>
    /// When an MDI child is closed, the MdiChildActivate event doesn’t tell you
    /// what is happening (is child activating, openning or closing). So, when
    /// a form is first activated we monitor the Closed event for the form. When
    /// the form is Closed, we get an event notification, but the MdiActivate event
    /// occurs again. The problem is that the closed form is still included in the
    /// list of MdiChildren, even though it has been closed. This list is used
    /// to hold a ref to a closed form, so that when the MdiChildActivate event occurs
    /// we can check to see whether a form should really be included in the MdiChildItems
    /// displayed in the menu.
    /// </summary>
    private ArrayList m_closedForms = new ArrayList();

    // the form that owns the menu
    private System.Windows.Forms.Form m_form;

    private System.ComponentModel.IContainer components = null;

    public WindowMdiListMenuItem()
    {
    // This call is required by the Windows Form Designer.
    InitializeComponent();

    // TODO: Add any initialization after the InitializeComponent call
    this.Text = “WindowMdiList”;
    base.Visible = false;
    }

    /// <summary>
    /// The Form that owns the SmartMenuBar
    /// </summary>
    public System.Windows.Forms.Form MainForm
    {
    get { return m_form; }
    set { m_form = value; }
    }

    /// <summary>
    /// Will always return false
    /// </summary>
    public new bool Visible
    {
    get { return base.Visible; }
    set { }
    }

    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    protected override void Dispose( bool disposing )
    {
    if( disposing )
    {
    if (components != null)
    {
    components.Dispose();
    }
    }
    base.Dispose( disposing );
    }

    /// <summary>
    /// Called when an MdiChild is activated, openned or closed in the MainForm
    /// </summary>
    /// <param name=”o”></param>
    /// <param name=”e”></param>
    public void MainForm_MdiChildActivate(object o, EventArgs e)
    {

    RemoveMdiChildrenMenuItems();
    m_mdiItems.Clear();
    m_menuItems.Clear();
    m_menuItemsHash.Clear();
    BuildMdiList();
    RenderMdiList();
    }

    /// <summary>
    /// Takes care of populating the list of MdiChild MenuItems that should
    /// be rendered
    /// </summary>
    private void BuildMdiList()
    {
    foreach (System.Windows.Forms.Form mdiChild in MainForm.MdiChildren)
    {
    // see note above explaining the purpose of the m_closedForm list
    if (m_closedForms.Contains(mdiChild))
    {
    // form won’t included in MdiList so remove form and let it be GC’d
    m_closedForms.Remove(mdiChild);
    }
    else if (!m_mdiItems.Contains(mdiChild))
    m_mdiItems.Add(mdiChild);
    }
    }

    /// <summary>
    /// Takes care of actually adding the MdiChild MenuItems to the MainMenuItem
    /// </summary>
    private void RenderMdiList()
    {
    if (m_mdiItems.Count > 0)
    {
    MainMenuItem mmi = (MainMenuItem) this.ParentItem;
    m_menuItems.Add(m_smi); // store in list so it can be removed later
    mmi.Items.Add(m_smi); // add to menu to separate mdi list items

    int pos = 1;

    foreach (Object o in m_mdiItems)
    {
    System.Windows.Forms.Form childForm = (System.Windows.Forms.Form) o;
    childForm.Closed += new EventHandler(mdiChildForm_Closing);

    MenuItem mi = new MenuItem(“&” + pos++ + ” ” + childForm.Text);
    mi.Tag = childForm;
    mi.Click += new Xceed.SmartUI.SmartItemClickEventHandler(mdiMenuItem_Click);

    // add to main menu item
    mmi.Items.Add( mi );
    // save so we can clear later
    m_menuItems.Add(mi);
    // save so when form closes we can remove menuite

    Imported from legacy forums. Posted by flahan (had 4256 views)

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.