winform空间批量控制
生活随笔
收集整理的這篇文章主要介紹了
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?
轉載于:https://www.cnblogs.com/liuslayer/p/5772977.html
與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的winform空间批量控制的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 马哥linux 培训第一周作业
- 下一篇: Servlet简介