PanelToDataTableView.cs 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. namespace LYFZ.ComponentLibrary
  9. {
  10. /* public class TablePanelContainer : System.Windows.Forms.Panel
  11. {
  12. public TablePanelContainer()
  13. {
  14. }
  15. }*/
  16. /// <summary>
  17. /// Panel转数据表格视图
  18. /// </summary>
  19. public class PanelToDataTableView:System.Windows.Forms.Panel
  20. {
  21. System.Windows.Forms.Panel _tableContainer;
  22. System.Windows.Forms.Panel _PanelTableTitle;
  23. public PanelToDataTableView(System.Windows.Forms.Panel container)
  24. {
  25. this._PanelTableTitle = new Panel();
  26. this._PanelTableTitle.Width = this.Width;
  27. this._PanelTableTitle.Height = 32;
  28. this._PanelTableTitle.Padding = new Padding(0, 0, 0, 0);
  29. this._PanelTableTitle.Margin = new Padding(0, 0, 0, 0);
  30. this._PanelTableTitle.Location = new Point(0, 0);
  31. this._tableContainer = container;
  32. this._tableContainer.Controls.Add(this._PanelTableTitle);
  33. this._tableContainer.Controls.Add(this);
  34. this._tableContainer.Scroll += _tableContainer_Scroll;
  35. this._tableContainer.Paint += _tableContainer_Paint;
  36. this._PanelTableTitle.Paint += _PanelTableTitle_Paint;
  37. this.Padding = new Padding(0, 0, 0, 0);
  38. this.Margin = new Padding(0, 0, 0, 0);
  39. this.Location = new Point(0, 0);
  40. this.Paint += _tableContent_Paint;
  41. this.MouseMove += _tableContent_MouseMove;
  42. this.MouseDown += _tableContent_MouseDown;
  43. this.MouseUp += _tableContent_MouseUp;
  44. this._PanelTableTitle.MouseMove += _tableContent_MouseMove;
  45. this._PanelTableTitle.MouseDown += _tableContent_MouseDown;
  46. this._PanelTableTitle.MouseUp += _tableContent_MouseUp;
  47. this._tableContainer.PreviewKeyDown += _tableContainer_PreviewKeyDown;
  48. }
  49. private void _tableContainer_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
  50. {
  51. this.isControl = e.Control;
  52. }
  53. bool isControl = false;
  54. protected override void OnKeyUp(KeyEventArgs e)
  55. {
  56. this.isControl = e.Control;
  57. base.OnKeyUp(e);
  58. }
  59. protected override void OnKeyDown(KeyEventArgs e)
  60. {
  61. this.isControl = e.Control;
  62. base.OnKeyDown(e);
  63. }
  64. private void _tableContent_MouseDoubleClick(object sender, MouseEventArgs e)
  65. {
  66. Point mousePoint = this.ConvertMousePoint(e.Location);
  67. DataEventArgs args = this.GetDataEventArgs(mousePoint, e.Button);
  68. if (args != null)
  69. {
  70. args.CurrentThumbtack = this.GetMouseSelectThumbtack(args.CurrentCell, mousePoint);
  71. if (args.CurrentThumbtack!=null)
  72. {
  73. if (this.EventCellThumbtack_DoubleClick != null)
  74. {
  75. this.EventCellThumbtack_DoubleClick(this, args);
  76. }
  77. }
  78. else
  79. {
  80. if (this.EventCell_DoubleClick != null)
  81. {
  82. this.EventCell_DoubleClick(this, args);
  83. }
  84. }
  85. }
  86. }
  87. /// <summary>
  88. /// 获取当前选择图钉
  89. /// </summary>
  90. /// <param name="currentCell"></param>
  91. /// <param name="mousePoint"></param>
  92. /// <returns></returns>
  93. ThumbtackData GetMouseSelectThumbtack(PDataColumn currentCell, Point mousePoint)
  94. {
  95. if (currentCell.ThumbtackList != null && currentCell.ThumbtackList.Count > 0)
  96. {
  97. return currentCell.ThumbtackList.Find(t => t != null && t.ThumbtackRectangle.Contains(mousePoint));
  98. }
  99. return null;
  100. }
  101. private void _tableContent_MouseClick(object sender, MouseEventArgs e)
  102. {
  103. Point mousePoint = this.ConvertMousePoint(e.Location);
  104. DataEventArgs args = this.GetDataEventArgs(mousePoint,e.Button);
  105. if (args != null)
  106. {
  107. args.CurrentThumbtack = this.GetMouseSelectThumbtack(args.CurrentCell, mousePoint);
  108. if (args.CurrentThumbtack != null)
  109. {
  110. if (this.EventCellThumbtack_Click != null)
  111. {
  112. this.EventCellThumbtack_Click(this, args);
  113. }
  114. }
  115. if (this.EventCell_Click != null)
  116. {
  117. this.EventCell_Click(this, args);
  118. }
  119. }
  120. }
  121. DataEventArgs GetDataEventArgs(Point mousePoint, MouseButtons button)
  122. {
  123. PDataRow mouseDownRow = this.dataRowList.Find(r => r.DataColumnList.Any(c => c.CellRectangle.Contains(mousePoint) && !c.IsIgnoreDraw));
  124. bool isHeadRow = false;
  125. if (mouseDownRow == null)
  126. {
  127. if (this.headColumnRow.DataColumnList.Any(c => c.CellRectangle.Contains(mousePoint)))
  128. {
  129. mouseDownRow = this.headColumnRow;
  130. isHeadRow = true;
  131. }
  132. }
  133. if (mouseDownRow != null)
  134. {
  135. PDataColumn mouseDownCell = mouseDownRow.DataColumnList.Find(c => c.CellRectangle.Contains(mousePoint));
  136. if (mouseDownCell != null)
  137. {
  138. return new DataEventArgs(mouseDownRow, mouseDownCell,mousePoint, button, isHeadRow);
  139. }
  140. }
  141. return null;
  142. }
  143. /// <summary>
  144. /// 鼠标弹起时的位置
  145. /// </summary>
  146. Point mouseUpPoint = new Point();
  147. DateTime MouseUpTime = DateTime.Now;
  148. Rectangle tempMouseClickRectangle = new Rectangle();
  149. private void _tableContent_MouseUp(object sender, MouseEventArgs e)
  150. {
  151. mouseUpPoint =this.ConvertMousePoint(e.Location);
  152. this._tableContainer.Focus();
  153. this.isControl = false;
  154. PDataColumn mouseDownCell = this.headColumnRow.DataColumnList.Find(c => c.CellRectangle.Contains(mouseDownPoint));
  155. if (mouseDownCell != null&& this.isSizeWE)
  156. {
  157. if (this.isSizeWE)
  158. {
  159. mouseDownCell.Width += mouseUpPoint.X - mouseDownPoint.X;
  160. if (mouseDownCell.Width < 2)
  161. {
  162. mouseDownCell.Width = 2;
  163. }
  164. this.isSizeWE = false;
  165. this.RefreshTableView();
  166. }
  167. }
  168. else
  169. {
  170. double secondCount = ExecDateDiff(MouseUpTime, DateTime.Now);
  171. MouseUpTime = DateTime.Now;
  172. if (secondCount < 300 && tempMouseClickRectangle.Contains(mouseUpPoint)&&e.Button== MouseButtons.Left)
  173. {
  174. this._tableContent_MouseDoubleClick(sender, e);
  175. }
  176. else
  177. {
  178. this._tableContent_MouseClick(sender, e);
  179. }
  180. tempMouseClickRectangle = new Rectangle(mouseUpPoint.X - 3, mouseUpPoint.Y - 3, 12, 12);
  181. }
  182. }
  183. /// <summary>
  184. /// 程序执行时间测试
  185. /// </summary>
  186. /// <param name="dateBegin">开始时间</param>
  187. /// <param name="dateEnd">结束时间</param>
  188. /// <returns>返回(秒)单位,比如: 0.00239秒</returns>
  189. public static double ExecDateDiff(DateTime dateBegin, DateTime dateEnd)
  190. {
  191. return LYFZ.WinAPI.CustomPublicMethod.ExecDateDiff(dateBegin, dateEnd);
  192. }
  193. /// <summary>
  194. /// 因为鼠标坐标点用的是 int16 位表示(int16 最大值:-32768到32767 之间) 所以需要转换成 int32位
  195. /// </summary>
  196. /// <param name="point"></param>
  197. /// <returns></returns>
  198. Point ConvertMousePoint(Point point)
  199. {
  200. Point tempPoint = point;
  201. if (tempPoint.Y < 0)
  202. {
  203. tempPoint = new Point(tempPoint.X, tempPoint.Y + 32767 * 2);
  204. }
  205. return tempPoint;
  206. }
  207. [Browsable(false)]
  208. public PDataRow CurrentSelectRow {
  209. get {
  210. return this.dataRowList.Find(r=>r.IsSelected);
  211. }
  212. }
  213. [Browsable(false)]
  214. public PDataColumn CurrentSelectCell
  215. {
  216. get
  217. {
  218. return this.dataRowList.Find(r => r.DataColumnList.Any(c => c.IsSelected)).DataColumnList.Find(c=>c.IsSelected);
  219. }
  220. }
  221. /// <summary>
  222. /// 当前选择行集合
  223. /// </summary>
  224. [Browsable(false)]
  225. public List<PDataRow> SelectRowList
  226. {
  227. get {
  228. return this.dataRowList.FindAll(r=>r.IsSelected);
  229. }
  230. }
  231. /// <summary>
  232. /// 上次选择行集合
  233. /// </summary>
  234. List<PDataRow> oldSelectRowList = new List<PDataRow>();
  235. /// <summary>
  236. /// 设置当前行选择状态
  237. /// </summary>
  238. /// <param name="currRow"></param>
  239. void SetSelectRowStatus(PDataRow currRow,bool isMouseDownRow=false)
  240. {
  241. if (currRow != null)
  242. {
  243. Graphics g = this.CreateGraphics();
  244. List<PDataRow> delSelectRowList = new List<PDataRow>();
  245. if (!this.isControl)
  246. {
  247. foreach (PDataRow row in this.oldSelectRowList)
  248. {
  249. if (row != null && mouseDownRow != null && row.RowIndex != currRow.RowIndex && row.RowIndex != mouseDownRow.RowIndex)
  250. {
  251. if (
  252. (mouseDownRow.RowIndex >= currRow.RowIndex && (row.RowIndex > mouseDownRow.RowIndex || row.RowIndex < currRow.RowIndex))
  253. || (mouseDownRow.RowIndex <= currRow.RowIndex && (row.RowIndex < mouseDownRow.RowIndex || row.RowIndex > currRow.RowIndex))
  254. )
  255. {
  256. row.IsSelected = false;
  257. foreach (PDataColumn col in row.DataColumnList)
  258. {
  259. if (col.CrossRowCell != null)
  260. {
  261. if (!currRow.DataColumnList.Any(c => c.CrossRowCell != null && c.CrossRowCell.RowIndex == col.CrossRowCell.RowIndex && c.CellIndex == col.CrossRowCell.CellIndex))
  262. {
  263. col.CrossRowCell.IsSelected = false;
  264. this.DrawColumnCell(g, row, col.CrossRowCell);
  265. }
  266. }
  267. }
  268. this.DrawColumn(g, row.RowRectangle, row, true);
  269. delSelectRowList.Add(row);
  270. }
  271. }
  272. }
  273. }
  274. if (delSelectRowList.Count > 0)
  275. {
  276. delSelectRowList.ForEach(row =>
  277. {
  278. this.oldSelectRowList.RemoveAll(r => r.RowIndex == row.RowIndex);
  279. });
  280. delSelectRowList.Clear();
  281. }
  282. if (this.oldSelectRowList.Any(r => r.RowIndex == currRow.RowIndex))
  283. {
  284. if (this.isControl && isMouseDownRow)
  285. {
  286. if (currRow.IsSelected)
  287. {
  288. currRow.IsSelected = false;
  289. this.DrawColumn(g, currRow.RowRectangle, currRow, true);
  290. this.oldSelectRowList.RemoveAll(r => r.RowIndex == currRow.RowIndex);
  291. bool isDeleteCrossRowCell = true;
  292. currRow.DataColumnList.FindAll(c => c.CrossRowCell != null).ForEach(c=> {
  293. if (this.oldSelectRowList.Any(r => r.DataColumnList.Any(c2 => c2.CrossRowCell != null && c2.CrossRowCell.RowIndex == c.CrossRowCell.RowIndex)))
  294. {
  295. isDeleteCrossRowCell = false;
  296. }
  297. });
  298. if (isDeleteCrossRowCell)
  299. {
  300. foreach (PDataColumn col in currRow.DataColumnList)
  301. {
  302. if (col.CrossRowCell != null)
  303. {
  304. col.CrossRowCell.IsSelected = false;
  305. this.DrawColumnCell(g, currRow, col.CrossRowCell);
  306. }
  307. }
  308. }
  309. }
  310. }
  311. //return;
  312. }
  313. else
  314. {
  315. currRow.IsSelected = true;
  316. foreach (PDataColumn col in currRow.DataColumnList)
  317. {
  318. if (col.CrossRowCell != null)
  319. {
  320. col.CrossRowCell.IsSelected = true;
  321. this.DrawColumnCell(g, currRow, col.CrossRowCell);
  322. }
  323. }
  324. this.DrawColumn(g, currRow.RowRectangle, currRow, true);
  325. this.oldSelectRowList.Add(currRow);
  326. }
  327. g.Dispose();
  328. }
  329. }
  330. /// <summary>
  331. /// 上次选择单元格集合
  332. /// </summary>
  333. List<PDataColumn> oldSelectCellList = new List<PDataColumn>();
  334. /// <summary>
  335. /// 设置当前单元格选择状态
  336. /// </summary>
  337. /// <param name="currCell"></param>
  338. void SetSelectCellStatus(PDataColumn currCell, bool isMouseDownCell = false)
  339. {
  340. if (currCell != null)
  341. {
  342. Graphics g = this.CreateGraphics();
  343. List<PDataColumn> delSelectCellList = new List<PDataColumn>();
  344. if (!this.isControl&& isMouseDownCell)
  345. {
  346. foreach (PDataColumn cell in this.oldSelectCellList)
  347. {
  348. if (!cell.CellRectangle.Contains(currCell.CellRectangle))
  349. {
  350. PDataRow row = this.dataRowList.Find(r => r.RowIndex == cell.RowIndex);
  351. if (row != null)
  352. {
  353. cell.IsSelected = false;
  354. this.DrawColumnCell(g, row, cell);
  355. delSelectCellList.Add(cell);
  356. }
  357. }
  358. }
  359. }
  360. if (delSelectCellList.Count > 0)
  361. {
  362. delSelectCellList.ForEach(cell =>
  363. {
  364. this.oldSelectCellList.RemoveAll(c => c.CellRectangle.Contains(cell.CellRectangle));
  365. });
  366. delSelectCellList.Clear();
  367. }
  368. if (this.oldSelectCellList.Any(c => c.CellRectangle.Contains(currCell.CellRectangle)||(currCell.CrossRowCell!=null&&c.CellRectangle.Contains(currCell.CrossRowCell.CellRectangle))))
  369. {
  370. if (this.isControl && isMouseDownCell)
  371. {
  372. if (currCell.CrossRowCell != null)
  373. {
  374. if (currCell.CrossRowCell.IsSelected)
  375. {
  376. currCell.CrossRowCell.IsSelected = false;
  377. PDataRow row = this.dataRowList.Find(r => r.RowIndex == currCell.CrossRowCell.RowIndex);
  378. this.DrawColumnCell(g, row, currCell.CrossRowCell);
  379. this.oldSelectCellList.RemoveAll(c => c.CellRectangle.Contains(currCell.CrossRowCell.CellRectangle));
  380. }
  381. }
  382. else
  383. {
  384. if (currCell.IsSelected)
  385. {
  386. currCell.IsSelected = false;
  387. PDataRow row = this.dataRowList.Find(r => r.RowIndex == currCell.RowIndex);
  388. this.DrawColumnCell(g, row, currCell);
  389. this.oldSelectCellList.RemoveAll(c => c.CellRectangle.Contains(currCell.CellRectangle));
  390. }
  391. }
  392. }
  393. }
  394. else
  395. {
  396. if (currCell.CrossRowCell != null)
  397. {
  398. currCell.CrossRowCell.IsSelected = true;
  399. PDataRow row = this.dataRowList.Find(r => r.RowIndex == currCell.CrossRowCell.RowIndex);
  400. this.DrawColumnCell(g, row, currCell.CrossRowCell);
  401. this.oldSelectCellList.Add(currCell.CrossRowCell);
  402. }
  403. else {
  404. currCell.IsSelected = true;
  405. PDataRow row = this.dataRowList.Find(r => r.RowIndex == currCell.RowIndex);
  406. this.DrawColumnCell(g, row, currCell);
  407. this.oldSelectCellList.Add(currCell);
  408. }
  409. }
  410. g.Dispose();
  411. }
  412. }
  413. /// <summary>
  414. /// 鼠标按下时的位置
  415. /// </summary>
  416. Point mouseDownPoint = new Point();
  417. bool isSizeWE = false;
  418. PDataRow mouseDownRow = null;
  419. PDataColumn mouseDownCell = null;
  420. private void _tableContent_MouseDown(object sender, MouseEventArgs e)
  421. {
  422. mouseDownPoint = this.ConvertMousePoint(e.Location);
  423. this._tableContainer.Focus();
  424. if (this.Cursor == Cursors.SizeWE)
  425. {
  426. this.isSizeWE = true;
  427. }
  428. if (e.Button == MouseButtons.Left)
  429. {
  430. this.mouseDownRow = this.dataRowList.Find(r => r.RowRectangle.Contains(mouseDownPoint));
  431. if (this.mouseDownRow != null)
  432. {
  433. if (this.isFullSelectRow)
  434. {
  435. this.SetSelectRowStatus(this.mouseDownRow, true);
  436. }
  437. else
  438. {
  439. this.mouseDownCell = this.mouseDownRow.DataColumnList.Find(c => c.CellRectangle.Contains(mouseDownPoint));
  440. if (this.mouseDownCell!=null)
  441. {
  442. this.SetSelectCellStatus(this.mouseDownCell, true);
  443. }
  444. }
  445. }
  446. }
  447. this.isControl = false;
  448. }
  449. Rectangle currentMoveRectangle = new Rectangle(0, 0, 1, 1);
  450. private void _tableContent_MouseMove(object sender, MouseEventArgs e)
  451. {
  452. Point mouseLocation = this.ConvertMousePoint(e.Location);
  453. PDataColumn cell = this.headColumnRow.DataColumnList.Find(c => c.CellRectangle.Contains(mouseLocation));
  454. if (cell != null)
  455. {
  456. if (mouseLocation.X > cell.CellRectangle.X + cell.CellRectangle.Width - 5)
  457. {
  458. this.Cursor = Cursors.SizeWE;
  459. }
  460. else
  461. {
  462. if (e.Button != MouseButtons.Left)
  463. {
  464. this.Cursor = Cursors.Default;
  465. }
  466. }
  467. }
  468. else
  469. {
  470. this.Cursor = Cursors.Default;
  471. }
  472. if (!this.currentMoveRectangle.Contains(mouseLocation))
  473. {
  474. this.currentMoveRectangle = new Rectangle(mouseLocation.X - 5, mouseLocation.Y - 5, 10, 10);
  475. DataEventArgs dataEvent = this.GetDataEventArgs(mouseLocation, e.Button);
  476. if (dataEvent != null)
  477. {
  478. dataEvent.CurrentThumbtack = this.GetMouseSelectThumbtack(dataEvent.CurrentCell, mouseLocation);
  479. if (dataEvent.CurrentThumbtack != null)
  480. {
  481. if (this.EventCellThumbtack_MouseEnter != null)
  482. {
  483. this.EventCellThumbtack_MouseEnter(this, dataEvent);
  484. }
  485. }
  486. else
  487. {
  488. if (this.EventCell_MouseEnter != null)
  489. {
  490. this.EventCell_MouseEnter(this, dataEvent);
  491. }
  492. }
  493. }
  494. }
  495. if (e.Button == MouseButtons.Left)
  496. {
  497. if (this.isMultipleSelection)
  498. {
  499. PDataRow mouseMoveRow = this.dataRowList.Find(r => r.RowRectangle.Contains(mouseLocation));
  500. if (mouseMoveRow != null)
  501. {
  502. if (this.isFullSelectRow)
  503. {
  504. this.SetSelectRowStatus(mouseMoveRow);
  505. }
  506. else {
  507. PDataColumn tempCell = mouseMoveRow.DataColumnList.Find(c=>c.CellRectangle.Contains(mouseLocation));
  508. this.SetSelectCellStatus(tempCell);
  509. }
  510. }
  511. }
  512. }
  513. }
  514. bool isMultipleSelection = true;
  515. bool isFullSelectRow = true;
  516. private PDataRow headColumnRow = new PDataRow(true);
  517. private List<PDataRow> dataRowList = new List<PDataRow>();
  518. private void _tableContent_Paint(object sender, PaintEventArgs e)
  519. {
  520. // this._tableContent.SuspendLayout();
  521. this.DrawDataTableView(e.Graphics);
  522. // this._tableContent.ResumeLayout();
  523. }
  524. private void _tableContainer_Paint(object sender, PaintEventArgs e)
  525. {
  526. this.Refresh();
  527. }
  528. public void RefreshTableView()
  529. {
  530. this.Width = this.headColumnRow.DataColumnList.Sum(c => c.Width) + 10;
  531. this.Height = this.dataRowList.Sum(r => r.Height) + this.headColumnRow.Height + 10;
  532. this._PanelTableTitle.Width = this.Width;
  533. this._PanelTableTitle.Height = this.headColumnRow.Height+2;
  534. foreach (PDataRow row in this.oldSelectRowList)
  535. {
  536. row.IsSelected = false;
  537. }
  538. this.oldSelectRowList.Clear();
  539. if (this.Height > 65530)
  540. {
  541. MessageBoxCustom.Show("数据内容超过可显示范围,请减少显示数据的行数并做分页处理.");
  542. }
  543. //最大高度为 65530
  544. this.Refresh();
  545. // this._tableContent.Update();
  546. //this._tableContent.Refresh();
  547. }
  548. Rectangle baseRec = new Rectangle(2, 2, 100, 32);
  549. private void _PanelTableTitle_Paint(object sender, PaintEventArgs e)
  550. {
  551. this._PanelTableTitle.Location = new Point(this._PanelTableTitle.Location.X, 0);
  552. this.DrawHeadColumn(e.Graphics, baseRec);
  553. }
  554. private void _tableContainer_Scroll(object sender, ScrollEventArgs e)
  555. {
  556. }
  557. void DrawDataTableView(Graphics g)
  558. {
  559. this._PanelTableTitle.Location = new Point(this._PanelTableTitle.Location.X, 0);
  560. //列标题
  561. Graphics titleG = this._PanelTableTitle.CreateGraphics();
  562. this.DrawHeadColumn(titleG, baseRec);
  563. titleG.Dispose();
  564. this.DrawHeadColumn(g, baseRec);
  565. //数据内容
  566. this.DrawDataColumn(g, baseRec);
  567. }
  568. /// <summary>
  569. /// 画表格数据
  570. /// </summary>
  571. /// <param name="g"></param>
  572. /// <param name="rec"></param>
  573. void DrawDataColumn(Graphics g, Rectangle rec)
  574. {
  575. Rectangle rowRec = new Rectangle(rec.X, rec.Y, 0, this.headColumnRow.Height);
  576. /*this.dataRowList.ForEach(row=>{
  577. rowRec = new Rectangle(rowRec.X, rowRec.Y + rowRec.Height, 0, row.Height);
  578. row.RowRectangle = new Rectangle(rowRec.X, rowRec.Y, this.headColumnRow.RowRectangle.Width, this.headColumnRow.Height);
  579. row.RowIndex = this.dataRowList.IndexOf(row);
  580. this.DrawColumn(g, rowRec, row);
  581. });*/
  582. int VerticalScrollValue = this._tableContainer.VerticalScroll.Value;
  583. Point tempLocation = new Point(rec.X, rec.Y+ VerticalScrollValue+ this.headColumnRow.Height+5);
  584. PDataRow locationRow = this.dataRowList.Find(c => c.RowRectangle.Contains(tempLocation));
  585. int locationRowIndex = 0;
  586. if (locationRow != null&& this.dataRowList.Count>0)
  587. {
  588. locationRowIndex = this.dataRowList.IndexOf(locationRow);
  589. }
  590. for (int i = 0; i < this.dataRowList.Count; i++)
  591. {
  592. PDataRow row = this.dataRowList[i];
  593. rowRec = new Rectangle(rowRec.X, rowRec.Y + rowRec.Height, 0, row.Height);
  594. row.RowRectangle = new Rectangle(rowRec.X, rowRec.Y, this.headColumnRow.RowRectangle.Width, rowRec.Height);
  595. row.RowIndex = i;
  596. this.DrawColumn(g, rowRec, row, VerticalScrollValue, locationRowIndex);
  597. }
  598. }
  599. /// <summary>
  600. /// 画行
  601. /// </summary>
  602. /// <param name="g"></param>
  603. /// <param name="rec"></param>
  604. /// <param name="row"></param>
  605. /// <param name="verticalScrollValue"></param>
  606. /// <param name="locationRowIndex"></param>
  607. void DrawColumn(Graphics g, Rectangle rec, PDataRow row,int verticalScrollValue, int locationRowIndex)
  608. {
  609. bool isDraw = true;
  610. #region 为了提高性能,判断当前行是否需要绘画单元格,不在显示区域内的单元格不绘制
  611. if (locationRowIndex > 1)
  612. {
  613. locationRowIndex = locationRowIndex - 1;
  614. }
  615. else {
  616. locationRowIndex = 0;
  617. }
  618. if (row.RowIndex < locationRowIndex)
  619. {
  620. PDataColumn tempCell = row.DataColumnList.Find(c=>c.CrossRowCell!=null);
  621. if (tempCell != null)
  622. {
  623. if (tempCell.RowIndex+tempCell.CrossRow < locationRowIndex)
  624. {
  625. isDraw = false;
  626. }
  627. }
  628. else
  629. {
  630. isDraw = false;
  631. }
  632. }
  633. if (row.RowRectangle.Y+row.Height > this._tableContainer.Height + this._tableContainer.Height / 2 + verticalScrollValue)
  634. {
  635. isDraw = false;
  636. }
  637. #endregion;
  638. this.DrawColumn(g,rec,row,isDraw);
  639. }
  640. /// <summary>
  641. /// 画行
  642. /// </summary>
  643. /// <param name="g"></param>
  644. /// <param name="rec"></param>
  645. /// <param name="row"></param>
  646. /// <param name="isDraw"></param>
  647. void DrawColumn(Graphics g, Rectangle rec, PDataRow row, bool isDraw)
  648. {
  649. Rectangle cellRec = new Rectangle(rec.X, rec.Y, 0, row.Height);
  650. for (int i = 0; i < this.headColumnRow.DataColumnList.Count; i++)
  651. {
  652. PDataColumn headCell = this.headColumnRow.DataColumnList[i];
  653. PDataColumn cell = null;
  654. if (i < row.DataColumnList.Count)
  655. {
  656. cell = row.DataColumnList[i];
  657. }
  658. else
  659. {
  660. cell = new PDataColumn();
  661. }
  662. cell.Width = headCell.Width;
  663. cell.Height = row.Height;
  664. cell.CellIndex = i;
  665. cell.RowIndex = row.RowIndex;
  666. cellRec = new Rectangle(cellRec.X + cellRec.Width, cellRec.Y, cell.Width, cell.Height);
  667. cell.CellRectangle = cellRec;
  668. #region 跨行 跨列处理
  669. if (cell.CrossRow > 1)
  670. {
  671. cell.Height = this.GetCrossRowHeight(row, cell);
  672. cell.CellRectangle = new Rectangle(cellRec.X, cellRec.Y, cellRec.Width, cell.Height);
  673. }
  674. if (cell.CrossColumn > 1)
  675. {
  676. cell.Width = this.GetCrossColumnWidth(row, cell);
  677. cell.CellRectangle = new Rectangle(cell.CellRectangle.X, cell.CellRectangle.Y, cell.Width, cell.CellRectangle.Height);
  678. }
  679. if (cell.CrossRow > 1 && cell.CrossColumn > 1)
  680. {
  681. this.SetIgnoreDrawColumn(row, cell);
  682. }
  683. bool isIgnoreDraw = cell.IsIgnoreDraw;
  684. #endregion
  685. if ((!isIgnoreDraw && isDraw)|| cell.CrossRow>1)
  686. {
  687. this.DrawColumnCell(g, row, cell);
  688. }
  689. }
  690. }
  691. public void RefreshCell(PDataRow row, PDataColumn cell)
  692. {
  693. Graphics g = this.CreateGraphics();
  694. this.DrawColumnCell(g,row,cell);
  695. g.Dispose();
  696. }
  697. /// <summary>
  698. /// 画单元格
  699. /// </summary>
  700. /// <param name="g"></param>
  701. /// <param name="row"></param>
  702. /// <param name="cell"></param>
  703. void DrawColumnCell(Graphics g, PDataRow row, PDataColumn cell)
  704. {
  705. Pen borderPen = new Pen(Brushes.White, 2);
  706. int tempBorderWidth = this.headColumnRow.IsRowBorderStyle ? this.headColumnRow.BorderWidth : cell.BorderWidth;
  707. borderPen = new Pen(new SolidBrush(row.IsRowBorderStyle ? row.BorderColor : cell.BorderColor), tempBorderWidth);
  708. Brush brush = new SolidBrush(row.IsRowBackColor ? row.BackgroundColor : cell.BackgroundColor);
  709. // if (cell.CrossRow <= 1)
  710. {
  711. if ((this.IsFullSelectRow && row.IsSelected) || cell.IsSelected)
  712. {
  713. brush = new SolidBrush(row.IsRowBackColor ? row.SelectBackgroundColor : cell.SelectBackgroundColor);
  714. }
  715. }
  716. g.DrawRectangle(borderPen, cell.CellRectangle);
  717. RectangleF fillRec = new RectangleF(cell.CellRectangle.X + tempBorderWidth / 2.0f, cell.CellRectangle.Y + tempBorderWidth / 2.0f, cell.CellRectangle.Width - tempBorderWidth, cell.CellRectangle.Height - tempBorderWidth);
  718. g.FillRectangle(brush, fillRec);
  719. RectangleF layoutRectangle = fillRec;
  720. StringFormat format = new StringFormat();
  721. format.Alignment = cell.TextAlignment;
  722. format.LineAlignment = cell.TextLineAlignment;
  723. if (cell.Width > 2)
  724. {
  725. bool isDrawText = true;
  726. if (this.EventCell_DrawColumn != null)
  727. {
  728. DrawCellEventArgs eData = new DrawCellEventArgs(row, cell);
  729. eData.TextColor = row.IsRowTextFont ? row.TextColor : cell.TextColor;
  730. eData.TextFont = row.IsRowTextFont ? row.TextFont : cell.TextFont;
  731. eData.Brush = new SolidBrush(eData.TextColor);
  732. eData.LayoutRectangle = layoutRectangle;
  733. eData.Format = format;
  734. eData.G = g;
  735. eData.BorderWidth = tempBorderWidth;
  736. eData.BorderColor = row.IsRowBorderStyle ? row.BorderColor : cell.BorderColor;
  737. isDrawText = this.EventCell_DrawColumn(this, eData);
  738. }
  739. if (isDrawText)
  740. {
  741. g.DrawString(String.Format("{0}", cell.Text), row.IsRowTextFont ? row.TextFont : cell.TextFont, new SolidBrush(row.IsRowTextFont ? row.TextColor : cell.TextColor), layoutRectangle, format);
  742. }
  743. if (cell.ThumbtackList != null && cell.ThumbtackList.Count > 0)
  744. {
  745. this.DrawCellThumbtack(g, cell);
  746. }
  747. }
  748. }
  749. /// <summary>
  750. /// 画图钉
  751. /// </summary>
  752. /// <param name="g"></param>
  753. /// <param name="cell"></param>
  754. void DrawCellThumbtack(Graphics g, PDataColumn cell)
  755. {
  756. int i = 0;
  757. foreach (ThumbtackData itme in cell.ThumbtackList)
  758. {
  759. if (itme != null && !itme.IsNullThumbtackText)
  760. {
  761. //画图钉
  762. Rectangle destRect = new Rectangle(cell.CellRectangle.X + cell.CellRectangle.Width - (28+i*26), cell.CellRectangle.Y+3, 24, 24);
  763. itme.ThumbtackRectangle = destRect;
  764. Rectangle srcRect;
  765. if (destRect.X > cell.CellRectangle.X)
  766. {
  767. switch (itme.ThumbtackType)
  768. {
  769. case 1:
  770. srcRect = new Rectangle(0, 0, LYFZ.ComponentLibrary.Properties.Resources.TuDing4_0.Width, LYFZ.ComponentLibrary.Properties.Resources.TuDing4_0.Height);
  771. g.DrawImage(LYFZ.ComponentLibrary.Properties.Resources.TuDing4_0, destRect, srcRect, GraphicsUnit.Pixel);
  772. break;
  773. default:
  774. srcRect = new Rectangle(0, 0, LYFZ.ComponentLibrary.Properties.Resources.TuDing1.Width, LYFZ.ComponentLibrary.Properties.Resources.TuDing1.Height);
  775. g.DrawImage(LYFZ.ComponentLibrary.Properties.Resources.TuDing1, destRect, srcRect, GraphicsUnit.Pixel);
  776. break;
  777. }
  778. }
  779. i++;
  780. }
  781. }
  782. }
  783. /// <summary>
  784. /// 设置跨行跨列时 要忽略的单元格
  785. /// </summary>
  786. /// <param name="row"></param>
  787. /// <param name="cell"></param>
  788. void SetIgnoreDrawColumn(PDataRow row, PDataColumn cell)
  789. {
  790. for (int i = 1; i < cell.CrossRow; i++)
  791. {
  792. int tempIndex = row.RowIndex + i;
  793. if (tempIndex < this.dataRowList.Count)
  794. {
  795. PDataRow tempRow = this.dataRowList[tempIndex];
  796. for (int j = 1; j < cell.CrossColumn; j++)
  797. {
  798. int tempCellIndex = cell.CellIndex + j;
  799. if (tempCellIndex < this.headColumnRow.DataColumnList.Count)
  800. {
  801. PDataColumn tempCell = tempRow.DataColumnList[tempCellIndex];
  802. tempCell.IsIgnoreDraw = true;
  803. }
  804. }
  805. }
  806. }
  807. }
  808. /// <summary>
  809. /// 获取 跨列后的宽度
  810. /// </summary>
  811. /// <param name="row"></param>
  812. /// <param name="cell"></param>
  813. /// <returns></returns>
  814. int GetCrossColumnWidth(PDataRow row, PDataColumn cell)
  815. {
  816. int tWidth = cell.Width;
  817. for (int i = 1; i < cell.CrossColumn; i++)
  818. {
  819. int tempIndex = cell.CellIndex + i;
  820. if (tempIndex < this.headColumnRow.DataColumnList.Count)
  821. {
  822. PDataColumn tempCell = row.DataColumnList[tempIndex];
  823. tWidth += this.headColumnRow.DataColumnList[tempIndex].Width;
  824. tempCell.IsIgnoreDraw = true;
  825. }
  826. }
  827. return tWidth;
  828. }
  829. /// <summary>
  830. /// 获取 跨行后的高度
  831. /// </summary>
  832. /// <param name="row"></param>
  833. /// <param name="cell"></param>
  834. /// <returns></returns>
  835. int GetCrossRowHeight(PDataRow row,PDataColumn cell)
  836. {
  837. int tHeight = row.Height;
  838. cell.CrossRowCell = cell;
  839. for (int i = 1; i < cell.CrossRow; i++)
  840. {
  841. int tempIndex = row.RowIndex + i;
  842. if (tempIndex < this.dataRowList.Count)
  843. {
  844. PDataRow tempRow = this.dataRowList[tempIndex];
  845. tHeight += tempRow.Height;
  846. PDataColumn tempCell = tempRow.DataColumnList[cell.CellIndex];
  847. tempCell.IsIgnoreDraw = true;
  848. tempCell.CrossRowCell = cell;
  849. }
  850. }
  851. return tHeight;
  852. }
  853. /// <summary>
  854. /// 画列标题
  855. /// </summary>
  856. /// <param name="g"></param>
  857. void DrawHeadColumn(Graphics g, Rectangle rec)
  858. {
  859. Pen borderPen = new Pen(Brushes.White, 2);
  860. Rectangle cellRec = new Rectangle(rec.X, rec.Y, 0, 0);
  861. float rowWidth = 0;
  862. for (int i = 0; i < this.headColumnRow.DataColumnList.Count; i++)
  863. {
  864. PDataColumn cell = this.headColumnRow.DataColumnList[i];
  865. cell.Height = this.headColumnRow.Height;
  866. cell.CellIndex = i;
  867. cell.RowIndex = 0;
  868. int tempBorderWidth = this.headColumnRow.IsRowBorderStyle ? this.headColumnRow.BorderWidth : cell.BorderWidth;
  869. borderPen = new Pen(new SolidBrush(this.headColumnRow.IsRowBorderStyle ? this.headColumnRow.BorderColor : cell.BorderColor), tempBorderWidth);
  870. cellRec = new Rectangle(cellRec.X + cellRec.Width, cellRec.Y, cell.Width, cell.Height);
  871. cell.CellRectangle = cellRec;
  872. g.DrawRectangle(borderPen, cellRec);
  873. Brush brush = new SolidBrush(this.headColumnRow.IsRowBackColor ? this.headColumnRow.BackgroundColor : cell.BackgroundColor);
  874. RectangleF fillRec = new RectangleF(cellRec.X + tempBorderWidth / 2.0f, cellRec.Y + tempBorderWidth / 2.0f, cellRec.Width - tempBorderWidth, cellRec.Height - tempBorderWidth);
  875. g.FillRectangle(brush, fillRec);
  876. RectangleF layoutRectangle = fillRec;
  877. StringFormat format = new StringFormat();
  878. format.Alignment = cell.TextAlignment;
  879. format.LineAlignment = cell.TextLineAlignment;
  880. if (cell.Width > 2)
  881. {
  882. bool isDrawText = true;
  883. if (this.EventCell_DrawHeadColumn != null)
  884. {
  885. DrawCellEventArgs eData = new DrawCellEventArgs(this.headColumnRow, cell);
  886. eData.TextColor = this.headColumnRow.IsRowTextFont ? this.headColumnRow.TextColor : cell.TextColor;
  887. eData.TextFont = this.headColumnRow.IsRowTextFont ? this.headColumnRow.TextFont : cell.TextFont;
  888. eData.BorderWidth = tempBorderWidth;
  889. eData.BorderColor = this.headColumnRow.IsRowBorderStyle ? this.headColumnRow.BorderColor : cell.BorderColor;
  890. eData.Brush = new SolidBrush(eData.TextColor);
  891. eData.LayoutRectangle = layoutRectangle;
  892. eData.Format = format;
  893. eData.G = g;
  894. isDrawText = this.EventCell_DrawHeadColumn(this, eData);
  895. }
  896. if (isDrawText)
  897. {
  898. g.DrawString(String.Format("{0}", cell.Text), this.headColumnRow.IsRowTextFont ? this.headColumnRow.TextFont : cell.TextFont, new SolidBrush(this.headColumnRow.IsRowTextFont ? this.headColumnRow.TextColor : cell.TextColor), layoutRectangle, format);
  899. }
  900. if (cell.ThumbtackList != null && cell.ThumbtackList.Count > 0)
  901. {
  902. this.DrawCellThumbtack(g, cell);
  903. }
  904. }
  905. rowWidth = fillRec.X + fillRec.Width;
  906. }
  907. this.headColumnRow.RowRectangle = new Rectangle(rec.X, rec.Y, Convert.ToInt32(rowWidth), this.headColumnRow.Height);
  908. }
  909. public event DataEventArgsHandler EventCellThumbtack_MouseEnter;
  910. public event DataEventArgsHandler EventCellThumbtack_Click;
  911. public event DataEventArgsHandler EventCellThumbtack_DoubleClick;
  912. public event DataEventArgsHandler EventCell_MouseEnter;
  913. public event DataEventArgsHandler EventCell_Click;
  914. public event DataEventArgsHandler EventCell_DoubleClick;
  915. public event DrawCellEventArgsHandler EventCell_DrawHeadColumn;
  916. public event DrawCellEventArgsHandler EventCell_DrawColumn;
  917. // 申明委托
  918. public delegate void DataEventArgsHandler(Panel viewPanel, DataEventArgs e);
  919. public delegate bool DrawCellEventArgsHandler(Panel viewPanel, DrawCellEventArgs e);
  920. /// <summary>
  921. /// 列表题行
  922. /// </summary>
  923. [Browsable(false)]
  924. public PDataRow HeadColumnRow { get => headColumnRow; set => headColumnRow = value; }
  925. /// <summary>
  926. /// 行集合
  927. /// </summary>
  928. [Browsable(false)]
  929. public List<PDataRow> DataRowList { get => dataRowList; set => dataRowList = value; }
  930. /// <summary>
  931. /// 选择行时 是否可以多选
  932. /// </summary>
  933. public bool IsMultipleSelection { get => isMultipleSelection; set => isMultipleSelection = value; }
  934. /// <summary>
  935. /// 选择时是按整行选择还是按单元格选择
  936. /// </summary>
  937. public bool IsFullSelectRow { get => isFullSelectRow; set => isFullSelectRow = value; }
  938. }
  939. public class DataEventArgs : EventArgs
  940. {
  941. public DataEventArgs() {
  942. }
  943. public DataEventArgs(PDataRow row, PDataColumn cell,Point mousePoint, MouseButtons button,bool isHeadRow=false)
  944. {
  945. this.button = button;
  946. this._crrrentRow = row;
  947. this._currentCell = cell;
  948. this.MousePoint = mousePoint;
  949. this._isHeadRow = isHeadRow;
  950. }
  951. bool _isHeadRow = false;
  952. private MouseButtons button = MouseButtons.Left;
  953. ThumbtackData _currentThumbtack;
  954. PDataColumn _currentCell;
  955. PDataRow _crrrentRow;
  956. Point _MousePoint = new Point();
  957. public PDataColumn CurrentCell { get => _currentCell; set => _currentCell = value; }
  958. public PDataRow CrrrentRow { get => _crrrentRow; set => _crrrentRow = value; }
  959. public Point MousePoint { get => _MousePoint; set => _MousePoint = value; }
  960. /// <summary>
  961. /// 当前图钉
  962. /// </summary>
  963. public ThumbtackData CurrentThumbtack { get => _currentThumbtack; set => _currentThumbtack = value; }
  964. public MouseButtons Button { get => button; set => button = value; }
  965. /// <summary>
  966. /// 是否为头部标题行
  967. /// </summary>
  968. public bool IsHeadRow { get => _isHeadRow; set => _isHeadRow = value; }
  969. }
  970. /// <summary>
  971. /// 绘画单元格
  972. /// </summary>
  973. public class DrawCellEventArgs : EventArgs
  974. {
  975. public DrawCellEventArgs()
  976. {
  977. }
  978. public DrawCellEventArgs(PDataRow row, PDataColumn cell)
  979. {
  980. this._crrrentRow = row;
  981. this._currentCell = cell;
  982. }
  983. Color borderColor = Color.FromArgb(215, 228, 242);
  984. int borderWidth = 1;
  985. Color textColor = Color.Black;
  986. Font textFont = new Font("微软雅黑", 10, FontStyle.Regular);
  987. SolidBrush brush;
  988. Graphics g;
  989. RectangleF layoutRectangle = new RectangleF();
  990. StringFormat format = new StringFormat();
  991. PDataColumn _currentCell;
  992. PDataRow _crrrentRow;
  993. public PDataColumn CurrentCell { get => _currentCell; set => _currentCell = value; }
  994. public PDataRow CrrrentRow { get => _crrrentRow; set => _crrrentRow = value; }
  995. public SolidBrush Brush { get => brush; set => brush = value; }
  996. public Graphics G { get => g; set => g = value; }
  997. public RectangleF LayoutRectangle { get => layoutRectangle; set => layoutRectangle = value; }
  998. public StringFormat Format { get => format; set => format = value; }
  999. public Color BorderColor { get => borderColor; set => borderColor = value; }
  1000. public int BorderWidth { get => borderWidth; set => borderWidth = value; }
  1001. public Color TextColor { get => textColor; set => textColor = value; }
  1002. public Font TextFont { get => textFont; set => textFont = value; }
  1003. }
  1004. /// <summary>
  1005. /// 行数据
  1006. /// </summary>
  1007. [Serializable]
  1008. public class PDataRow
  1009. {
  1010. public PDataRow(bool isHeadColumnRow=false)
  1011. {
  1012. if (isHeadColumnRow)
  1013. {
  1014. this.isRowBackColor = true;
  1015. this.isRowTextFont = true;
  1016. this.isRowBorderStyle = true;
  1017. }
  1018. }
  1019. int height = 32;
  1020. int rowIndex = 0;
  1021. bool isSelected = false;
  1022. bool isRowBackColor = false;
  1023. bool isRowTextFont = false;
  1024. bool isRowBorderStyle = false;
  1025. Color selectBackgroundColor = Color.FromArgb(234, 234, 234);//Color.FromArgb(90, 120, 255);
  1026. Color backgroundColor = Color.FromArgb(90, 158, 203);
  1027. Color borderColor = Color.FromArgb(215, 228, 242);
  1028. int borderWidth = 1;
  1029. Color textColor = Color.White;
  1030. Font textFont = new Font("微软雅黑", 10, FontStyle.Bold);
  1031. Rectangle rowRectangle = new Rectangle();
  1032. object tag;
  1033. private List<PDataColumn> dataColumnList = new List<PDataColumn>();
  1034. /// <summary>
  1035. /// 数据单元格集合
  1036. /// </summary>
  1037. public List<PDataColumn> DataColumnList { get => dataColumnList; set => dataColumnList = value; }
  1038. public int Height { get => height; set => height = value; }
  1039. public int RowIndex { get => rowIndex; set => rowIndex = value; }
  1040. public bool IsSelected { get => isSelected; set => isSelected = value; }
  1041. public bool IsRowBackColor { get => isRowBackColor; set => isRowBackColor = value; }
  1042. public bool IsRowTextFont { get => isRowTextFont; set => isRowTextFont = value; }
  1043. public Color SelectBackgroundColor { get => selectBackgroundColor; set => selectBackgroundColor = value; }
  1044. public Color BackgroundColor { get => backgroundColor; set => backgroundColor = value; }
  1045. public Color TextColor { get => textColor; set => textColor = value; }
  1046. public Font TextFont { get => textFont; set => textFont = value; }
  1047. public Rectangle RowRectangle { get => rowRectangle; set => rowRectangle = value; }
  1048. public object Tag { get => tag; set => tag = value; }
  1049. public Color BorderColor { get => borderColor; set => borderColor = value; }
  1050. public int BorderWidth { get => borderWidth; set => borderWidth = value; }
  1051. public bool IsRowBorderStyle { get => isRowBorderStyle; set => isRowBorderStyle = value; }
  1052. }
  1053. /// <summary>
  1054. /// 数据单元格
  1055. /// </summary>
  1056. [Serializable]
  1057. public class PDataColumn
  1058. {
  1059. public PDataColumn()
  1060. {
  1061. }
  1062. string name = "";
  1063. string text = "";
  1064. int width = 100;
  1065. int height = 32;
  1066. int cellIndex = 0;
  1067. int rowIndex = 0;
  1068. int crossRow = 1;
  1069. int crossColumn = 1;
  1070. bool isIgnoreDraw = false;
  1071. bool isSelected = false;
  1072. Color selectBackgroundColor = Color.FromArgb(234, 234, 234);
  1073. Color backgroundColor = Color.FromArgb(255, 255, 255);
  1074. Color borderColor = Color.FromArgb(215, 228, 242);
  1075. Color textColor = Color.Black;
  1076. Font textFont = new Font("微软雅黑", 10, FontStyle.Regular);
  1077. Rectangle cellRectangle = new Rectangle();
  1078. StringAlignment textAlignment = StringAlignment.Center;
  1079. StringAlignment textLineAlignment = StringAlignment.Center;
  1080. int borderWidth = 1;
  1081. PDataColumn crossRowCell;
  1082. object tag;
  1083. DateTime dateTimeTag;
  1084. List<ThumbtackData> _ThumbtackList = new List<ThumbtackData>();
  1085. public string Name { get => name; set => name = value; }
  1086. public string Text { get => text; set => text = value; }
  1087. public int Width { get => width; set => width = value; }
  1088. public int Height { get => height; set => height = value; }
  1089. public object Tag { get => tag; set => tag = value; }
  1090. public Color BackgroundColor { get => backgroundColor; set => backgroundColor = value; }
  1091. public Color BorderColor { get => borderColor; set => borderColor = value; }
  1092. public Color TextColor { get => textColor; set => textColor = value; }
  1093. public Font TextFont { get => textFont; set => textFont = value; }
  1094. public int BorderWidth { get => borderWidth; set => borderWidth = value; }
  1095. public bool IsSelected { get => isSelected; set => isSelected = value; }
  1096. public Color SelectBackgroundColor { get => selectBackgroundColor; set => selectBackgroundColor = value; }
  1097. /// <summary>
  1098. /// 文字水平对齐方式
  1099. /// </summary>
  1100. public StringAlignment TextAlignment { get => textAlignment; set => textAlignment = value; }
  1101. /// <summary>
  1102. /// 文字垂直对齐方式
  1103. /// </summary>
  1104. public StringAlignment TextLineAlignment { get => textLineAlignment; set => textLineAlignment = value; }
  1105. /// <summary>
  1106. /// 单元格区域
  1107. /// </summary>
  1108. public Rectangle CellRectangle { get => cellRectangle; set => cellRectangle = value; }
  1109. public int CellIndex { get => cellIndex; set => cellIndex = value; }
  1110. public int RowIndex { get => rowIndex; set => rowIndex = value; }
  1111. /// <summary>
  1112. /// 跨行 数
  1113. /// </summary>
  1114. public int CrossRow { get => crossRow; set => crossRow = value; }
  1115. /// <summary>
  1116. /// 跨列 数
  1117. /// </summary>
  1118. public int CrossColumn { get => crossColumn; set => crossColumn = value; }
  1119. /// <summary>
  1120. /// 是否被忽略,不显示 一般用于跨行 跨列时
  1121. /// </summary>
  1122. public bool IsIgnoreDraw { get => isIgnoreDraw; set => isIgnoreDraw = value; }
  1123. /// <summary>
  1124. /// 跨行单元格
  1125. /// </summary>
  1126. public PDataColumn CrossRowCell { get => crossRowCell; set => crossRowCell = value; }
  1127. /// <summary>
  1128. /// 图钉集合
  1129. /// </summary>
  1130. public List<ThumbtackData> ThumbtackList { get => _ThumbtackList; set => _ThumbtackList = value; }
  1131. /// <summary>
  1132. /// 时间附加参数
  1133. /// </summary>
  1134. public DateTime DateTimeTag { get => dateTimeTag; set => dateTimeTag = value; }
  1135. }
  1136. /// <summary>
  1137. /// 图钉数据
  1138. /// </summary>
  1139. [Serializable]
  1140. public class ThumbtackData
  1141. {
  1142. public ThumbtackData()
  1143. {
  1144. }
  1145. Rectangle _ThumbtackRectangle = new Rectangle();
  1146. string _ThumbtackText = "";
  1147. int _ThumbtackType = 0;
  1148. object _Tag = null;
  1149. public Rectangle ThumbtackRectangle { get => _ThumbtackRectangle; set => _ThumbtackRectangle = value; }
  1150. public string ThumbtackText { get => _ThumbtackText; set => _ThumbtackText = value; }
  1151. public object Tag { get => _Tag; set => _Tag = value; }
  1152. /// <summary>
  1153. /// 图钉类型 0 为普通图钉 1 为公休图钉 2 为摄控本日历图钉
  1154. /// </summary>
  1155. public int ThumbtackType { get => _ThumbtackType; set => _ThumbtackType = value; }
  1156. /// <summary>
  1157. /// 图钉内容是否为空
  1158. /// </summary>
  1159. public bool IsNullThumbtackText
  1160. {
  1161. get { return String.IsNullOrWhiteSpace(this._ThumbtackText); }
  1162. }
  1163. }
  1164. }