Winform中窗体切换

  /// 
        /// 打开窗体
        /// 
        /// 
        /// 
        private void OpenForm(Form form,Panel panelParent)
        {
            form.TopLevel = false;
            form.FormBorderStyle = FormBorderStyle.None;
            form.Dock = DockStyle.Fill;
            form.Parent = panelParent;
            form.Show();
        }
        /// 
        /// 打开之前进行检查是否已经打开
        /// 
        /// 
        /// 
        /// 
        private bool CloseForm(string formName,Panel panelParent)
        {
            foreach (Control item in panelParent.Controls)
            {
                if (item is Form)
                {
                    Form form = item as Form;
                    if (form.Name == formName)
                    {
                        return true;
                    }
                    else
                    {
                        form.Close();
                    } 
                }
            }
            return false;
        }
        
    Dictionary KeyValuePairs = new Dictionary
        ();
        
        private void Form1_Load(object sender, EventArgs e)
        {
            KeyValuePairs.Add(btnForm2, labelForm2);
            KeyValuePairs.Add(btnForm3, lableForm3);
        }
 /// 
        /// 配置颜色
        /// 
        /// 
        private void SetBackColor(object sender)
        {
            foreach (var item in KeyValuePairs.Values)
            {
                item.BackColor = Color.White;
            }
            if (sender is Control)
            {
                Control control = sender as Control;
                KeyValuePairs[control].BackColor = Color.Green;
            }
        }

你可能感兴趣的:(C#笔记)