C# 点击父窗口按钮,显示子窗口,再次点击该按钮时则隐藏子窗口,如此反复。

如果子窗口已经显示了,则隐藏,如未显示,则打开。

简单的说就是要用winform 实现类似于 音乐软件上的 “在线音乐”按钮功能。

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 WinFormTest
{
    public partial class frmMain : Form
    {
        public frmMain()
        {
            InitializeComponent();   
        }

        private void btnSubFormControler_Click(object sender, EventArgs e)
        {
            if (this.OwnedForms.Count() == 0)
                this.AddOwnedForm(new SubForm());
            this.OwnedForms[0].Visible = !this.OwnedForms[0].Visible;
        }

        private void frmMain_Load(object sender, EventArgs e)
        {
            this.AddOwnedForm(new SubForm());
        }

    }
}

温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答