InitializeComponent +隐藏/显示表单? [英] InitializeComponent + Hide / Show forms?

查看:119
本文介绍了InitializeComponent +隐藏/显示表单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我目前正在开发一个应用程序,但遇到了一些问题.
正如我在以前的帖子中所说的那样,我是一个编程新手. ;-)

不知何故,我的显示"命令无法正常工作?

我的代码如下:

Hello, I''m currently working on an app., and I''m having some issues.
As I''ve said in previous posts, I''m a programming noob. ;-)

Somehow my "show" commands don''t work???

My code looks like this:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MusicBiz_Unlimited
{
    public partial class formEditorMain : Form
    {
    public formEditorMain()
    {
    InitializeComponent();

    MainMenu mainMenuForm = new MainMenu();

    mainMenuForm.Show();
     
    }

    MainMenu mainMenuForm = new MainMenu();

    private void btnMainMenu_Click(object sender, EventArgs e)
    {
    mainMenuForm.Show();
    }

    Instruments instrumentsForm = new Instruments();

    private void btnInstruments_Click(object sender, EventArgs e)
    {
    instrumentsForm.Show();
    }

    LyricalSubjects lyricalSubjectsForm = new LyricalSubjects();

    private void btnLyricalSubjects_Click(object sender, EventArgs e)
    {
    lyricalSubjectsForm.Show();
    }
   
    }
}



我想要这个应用程序.要执行的操作如下(伪代码):

用主菜单"形式初始化应用程序

单击工具"按钮–关闭/隐藏当前打开的表单,显示工具"表单

单击抒情主题"按钮–关闭/隐藏当前打开的表单,显示表单抒情主题"等.

单击主菜单"按钮–关闭/隐藏当前打开的表单,如果未打开主菜单"表单,则显示主菜单",否则:不执行任何操作.

我希望有人能帮助我.

在此先谢谢您.



What I want this app. to do is the following (pseudo code):

Initialize application with form "Main Menu"

Button "Instruments" click – close/hide currently open form, show form "Instruments"

Button "Lyrical Subjects" click – close/hide currently open form, show form "Lyrical Subjects" Etc.

Button "Main Menu" click – close/hide currently open form, show form "Main Menu" if form "Main Menu" is not open, else: do nothing.

I hope someone can help me out.

Thanks in advance.

推荐答案

尝试检查按钮按下时每个表单的可见性状态,并相应地隐藏或显示,例如:

Try checking the Visibility state of each form on the button press and hiding or showing accordingly, e.g.:

if (instrumentsForm.Visible == false)
{
   instrumentsForm.Show();
}
else
{
   instrumentsForm.Visible = false;
}




我会尝试:

Hi,

I would try :

public formEditorMain()
{
   InitializeComponent();
   MainMenu mainMenuForm = new MainMenu();
   this.Menu = mainMenuForm;
}



System.Windows.Form.MainMenu没有Show()方法( ^ ).

此外,如果希望某些项目出现在主菜单中,则必须创建它们并将其添加到主菜单中(请参阅为MainMenu类提供的示例).



System.Windows.Form.MainMenu does not have a Show() method (^).

Moreover, if you want some items to appear in your main menu, you have to create and add them to your main menu (look at the examples given for the MainMenu class).


您需要检查表格是否可以看到:
You need to check if the form can be seen:
private void btnMainMenu_Click(object sender, EventArgs e)
{
if (mainMenuForm.Visible)
   {
   mainMenuForm.Hide();
   }
else
   {
   mainMenuForm.Show();
   }
}


这篇关于InitializeComponent +隐藏/显示表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆