2013-05-19 59 views
-2

我已经做了一个侧栏,我停靠在我的应用程序的左侧。基于选定菜单项的形式

现在我想知道根据他们从我的边栏中选择的菜单选项显示表单的最佳方式是什么。

这基本上就是我想做的事:

http://www.dreamincode.net/forums/topic/176782-building-an-application-poscash-register-part-one/

左边是我的菜单栏,右边我想有基于期权点击左侧的形式。

我已经研究过MDI,但是当我这样做时,即使我已经在子窗体中禁用它,我总是会得到一个ControlBox

更新:看来这个作品,以及:

看起来你也可以创建自己的用户控件来做到这一点:

User controls

+0

嗨!请阅读如何提出关于Stackoverflow的问题:http://stackoverflow.com/questions/ask-advice – glts

回答

0

首先创建表单面板,将举行您当前表单的内容(将其添加到表单中,但现在将其保留为空)。

Panel active = new Panel(); 
this.Controls.Add(active); 

然后为每个要显示的表单创建一个包含控件的面板。

Panel firstFormPanel = new Panel(); 
firstFormPanel.Add(new Button()); 
Panel secondFormPanel = new Panel(); 
secondFormPanel.Add(new Button()); 

现在,将你想要的面板默认:

active = firstFormPanel; 

然后,当你想换一种新形式(点击侧边栏的事件),分配板中的一个像活动面板所以:

active.Visible = false; 
active = secondFormPanel; 
active.Visible = true; 
+0

我忘了添加这个。我想在同一个窗口中显示我的工具栏上不同的表单。 – Flybersite

+0

请参阅我的编辑。 –

0

如果你想第二不会允许,除非其closed.then使用您访问您的主要形式...

second_form_name sfn = new second_form_name(); 
sfn.ShowDialog(); 

如果你想第二允许,除非其closed.then使用

second_form_name sfn = new second_form_name(); 
    sfn.Show(); 
0

您访问您的主要形式,这里有一个小例子,我有一个侧边栏的从我的比赛即时决策能够到一个新的子菜单滑入视觉范围。我使用一个计时器来控制移动,并使用一个子菜单列表来确定要显示的内容。据我所知,只有一个到目前为止,所以不是一个很好的例子。

public List<UserControl> Submenus = new List<UserControl>(); 
    Multiplayer_Menu MPM; 
    enum At { Left, Right } 
    At Current = At.Right; 
    At Go_to = At.Right; 
    int Submenu_Index = 0; 
    bool done = false; 

    public void Load_Submenus() 
    { 
     Multiplayer_Menu MM = new Multiplayer_Menu(this); 
     MainMenu.Controls.Add(MM); 
     MM.Location = new Point(MainMenu.Size.Width, 0); 
     MM.Visible = false; 
     Submenus.Add(MM); 
     PictureBox PB = new PictureBox(); 
     MainMenu.Controls.Add(PB); 
     PB.Location = new Point(MainMenu.Size.Width, 0); 
     PB.Size = new System.Drawing.Size(924, 736); 
     PB.SizeMode = PictureBoxSizeMode.StretchImage; 
     PB.ImageLocation = "http://www.taloreal.com/Earth%20Rotation/Rotating.gif"; 
     PB.Visible = true; 
    } 

    private void Form1_Load(object sender, EventArgs e) 
    { 
     Load_Submenus(); 
    } 

    public void MML_Multiplayer_Click(object sender, EventArgs e) 
    { 
     Submenus[Submenu_Index].Visible = false; 
     if (Current == At.Left) 
      Go_to = At.Right; 
     if (Current == At.Right) 
      Go_to = At.Left; 
     ShowHideMenus.Enabled = true; 
     Submenu_Index = 0; 
    } 

    private void ShowHideMenus_Tick(object sender, EventArgs e) 
    { 
     Point P = new Point(MainMenu.Location.X, MainMenu.Location.Y); 
     Size S = new Size(MainMenu.Size.Width, MainMenu.Size.Height); 
     if (Go_to == At.Left) 
     { 
      P = new Point(P.X - 30, P.Y); 
      S = new Size(S.Width + 30, S.Height); 
      if (P.X == 0) 
      { 
       Submenus[Submenu_Index].Visible = true; 
       ShowHideMenus.Enabled = false; 
       Current = Go_to; 
      } 
     } 
     if (Go_to == At.Right) 
     { 
      P = new Point(P.X + 30, P.Y); 
      S = new Size(S.Width - 30, S.Height); 
      if (P.X == 930) 
      { 
       ShowHideMenus.Enabled = false; 
       Current = Go_to; 
      } 
     } 
     Reposition_Menu(P, S); 
    } 

    void Reposition_Menu(Point P, Size S) 
    { 
     MainMenu.Location = P; 
     MainMenu.Size = S; 
    }