fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Drawing;
  7. using System.Windows.Forms;
  8.  
  9. namespace WindowsFormsApp1
  10. {
  11. class NullableDateTimePicker : DateTimePicker
  12. {
  13. private DateTime? SavedValue { get; set; }
  14. private DateTimePickerFormat SavedFormat { get; set; }
  15. private string SavedCustomFormat { get; set; }
  16. private bool IsNullValue { get; set; }
  17.  
  18. public NullableDateTimePicker()
  19. {
  20. Format = DateTimePickerFormat.Custom;
  21. CustomFormat = "yyyy/MM/dd";
  22. Value = DateTime.Now;
  23. Checked = true;
  24. IsNullValue = false;
  25. }
  26.  
  27. public new DateTime? Value { get; set; }
  28.  
  29. protected override void OnKeyDown(KeyEventArgs e)
  30. {
  31. base.OnKeyDown(e);
  32.  
  33. if(e.KeyCode == Keys.Delete)
  34. {
  35. if (!IsNullValue)
  36. {
  37. SavedValue = Value;
  38. SavedFormat = Format;
  39. SavedCustomFormat = CustomFormat;
  40.  
  41. Value = null;
  42. CustomFormat = " ";
  43.  
  44. IsNullValue = true;
  45. }
  46. }
  47. else
  48. {
  49. if (IsNullValue)
  50. {
  51. CustomFormat = "yyyy/MM/dd";
  52. Format = SavedFormat;
  53. Value = SavedValue;
  54.  
  55. IsNullValue = false;
  56. }
  57. }
  58. }
  59. }
  60. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cs(7,22): error CS0234: The type or namespace name `Forms' does not exist in the namespace `System.Windows'. Are you missing `System.Windows.Forms' assembly reference?
prog.cs(11,36): error CS0246: The type or namespace name `DateTimePicker' could not be found. Are you missing an assembly reference?
prog.cs(14,17): error CS0246: The type or namespace name `DateTimePickerFormat' could not be found. Are you missing an assembly reference?
prog.cs(27,30): warning CS0109: The member `WindowsFormsApp1.NullableDateTimePicker.Value' does not hide an inherited member. The new keyword is not required
prog.cs(29,43): error CS0246: The type or namespace name `KeyEventArgs' could not be found. Are you missing an assembly reference?
Compilation failed: 4 error(s), 1 warnings
stdout
Standard output is empty