FrmStyleBase.cs 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using Infragistics.Win;
  9. using Infragistics.Win.Misc;
  10. using Infragistics.Win.UltraWinEditors;
  11. using Infragistics.Win.UltraWinGrid;
  12. using Infragistics.Win.UltraWinTabControl;
  13. using Infragistics.Win.UltraWinToolbars;
  14. using CoreFS.CA06;
  15. namespace Core.StlMes.Client.Sale.Common.FrmStyleBase
  16. {
  17. public partial class FrmStyleBase :FrmBase
  18. {
  19. public FrmStyleBase()
  20. {
  21. InitializeComponent();
  22. }
  23. public string[] QueryStrings
  24. {
  25. get
  26. {
  27. return this.Key.Split('@');
  28. }
  29. }
  30. ComboBox cboMain; //定义ComboBox控件
  31. // public bool On_Off_Thread = false;
  32. /// <summary>
  33. /// 样式用平台样式,允许自定义平台外的样式
  34. /// </summary>
  35. /// <param name="e"></param>
  36. protected override void OnLoad(EventArgs e)
  37. {
  38. // SetControlStyle(this);
  39. base.OnLoad(e);
  40. try
  41. {
  42. Core.StlMes.Client.Sale.DbHelp.DbBase.GetInstance().OpenBase = this.ob;
  43. }
  44. catch
  45. {
  46. }
  47. SetControlStyleDefine(this);
  48. }
  49. private void SetControlStyleDefine(Control parentCtrl)
  50. {
  51. try
  52. {
  53. foreach (Control ctrl in parentCtrl.Controls)
  54. {
  55. if (ctrl.HasChildren) SetControlStyleDefine(ctrl);
  56. if (ctrl.ToString().IndexOf("Label") > 0 && (ctrl is Label))
  57. {
  58. SetLabelStyle(ctrl as Label);
  59. continue;
  60. }
  61. if (ctrl.ToString().IndexOf("ComboBox") > 0 && (ctrl is ComboBox))
  62. {
  63. SetComboBoxStyle(ctrl as ComboBox);
  64. continue;
  65. }
  66. }
  67. }
  68. catch
  69. {
  70. }
  71. }
  72. //protected override void OnPaint(PaintEventArgs e)
  73. //{
  74. // // FillRectangleFloat(e, this);
  75. // // base.OnPaint(e);
  76. //}
  77. private void frmStyleBase_Load(object sender, EventArgs e)
  78. {
  79. }
  80. /// <summary>
  81. /// 处理ComboBox边框问题(没完成)
  82. /// </summary>
  83. /// <param name="e"></param>
  84. /// <param name="parentCtrl"></param>
  85. private void FillRectangleFloat(PaintEventArgs e)
  86. {
  87. //创建边框颜色
  88. SolidBrush blueBrush = new SolidBrush(Color.Black);
  89. //设置边框坐标
  90. float x = cboMain.Location.X - 1;
  91. float y = cboMain.Location.Y - 1;
  92. float width = cboMain.Width + 2;
  93. float height = cboMain.Height + 2;
  94. //填充边框
  95. e.Graphics.FillRectangle(blueBrush, x, y, width, height);
  96. }
  97. /// <summary>
  98. /// 控件重画事情(没完成)
  99. /// </summary>
  100. /// <param name="sender"></param>
  101. /// <param name="e"></param>
  102. /// <param name="cboMain"></param>
  103. private void Main_Paint(object sender, PaintEventArgs e)
  104. {
  105. FillRectangleFloat(e);
  106. }
  107. /// <summary>
  108. /// 遍历设置窗体上控件样式
  109. /// </summary>
  110. /// <param name="parentCtrl">父容器</param>
  111. private void SetControlStyle(Control parentCtrl)
  112. {
  113. try
  114. {
  115. foreach (Control ctrl in parentCtrl.Controls)
  116. {
  117. if (ctrl.HasChildren) SetControlStyle(ctrl);
  118. ctrl.EnabledChanged += new System.EventHandler(AllEnabledChanged);
  119. if (ctrl.ToString().IndexOf("ComboBox") > 0 && (ctrl is ComboBox))
  120. {
  121. SetComboBoxStyle(ctrl as ComboBox);
  122. continue;
  123. }
  124. if (ctrl.ToString().IndexOf("UltraGroupBox") > 0 && (ctrl is UltraGroupBox))
  125. {
  126. SetUltraGroupBoxStyle(ctrl as UltraGroupBox);
  127. continue;
  128. }
  129. if (ctrl.ToString().IndexOf("UltraExpandableGroupBox") > 0 && (ctrl is UltraExpandableGroupBox))
  130. {
  131. SetUltraExpandableGroupBoxStyle(ctrl as UltraExpandableGroupBox);
  132. continue;
  133. }
  134. if (ctrl.ToString().IndexOf("UltraTextEditor") > 0 && (ctrl is UltraTextEditor))
  135. {
  136. SetUltraTextEditorStyle(ctrl as UltraTextEditor);
  137. continue;
  138. }
  139. if (ctrl.ToString().IndexOf("UltraComboEditor") > 0 && (ctrl is UltraComboEditor))
  140. {
  141. SetUltraComboEditorStyle(ctrl as UltraComboEditor);
  142. continue;
  143. }
  144. if (ctrl.ToString().IndexOf("UltraCombo") > 0 && (ctrl is UltraCombo))
  145. {
  146. SetUltraComboStyle(ctrl as UltraCombo);
  147. continue;
  148. }
  149. if (ctrl.ToString().IndexOf("UltraDateTimeEditor") > 0 && (ctrl is UltraDateTimeEditor))
  150. {
  151. SetUltraDateTimeEditorStyle(ctrl as UltraDateTimeEditor);
  152. continue;
  153. }
  154. if (ctrl.ToString().IndexOf("UltraGrid") > 0 && (ctrl is UltraGrid))
  155. {
  156. SetUltraGridStyle(ctrl as UltraGrid);
  157. continue;
  158. }
  159. if (ctrl.ToString().IndexOf("Label") > 0 && (ctrl is Label))
  160. {
  161. SetLabelStyle(ctrl as Label);
  162. continue;
  163. }
  164. if (ctrl.ToString().IndexOf("CheckBox") > 0 && (ctrl is CheckBox))
  165. {
  166. SetCheckBoxStyle(ctrl as CheckBox);
  167. continue;
  168. }
  169. if (ctrl.ToString().IndexOf("RadioButton") > 0 && (ctrl is RadioButton))
  170. {
  171. SetRadioButtonStyle(ctrl as RadioButton);
  172. continue;
  173. }
  174. if (ctrl.ToString().IndexOf("TextBox") > 0 && (ctrl is TextBox))
  175. {
  176. SetTextBoxStyle(ctrl as TextBox);
  177. continue;
  178. }
  179. if (ctrl.ToString().IndexOf("ComboBox") > 0 && (ctrl is ComboBox))
  180. {
  181. SetComboBoxStyle(ctrl as ComboBox);
  182. continue;
  183. }
  184. if (ctrl.ToString().IndexOf("UltraNumericEditor") > 0 && (ctrl is UltraNumericEditor))
  185. {
  186. SetUltraNumericEditorStyle(ctrl as UltraNumericEditor);
  187. continue;
  188. }
  189. }
  190. }
  191. catch (Exception ee)
  192. {
  193. Console.WriteLine(ee.Message);
  194. }
  195. }
  196. private void AllEnabledChanged(object sender, EventArgs e)
  197. {
  198. if (((Control)sender).Enabled == true)
  199. {
  200. if (sender is TextBox || sender is ComboBox)
  201. ((Control)sender).BackColor = Color.White;//Color.LightCyan;
  202. else if (sender is UltraTextEditor)
  203. ((UltraTextEditor)sender).Appearance.BackColor = Color.White;//Color.LightCyan;
  204. else if (sender is UltraComboEditor)
  205. ((UltraComboEditor)sender).Appearance.BackColor = Color.White;//Color.LightCyan;
  206. else if (sender is UltraCombo)
  207. ((UltraCombo)sender).Appearance.BackColor = Color.White;//Color.LightCyan;
  208. else if (sender is UltraDateTimeEditor)
  209. ((UltraDateTimeEditor)sender).Appearance.BackColor = Color.White;//Color.LightCyan;
  210. else if (sender is UltraNumericEditor)
  211. ((UltraNumericEditor)sender).Appearance.BackColor = Color.White;//Color.LightCyan;
  212. }
  213. else
  214. {
  215. if (sender is TextBox || sender is ComboBox)
  216. ((Control)sender).BackColor = Color.White;// Color.Empty;
  217. else if (sender is UltraTextEditor)
  218. ((UltraTextEditor)sender).Appearance.BackColor = Color.White;// Color.Empty;
  219. else if (sender is UltraComboEditor)
  220. ((UltraComboEditor)sender).Appearance.BackColor = Color.White;// Color.Empty;
  221. else if (sender is UltraCombo)
  222. ((UltraCombo)sender).Appearance.BackColor = Color.White;// Color.Empty;
  223. else if (sender is UltraDateTimeEditor)
  224. ((UltraDateTimeEditor)sender).Appearance.BackColor = Color.White;// Color.Empty;
  225. else if (sender is UltraNumericEditor)
  226. ((UltraNumericEditor)sender).Appearance.BackColor = Color.White;// Color.Empty;
  227. }
  228. }
  229. #region "设置控件样式"
  230. /// <summary>
  231. /// 设置UltraGroupBox样式
  232. /// </summary>
  233. /// <param name="ulgrpbx">UltraGroup控件</param>
  234. private void SetUltraGroupBoxStyle(UltraGroupBox ulgrpbx)
  235. {
  236. ulgrpbx.ViewStyle = Infragistics.Win.Misc.GroupBoxViewStyle.XP;
  237. ulgrpbx.Font = new System.Drawing.Font("宋体", 9F);
  238. ulgrpbx.BackColor = Color.FromArgb(213, 228, 242);//System.Drawing.Color.Gainsboro;
  239. ulgrpbx.HeaderAppearance.BackColor = System.Drawing.Color.Empty;
  240. ulgrpbx.HeaderAppearance.BackColor2 = System.Drawing.Color.Empty;
  241. }
  242. /// <summary>
  243. /// 设置UltraExpandableGroupBox样式
  244. /// </summary>
  245. /// <param name="ulgrpbx">UltraExpandableGroupBox控件</param>
  246. private void SetUltraExpandableGroupBoxStyle(UltraExpandableGroupBox ulexgrpbx)
  247. {
  248. ulexgrpbx.ViewStyle = Infragistics.Win.Misc.GroupBoxViewStyle.VisualStudio2005;
  249. ulexgrpbx.Font = new System.Drawing.Font("宋体", 9F);
  250. ulexgrpbx.BackColor = Color.FromArgb(213, 228, 242);// System.Drawing.Color.Gainsboro;
  251. ulexgrpbx.HeaderAppearance.BackColor = Color.FromArgb(202, 218,238);// System.Drawing.Color.Empty;
  252. ulexgrpbx.HeaderAppearance.BackColor2 = Color.White;// System.Drawing.Color.Empty;
  253. }
  254. /// <summary>
  255. /// 设置UltraTextEditor样式
  256. /// </summary>
  257. /// <param name="ulgrpbx">UltraTextEditor控件</param>
  258. private void SetUltraTextEditorStyle(UltraTextEditor ultxte)
  259. {
  260. ultxte.FlatMode = true;
  261. if (ultxte.ReadOnly == false && ultxte.Enabled == true)
  262. ultxte.Appearance.BackColor = Color.White;// Color.LightCyan;
  263. if (ultxte.ReadOnly == true) ultxte.Appearance.BackColor = Color.White;
  264. ultxte.BorderStyle = Infragistics.Win.UIElementBorderStyle.Solid;
  265. ultxte.Appearance.BorderColor = Color.Black;
  266. ultxte.DisplayStyle = EmbeddableElementDisplayStyle.Standard;
  267. }
  268. /// <summary>
  269. /// 设置UltraComboEditor样式
  270. /// </summary>
  271. /// <param name="ulcmbxe">UltraComboEditor控件</param>
  272. private void SetUltraComboEditorStyle(UltraComboEditor ulcmbxe)
  273. {
  274. ulcmbxe.FlatMode = true;
  275. ulcmbxe.AutoComplete = true;
  276. ulcmbxe.DropDownListWidth = -1;
  277. if (ulcmbxe.Enabled == true && ulcmbxe.ReadOnly == false)
  278. ulcmbxe.Appearance.BackColor = Color.White;//Color.LightCyan;
  279. ulcmbxe.BorderStyle = Infragistics.Win.UIElementBorderStyle.Solid;
  280. ulcmbxe.Appearance.BorderColor = Color.Black;
  281. ulcmbxe.DisplayStyle = EmbeddableElementDisplayStyle.Standard;
  282. }
  283. /// <summary>
  284. /// 设置UltraCombo样式
  285. /// </summary>
  286. /// <param name="ulcmb">UltraCombo控件</param>
  287. private void SetUltraComboStyle(UltraCombo ulcmb)
  288. {
  289. ulcmb.FlatMode = true;// DefaultableBoolean.True;
  290. ulcmb.BorderStyle = Infragistics.Win.UIElementBorderStyle.Default;
  291. if (ulcmb.Enabled == true && ulcmb.ReadOnly == false)
  292. ulcmb.Appearance.BackColor = Color.White;//Color.LightCyan;
  293. }
  294. /// <summary>
  295. /// 设置UltraDateTimeEditor样式
  296. /// </summary>
  297. /// <param name="uldte">UltraDateTimeEditor控件</param>
  298. private void SetUltraDateTimeEditorStyle(UltraDateTimeEditor uldte)
  299. {
  300. uldte.FlatMode = true;
  301. if (uldte.Enabled == true && uldte.ReadOnly == false)
  302. uldte.Appearance.BackColor = Color.White;//Color.LightCyan;
  303. uldte.BorderStyle = Infragistics.Win.UIElementBorderStyle.Solid;
  304. uldte.Appearance.BorderColor = Color.Black;
  305. }
  306. /// <summary>
  307. /// 设置UltraToolbarsManager样式
  308. /// </summary>
  309. /// <param name="uldte">UltraToolbarsManager控件</param>
  310. private void SetUltraToolbarsManager(UltraToolbarsManager ctrl)
  311. {
  312. ctrl.ShowQuickCustomizeButton = false;
  313. ctrl.ToolbarSettings.ToolDisplayStyle = ToolDisplayStyle.ImageAndText;
  314. ctrl.Style = ToolbarStyle.VisualStudio2005;
  315. ctrl.LockToolbars = true;
  316. }
  317. /// <summary>
  318. /// 设置UltraGrid样式
  319. /// </summary>
  320. /// <param name="ulgrid">UltraGrid控件</param>
  321. private void SetUltraGridStyle(UltraGrid ulgrid)
  322. {
  323. ulgrid.Font = new System.Drawing.Font("宋体", 9F);
  324. return;
  325. ulgrid.DisplayLayout.Appearance.BackColor = Color.FromArgb(245, 250, 254);
  326. ulgrid.DisplayLayout.CaptionVisible = Infragistics.Win.DefaultableBoolean.False;
  327. ulgrid.DisplayLayout.ScrollBounds = Infragistics.Win.UltraWinGrid.ScrollBounds.ScrollToFill;
  328. ulgrid.DisplayLayout.ScrollStyle = Infragistics.Win.UltraWinGrid.ScrollStyle.Immediate;
  329. ulgrid.DisplayLayout.MaxColScrollRegions = 2;
  330. ulgrid.DisplayLayout.MaxRowScrollRegions = 2;
  331. ulgrid.DisplayLayout.UseFixedHeaders = true;
  332. ulgrid.DisplayLayout.Override.FixedHeaderIndicator = FixedHeaderIndicator.None;
  333. ulgrid.DisplayLayout.Override.HeaderAppearance.TextHAlign = Infragistics.Win.HAlign.Center;
  334. // ulgrid.DisplayLayout.Override.HeaderStyle = Infragistics.Win.HeaderStyle.Standard;
  335. ulgrid.DisplayLayout.Override.MinRowHeight = 21;
  336. ulgrid.DisplayLayout.Override.RowSelectorNumberStyle = Infragistics.Win.UltraWinGrid.RowSelectorNumberStyle.RowIndex;
  337. ulgrid.DisplayLayout.Override.RowSelectors = Infragistics.Win.DefaultableBoolean.True;
  338. ulgrid.DisplayLayout.Override.AllowDelete = DefaultableBoolean.False;
  339. if (ulgrid.DisplayLayout.Bands[0].CardView == false)
  340. ulgrid.DisplayLayout.Override.ActiveRowAppearance.FontData.Bold = DefaultableBoolean.True;
  341. else
  342. ulgrid.DisplayLayout.Override.ActiveRowAppearance.FontData.Bold = DefaultableBoolean.False;
  343. ulgrid.DisplayLayout.Override.ActiveRowAppearance.BackColor = Color.Empty;
  344. ulgrid.DisplayLayout.Override.ActiveRowAppearance.ForeColor = Color.Empty;
  345. ulgrid.DisplayLayout.Override.CellClickAction = CellClickAction.EditAndSelectText;
  346. ulgrid.Font = new System.Drawing.Font("宋体", 9F);
  347. ulgrid.DisplayLayout.Appearance.FontData.SizeInPoints = 9;
  348. if ( ulgrid.DisplayLayout.Bands.Count == 1)
  349. {
  350. ulgrid.DisplayLayout.Override.HeaderAppearance.BackColor = Color.FromArgb(158, 191, 231);// System.Drawing.Color.LightSteelBlue;
  351. ulgrid.DisplayLayout.Override.RowSelectorAppearance.BackColor = System.Drawing.Color.LightSteelBlue;
  352. ulgrid.DisplayLayout.Override.RowAlternateAppearance.BackColor = Color.GhostWhite;
  353. }
  354. else if (ulgrid.DisplayLayout.Bands.Count == 2)
  355. {
  356. ulgrid.DisplayLayout.Bands[0].Override.HeaderAppearance.BackColor = Color.FromArgb(158, 191, 231);//System.Drawing.Color.LightSteelBlue;
  357. ulgrid.DisplayLayout.Bands[0].Override.RowSelectorAppearance.BackColor = System.Drawing.Color.LightSteelBlue;
  358. ulgrid.DisplayLayout.Bands[0].Override.RowAppearance.BackColor = Color.LightGray;
  359. ulgrid.DisplayLayout.Bands[1].Override.HeaderAppearance.BackColor = Color.FromArgb(233, 242, 199);
  360. ulgrid.DisplayLayout.Bands[1].Override.HeaderAppearance.BackColor2 = Color.FromArgb(170, 184, 131);
  361. ulgrid.DisplayLayout.Bands[1].Override.HeaderAppearance.BackGradientStyle = Infragistics.Win.GradientStyle.Vertical;
  362. ulgrid.DisplayLayout.Bands[1].Override.RowSelectorAppearance.BackColor = Color.FromArgb(233, 242, 199);
  363. ulgrid.DisplayLayout.Bands[1].Override.RowSelectorAppearance.BackColor2 = Color.FromArgb(170, 184, 131);
  364. ulgrid.DisplayLayout.Bands[1].Override.RowSelectorAppearance.BackGradientStyle = Infragistics.Win.GradientStyle.Vertical;
  365. ulgrid.DisplayLayout.Bands[1].Override.RowAppearance.BorderColor = Color.FromArgb(170, 184, 131);
  366. }
  367. else if (ulgrid.DisplayLayout.Bands.Count == 3)
  368. {
  369. ulgrid.DisplayLayout.Bands[0].Override.HeaderAppearance.BackColor = Color.FromArgb(158, 191, 231);//System.Drawing.Color.LightSteelBlue;
  370. ulgrid.DisplayLayout.Bands[0].Override.RowSelectorAppearance.BackColor = System.Drawing.Color.LightSteelBlue;
  371. ulgrid.DisplayLayout.Bands[0].Override.RowAppearance.BackColor = Color.LightGray;
  372. ulgrid.DisplayLayout.Bands[1].Override.HeaderAppearance.BackColor = Color.FromArgb(233, 242, 199);
  373. ulgrid.DisplayLayout.Bands[1].Override.HeaderAppearance.BackColor2 = Color.FromArgb(170, 184, 131);
  374. ulgrid.DisplayLayout.Bands[1].Override.HeaderAppearance.BackGradientStyle = Infragistics.Win.GradientStyle.Vertical;
  375. ulgrid.DisplayLayout.Bands[1].Override.RowSelectorAppearance.BackColor = Color.FromArgb(233, 242, 199);
  376. ulgrid.DisplayLayout.Bands[1].Override.RowSelectorAppearance.BackColor2 = Color.FromArgb(170, 184, 131);
  377. ulgrid.DisplayLayout.Bands[1].Override.RowSelectorAppearance.BackGradientStyle = Infragistics.Win.GradientStyle.Vertical;
  378. ulgrid.DisplayLayout.Bands[1].Override.RowAppearance.BorderColor = Color.FromArgb(170, 184, 131);
  379. ulgrid.DisplayLayout.Bands[2].Override.HeaderAppearance.BackColor = Color.FromArgb(233, 242, 199);
  380. ulgrid.DisplayLayout.Bands[2].Override.HeaderAppearance.BackColor2 = Color.FromArgb(170, 184, 131);
  381. ulgrid.DisplayLayout.Bands[2].Override.HeaderAppearance.BackGradientStyle = Infragistics.Win.GradientStyle.Vertical;
  382. ulgrid.DisplayLayout.Bands[2].Override.RowSelectorAppearance.BackColor = Color.FromArgb(233, 242, 199);
  383. ulgrid.DisplayLayout.Bands[2].Override.RowSelectorAppearance.BackColor2 = Color.FromArgb(170, 184, 131);
  384. ulgrid.DisplayLayout.Bands[2].Override.RowSelectorAppearance.BackGradientStyle = Infragistics.Win.GradientStyle.Vertical;
  385. ulgrid.DisplayLayout.Bands[2].Override.RowAppearance.BorderColor = Color.FromArgb(170, 184, 131);
  386. }
  387. }
  388. /// <summary>
  389. /// 设置Label样式
  390. /// </summary>
  391. /// <param name="lbl">Label控件</param>
  392. private void SetLabelStyle(Label lbl)
  393. {
  394. // lbl.BackColor = Color.LightBlue;
  395. // lbl.BorderStyle = BorderStyle.FixedSingle;
  396. lbl.TextAlign = ContentAlignment.MiddleRight;
  397. lbl.BorderStyle = BorderStyle.None;
  398. }
  399. /// <summary>
  400. /// 设置CheckBox样式
  401. /// </summary>
  402. /// <param name="chkbx">CheckBox控件</param>
  403. private void SetCheckBoxStyle(CheckBox chkbx)
  404. {
  405. chkbx.FlatStyle = FlatStyle.Flat;
  406. chkbx.BackColor = Color.Transparent;
  407. }
  408. /// <summary>
  409. /// 设置RadioButton样式
  410. /// </summary>
  411. /// <param name="rdbtn">RadioButton控件</param>
  412. private void SetRadioButtonStyle(RadioButton rdbtn)
  413. {
  414. rdbtn.FlatStyle = FlatStyle.Flat;
  415. rdbtn.BackColor = Color.Transparent;
  416. }
  417. /// <summary>
  418. /// 设置TextBox样式
  419. /// </summary>
  420. /// <param name="txtbx">TextBox控件</param>
  421. private void SetTextBoxStyle(TextBox txtbx)
  422. {
  423. txtbx.BorderStyle = BorderStyle.Fixed3D;
  424. if (txtbx.Enabled == true && txtbx.ReadOnly == false)
  425. txtbx.BackColor = Color.White;//Color.LightCyan;
  426. if (txtbx.ReadOnly == true) txtbx.BackColor = Color.White;
  427. }
  428. /// <summary>
  429. /// 设置ComboBox样式
  430. /// </summary>
  431. /// <param name="cmbx">ComboBox控件</param>
  432. private void SetComboBoxStyle(ComboBox cmbx)
  433. {
  434. cmbx.DisplayMember = "NAME_";
  435. cmbx.ValueMember = "ID_";
  436. //cmbx.FlatStyle = FlatStyle.Standard;
  437. //if (cmbx.Enabled == true)
  438. // cmbx.BackColor = Color.White;//Color.LightCyan;
  439. //else
  440. // cmbx.BackColor = Color.White;//Color.LightCyan;
  441. }
  442. /// <summary>
  443. /// 设置UltraNumericEditor样式
  444. /// </summary>
  445. /// <param name="ulNumEdor">UltraNumericEditor控件</param>
  446. private void SetUltraNumericEditorStyle(UltraNumericEditor ulNumEdor)
  447. {
  448. ulNumEdor.ImeMode = ImeMode.Disable;
  449. ulNumEdor.DisplayStyle = EmbeddableElementDisplayStyle.Standard;
  450. if (ulNumEdor.Enabled == true && ulNumEdor.ReadOnly == false)
  451. ulNumEdor.Appearance.BackColor = Color.White;// Color.LightCyan;
  452. }
  453. #endregion
  454. #region "公共方法"
  455. /// <summary>
  456. /// ultraGrid单元格内容复制
  457. /// </summary>
  458. /// <param name="sender"></param>
  459. /// <param name="e"></param>
  460. private void ultraGrid1_KeyDown(object sender, KeyEventArgs e)
  461. {
  462. if (((UltraGrid)sender).ActiveCell != null)
  463. {
  464. if (e.Control && e.KeyCode == Keys.C)
  465. {
  466. Clipboard.SetDataObject(((UltraGrid)sender).ActiveCell.Value, false);
  467. }
  468. }
  469. }
  470. /// <summary>
  471. /// 设置ultraGrid是否允许分组
  472. /// </summary>
  473. /// <param name="ulgrid">ultraGrid控件</param>
  474. /// <param name="Checked">是否允许</param>
  475. public void AllowGroup(Infragistics.Win.UltraWinGrid.UltraGrid ulgrid, bool Checked)
  476. {
  477. ulgrid.DisplayLayout.GroupByBox.Hidden = !Checked;
  478. if (!Checked)
  479. ulgrid.DisplayLayout.Bands[0].SortedColumns.Clear();
  480. }
  481. /// <summary>
  482. /// 设置ultraGrid是允许过滤
  483. /// </summary>
  484. /// <param name="Grid">ultraGrid控件</param>
  485. /// <param name="Checked">是否允许</param>
  486. public void AllowFilter(Infragistics.Win.UltraWinGrid.UltraGrid ulgrid, bool Checked)
  487. {
  488. ulgrid.DisplayLayout.Override.FilterUIType = Infragistics.Win.UltraWinGrid.FilterUIType.FilterRow;
  489. if (Checked)
  490. ulgrid.DisplayLayout.Override.AllowRowFiltering = Infragistics.Win.DefaultableBoolean.True;
  491. else
  492. ulgrid.DisplayLayout.Override.AllowRowFiltering = Infragistics.Win.DefaultableBoolean.False;
  493. ulgrid.DisplayLayout.Bands[0].ColumnFilters.ClearAllFilters();
  494. }
  495. /// <summary>
  496. /// 设置ultraGrid指定Bands索引的为不可编辑,如有选择Checked列Key为selectkey
  497. /// </summary>
  498. /// <param name="Grid">ultraGrid控件</param>
  499. /// <param name="index">Bands索引</param>
  500. public void SetNoEnable(Infragistics.Win.UltraWinGrid.UltraGrid ulgrid, int index)
  501. {
  502. foreach (Infragistics.Win.UltraWinGrid.UltraGridColumn Col in ulgrid.DisplayLayout.Bands[index].Columns)
  503. {
  504. if (Col.Key.ToLower() != "selectkey") //选择复选框
  505. Col.CellActivation = Infragistics.Win.UltraWinGrid.Activation.NoEdit;
  506. }
  507. }
  508. /// <summary>
  509. /// 设置ultraGrid为不可编辑,如有选择Checked列Key为selectkey
  510. /// </summary>
  511. /// <param name="ulgrid">ultraGrid控件</param>
  512. public void SetNoEnable(Infragistics.Win.UltraWinGrid.UltraGrid ulgrid)
  513. {
  514. foreach (Infragistics.Win.UltraWinGrid.UltraGridBand var in ulgrid.DisplayLayout.Bands)
  515. {
  516. foreach (Infragistics.Win.UltraWinGrid.UltraGridColumn Col in var.Columns)
  517. {
  518. if (Col.Key.ToLower() != "selectkey") //选择复选框
  519. Col.CellActivation = Infragistics.Win.UltraWinGrid.Activation.NoEdit;
  520. }
  521. }
  522. }
  523. /// <summary>
  524. /// 设置指定条件行的背景颜色
  525. /// </summary>
  526. /// <param name="condition">数据筛条件(DataView.RowFilter的值)</param>
  527. /// <param name="key"></param>
  528. /// <param name="color">颜色值</param>
  529. /// <param name="table">数据源</param>
  530. /// <param name="Grid">ultraGrid控件</param>
  531. /// <param name="NotEdit">是否可编辑</param>
  532. public void SetRowBackColor(string condition, string key, System.Drawing.Color color, DataTable table,
  533. Infragistics.Win.UltraWinGrid.UltraGrid Grid, bool NotEdit)
  534. {
  535. try
  536. {
  537. bool ISOK = true;
  538. List<string> priKey = new List<string>();
  539. priKey.Add(key);
  540. ISOK = SetPriKey(priKey, table);
  541. DataView dv = new DataView();
  542. dv.Table = table;
  543. dv.RowFilter = condition;
  544. DataTable dt = dv.ToTable();
  545. if (ISOK)
  546. {
  547. foreach (Infragistics.Win.UltraWinGrid.UltraGridRow row in Grid.Rows)
  548. {
  549. if (!row.IsDataRow) continue;
  550. DataRow[] dr = dt.Select(key + "=" + this.getStr(row.Cells[key].Value));
  551. if (dr.Length > 0)
  552. {
  553. Infragistics.Win.Appearance appearance1 = new Infragistics.Win.Appearance();
  554. appearance1.ForeColor = color;
  555. row.Appearance = appearance1;
  556. if (NotEdit)
  557. {
  558. try
  559. {
  560. row.Cells["SelectKey"].Activation = Infragistics.Win.UltraWinGrid.Activation.NoEdit;
  561. }
  562. catch (Exception)
  563. {
  564. }
  565. }
  566. }
  567. }
  568. }
  569. else
  570. foreach (Infragistics.Win.UltraWinGrid.UltraGridRow row in Grid.Rows)
  571. {
  572. if (!row.IsDataRow) continue;
  573. foreach (DataRowView drow in dv)
  574. {
  575. if (drow[key].ToString() == row.Cells[key].Value.ToString())
  576. {
  577. Infragistics.Win.Appearance appearance1 = new Infragistics.Win.Appearance();
  578. appearance1.ForeColor = color;
  579. row.Appearance = appearance1;
  580. if (NotEdit)
  581. {
  582. try
  583. {
  584. row.Cells["SelectKey"].Activation = Infragistics.Win.UltraWinGrid.Activation.NoEdit;
  585. }
  586. catch (Exception)
  587. {
  588. }
  589. }
  590. }
  591. }
  592. }
  593. }
  594. catch (Exception)
  595. {
  596. }
  597. }
  598. /// <summary>
  599. /// 对目标对象进行字符串的转换
  600. /// </summary>
  601. /// <param name="obj"></param>
  602. /// <returns></returns>
  603. public string getStr(object obj)
  604. {
  605. if (obj == null || obj.GetType() == typeof(System.DBNull))
  606. {
  607. return "";
  608. }
  609. else
  610. {
  611. return Convert.ToString(obj).Trim();
  612. }
  613. }
  614. public bool SetPriKey(List<string> PriStr, DataTable dt)
  615. {
  616. try
  617. {
  618. DataColumn[] PriColunms = new DataColumn[PriStr.Count];
  619. int i = 0;
  620. foreach (string var in PriStr)
  621. {
  622. PriColunms[i] = dt.Columns[var];
  623. i++;
  624. }
  625. dt.PrimaryKey = PriColunms;
  626. }
  627. catch
  628. {
  629. return false;
  630. }
  631. return true;
  632. }
  633. /// <summary>
  634. /// 获取子窗体弹出的位置坐标
  635. /// </summary>
  636. /// <param name="ChildWindowSize"></param>
  637. /// <returns></returns>
  638. public static Point GetChildWindowLocation(Size ChildWindowSize)
  639. {
  640. int width = Cursor.Position.X + ChildWindowSize.Width - Screen.PrimaryScreen.Bounds.Width;
  641. int height = Cursor.Position.Y + ChildWindowSize.Height - Screen.PrimaryScreen.Bounds.Height + 30;
  642. width = (width > 0) ? (Cursor.Position.X - width) : Cursor.Position.X; // X坐标
  643. height = (height > 0) ? (Cursor.Position.Y - height + 10) : (Cursor.Position.Y + 10); // Y坐标
  644. return new Point(width, height);
  645. }
  646. #endregion
  647. private void FrmStyleBase_Load_1(object sender, EventArgs e)
  648. {
  649. }
  650. }
  651. }