fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. namespace WindowsFormsApplicationTest
  12. {
  13. public partial class Form1 : Form
  14. {
  15. public Form1()
  16. {
  17. InitializeComponent();
  18.  
  19. var dgv = new DataGridView();
  20. dgv.Dock = DockStyle.Fill;
  21.  
  22. var c = new DataGridViewCheckBoxColumn();
  23. c.CellTemplate = new TestCell();
  24.  
  25. dgv.Columns.Add(c);
  26. dgv.RowCount = 10;
  27.  
  28. Controls.Add(dgv);
  29. }
  30. }
  31.  
  32. public class TestCell : DataGridViewCheckBoxCell
  33. {
  34. protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates elementState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
  35. {
  36. if (rowIndex % 2 == 0) // 条件
  37. {
  38. paintParts &= DataGridViewPaintParts.All ^ DataGridViewPaintParts.ContentBackground ^ DataGridViewPaintParts.ContentForeground;
  39. }
  40. base.Paint(graphics, clipBounds, cellBounds, rowIndex, elementState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts);
  41. }
  42. protected override void OnContentClick(DataGridViewCellEventArgs e)
  43. {
  44. if (e.RowIndex % 2 == 0) // 条件
  45. {
  46. return;
  47. }
  48. base.OnContentClick(e);
  49. }
  50. }
  51. }
  52.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cs(4,14): error CS0234: The type or namespace name `Data' does not exist in the namespace `System'. Are you missing an assembly reference?
prog.cs(8,24): error CS0234: The type or namespace name `Tasks' does not exist in the namespace `System.Threading'. Are you missing an assembly reference?
prog.cs(9,14): error CS0234: The type or namespace name `Windows' does not exist in the namespace `System'. Are you missing an assembly reference?
prog.cs(32,29): error CS0246: The type or namespace name `DataGridViewCheckBoxCell' could not be found. Are you missing a using directive or an assembly reference?
prog.cs(34,116): error CS0246: The type or namespace name `DataGridViewElementStates' could not be found. Are you missing a using directive or an assembly reference?
prog.cs(34,211): error CS0246: The type or namespace name `DataGridViewCellStyle' could not be found. Are you missing a using directive or an assembly reference?
prog.cs(34,244): error CS0246: The type or namespace name `DataGridViewAdvancedBorderStyle' could not be found. Are you missing a using directive or an assembly reference?
prog.cs(34,254): error CS0246: The type or namespace name `DataGridViewPaintParts' could not be found. Are you missing a using directive or an assembly reference?
prog.cs(42,48): error CS0246: The type or namespace name `DataGridViewCellEventArgs' could not be found. Are you missing a using directive or an assembly reference?
Compilation failed: 9 error(s), 0 warnings
stdout
Standard output is empty