日期:2014-05-17  浏览次数:20888 次

在aboutbox窗体修改子窗体B的button控件的Visible属性
想要达到的效果
点击关于窗体(aboutbox窗体)的logoPictureBox控件

修改子窗体frmmodily的button的Visible属性为true

目的是隐藏这个功能,但通过一个方法可以激活这个功能。
注:frmmodily的父窗体为MDIParent1



------解决方案--------------------
设置父窗体一个属性,然后在子窗体Load中访问该属性,通过属性值,来判断是否隐藏
------解决方案--------------------
C# code

//frmmodily 窗体
public partial class frmmodily : Form
    {
        //静态变量
        static bool btvs;

        //将aboutbox传的值赋给静态变量btvs
        public bool Btvs
        {
            get { return btvs; }
            set { btvs = value; }
        }

        //静态变量,只是为了标识是否触发了aboutbox的logoPictureBox_Click事件
        static bool pcclick;

        public bool Pcclick
        {
            get { return pcclick; }
            set { pcclick = value; }
        }

        public frmmodily()
        {
            InitializeComponent();
        }

        private void frmmodily_MouseMove(object sender, MouseEventArgs e)
        {
            //触发,执行一次
            if (pcclick == true)
            {
                //为按钮的Visible赋值
                button1.Visible = btvs;
                pcclick = false;
            }
        }

        /// <summary>
        /// 为了区分下button1.Visible值已经改变
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void frmmodily_Load(object sender, EventArgs e)
        {
            button1.Visible = false;
        }
    }

//aboutbox 窗体
public partial class aboutbox : Form
    {
        public aboutbox()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 弹出frmmodily窗体
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            frmmodily fd = new frmmodily();
            fd.Show();
        }

        /// <summary>
        /// 为frmmodily窗体上的公开变量Btvs赋值,同时修改触发属性
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void logoPictureBox_Click(object sender, EventArgs e)
        {
            frmmodily fd = new frmmodily();
            fd.Btvs = true;
            fd.Pcclick = true;
        }
    }