zoukankan      html  css  js  c++  java
  • winform空间批量控制

    第一版:

    private void RefreshControl(PanelEx panel, bool enabled, bool isClear)
            {
                for (int i = 0; i < panel.Controls.Count; i++)
                {
                    if (panel.Controls[i] is PanelEx)
                    {
                        PanelEx panel1 = panel.Controls[i] as PanelEx;
                        RefreshControl(panel1, enabled, isClear);
                    }
                    else if (panel.Controls[i] is DevComponents.DotNetBar.TabControl)
                    {
                        DevComponents.DotNetBar.TabControl tabControl = panel.Controls[i] as DevComponents.DotNetBar.TabControl;
                        RefreshControl(tabControl, enabled, isClear);
                    }
                    else if (panel.Controls[i] is TextBoxX)
                    {
                        TextBox textbox = panel.Controls[i] as TextBoxX;
                        textbox.Enabled = enabled;
                        if (isClear)
                            textbox.Clear();
                    }
                    else if (panel.Controls[i] is DateTimeInput)
                    {
                        DateTimeInput dtInput = panel.Controls[i] as DateTimeInput;
                        dtInput.Enabled = enabled;
                        if (isClear)
                            dtInput.Value = DateTime.Parse("2999/1/1");
                    }
                    else if (panel.Controls[i] is ButtonX)
                    {
                        ButtonX btn = panel.Controls[i] as ButtonX;
                        btn.Enabled = enabled;
                    }
                    else if (panel.Controls[i] is CheckBoxX)
                    {
                        CheckBoxX checkBoxX = panel.Controls[i] as CheckBoxX;
                        checkBoxX.Enabled = enabled;
                        if (isClear)
                            checkBoxX.Checked = false;
                    }
                    else if (panel.Controls[i] is BarcodeControl)
                    {
                        BarcodeControl barcodeControl = panel.Controls[i] as BarcodeControl;
                        barcodeControl.Enabled = enabled;
                        if (isClear)
                            barcodeControl.Data = "000000000";
                    }
                    else if (panel.Controls[i] is ComboBoxEx)
                    {
                        ComboBoxEx comboBoxEx = panel.Controls[i] as ComboBoxEx;
                        comboBoxEx.Enabled = enabled;
                        if (isClear)
                            comboBoxEx.Text = "";
                    }
                }
            }
    
    private void RefreshControl(DevComponents.DotNetBar.TabControl tabControl, bool enabled, bool isClear)
            {
                int index = tabControl.SelectedTabIndex;
                for (int i = 0; i < 5; i++)
                {
                    TabControlPanel panel = tabControl.SelectedPanel;
                    foreach (Control item in panel.Controls)
                    {
                        if (item is TextBoxX)
                        {
                            TextBox textbox = item as TextBoxX;
                            textbox.Enabled = enabled;
                            if (isClear)
                                textbox.Clear();
                        }
                        else if (item is CheckBoxX)
                        {
                            CheckBoxX checkBoxX = item as CheckBoxX;
                            checkBoxX.Enabled = enabled;
                            if (isClear)
                                checkBoxX.Checked = false;
                        }
                        else if (item is ButtonX)
                        {
                            ButtonX btn = item as ButtonX;
                            btn.Enabled = enabled;
                        }
                        else if (item is DataGridViewX)
                        {
                            DataGridViewX grid = item as DataGridViewX;
                            if (isClear)
                            {
                                if (grid.DataSource != null && grid.Rows.Count != 0)
                                {
                                    DataTable dt = (DataTable)grid.DataSource;
                                    dt.Rows.Clear();
                                    grid.DataSource = dt;
                                    //grid.Rows.Clear();
                                }
                            }
                        }
                        else if (item is DateTimeInput)
                        {
                            DateTimeInput dtInput = item as DateTimeInput;
                            dtInput.Enabled = enabled;
                            if (isClear)
                            {
                                dtInput.Value = DateTime.Parse("2999/1/1");
                            }
                        }
                        else if (item is PictureBox)
                        {
                            PictureBox pic = item as PictureBox;
                            pic.Enabled = enabled;
                            if (isClear)
                            {
                                pic.Image = null;
                            }
                        }
                        else if (item is PanelEx)
                        {
                            PanelEx panel1 = item as PanelEx;
                            RefreshControl(panel1, enabled, isClear);
                        }
                    }
                    if (!tabControl.SelectNextTab())
                    {
                        tabControl.SelectedTabIndex = 0;
                        if (tabControl.SelectedTabIndex == index)
                            break;
                    }
                }
                tabControl.SelectedTabIndex = index;
            }
    View Code

    第二版

    private void RefreshControl(Control baseControl,bool enabled, bool isClear)
            {
                foreach (Control Control in baseControl.Controls)
                {
                    if (Control is PanelEx)
                    {
                        PanelEx panel = Control as PanelEx;
                        RefreshControl(panel, enabled, isClear);
                    }
                    else if (Control is DevComponents.DotNetBar.TabControl)
                    {
                        DevComponents.DotNetBar.TabControl tabControl = Control as DevComponents.DotNetBar.TabControl;
                        RefreshControl(tabControl, enabled, isClear);
                    }
                    else if (Control is TabControlPanel)
                    {
                        TabControlPanel tabPanel = Control as TabControlPanel;
                        RefreshControl(tabPanel, enabled, isClear);
                    }
                    else if (Control is TextBoxX)
                    {
                        TextBox textbox = Control as TextBoxX;
                        textbox.Enabled = enabled;
                        if (isClear)
                            textbox.Clear();
                    }
                    else if (Control is ButtonX)
                    {
                        ButtonX btn = Control as ButtonX;
                        btn.Enabled = enabled;
                    }
                    else if (Control is DateTimeInput)
                    {
                        DateTimeInput dtInput = Control as DateTimeInput;
                        dtInput.Enabled = enabled;
                        if (isClear)
                            dtInput.Value = DateTime.Parse("2999/1/1");
                    }
                    else if (Control is CheckBoxX)
                    {
                        CheckBoxX checkBoxX = Control as CheckBoxX;
                        checkBoxX.Enabled = enabled;
                        if (isClear)
                            checkBoxX.Checked = false;
                    }
                    else if (Control is BarcodeControl)
                    {
                        BarcodeControl barcodeControl = Control as BarcodeControl;
                        barcodeControl.Enabled = enabled;
                        if (isClear)
                            barcodeControl.Data = "000000000";
                    }
                    else if (Control is ComboBoxEx)
                    {
                        ComboBoxEx comboBoxEx = Control as ComboBoxEx;
                        comboBoxEx.Enabled = enabled;
                        if (isClear)
                            comboBoxEx.Text = "";
                    }
                    else if (Control is DataGridViewX)
                    {
                        DataGridViewX grid = Control as DataGridViewX;
                        if (isClear)
                        {
                            if (grid.DataSource != null && grid.Rows.Count != 0)
                            {
                                DataTable dt = (DataTable)grid.DataSource;
                                dt.Rows.Clear();
                                grid.DataSource = dt;
                                //grid.Rows.Clear();
                            }
                        }
                    }
                    else if (Control is PictureBox)
                    {
                        PictureBox pic = Control as PictureBox;
                        pic.Enabled = enabled;
                        if (isClear)
                        {
                            pic.Image = null;
                        }
                    }
                    else if (Control is GroupPanel)
                    {
                        RefreshControl(Control, enabled, isClear);
                    }
                }
            }
    View Code
  • 相关阅读:
    BZOJ 1391: [Ceoi2008]order
    BZOJ 4504: K个串
    2019 年百度之星·程序设计大赛
    POJ 2398 Toy Storage (二分 叉积)
    POJ 2318 TOYS (二分 叉积)
    HDU 6697 Closest Pair of Segments (计算几何 暴力)
    HDU 6695 Welcome Party (贪心)
    HDU 6693 Valentine's Day (概率)
    HDU 6590 Code (判断凸包相交)
    POJ 3805 Separate Points (判断凸包相交)
  • 原文地址:https://www.cnblogs.com/liuslayer/p/5772977.html
Copyright © 2011-2022 走看看