ToolStripTextBox.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. namespace System.Windows.Forms
  2. {
  3. public class ToolStripTextBox : ToolStripItem
  4. {
  5. private CustomControls.ToolStripTextBox textbox;
  6. public override string Text
  7. {
  8. get => textbox.Text;
  9. set => textbox.Text = value;
  10. }
  11. public bool AcceptsReturn
  12. {
  13. get => textbox.AcceptsReturn;
  14. set => textbox.AcceptsReturn = value;
  15. }
  16. public bool AcceptsTab
  17. {
  18. get => textbox.AcceptsTab;
  19. set => textbox.AcceptsTab = value;
  20. }
  21. public bool ReadOnly
  22. {
  23. get => textbox.IsReadOnly;
  24. set => textbox.IsReadOnly = value;
  25. }
  26. private HorizontalAlignment textBoxTextAlign;
  27. public HorizontalAlignment TextBoxTextAlign
  28. {
  29. get => textBoxTextAlign;
  30. set
  31. {
  32. textBoxTextAlign = value;
  33. textbox.HorizontalContentAlignment = value switch
  34. {
  35. HorizontalAlignment.Center => Windows.HorizontalAlignment.Center,
  36. HorizontalAlignment.Right => Windows.HorizontalAlignment.Right,
  37. _ => Windows.HorizontalAlignment.Left
  38. };
  39. }
  40. }
  41. public int MaxLength
  42. {
  43. get => textbox.MaxLength;
  44. set => textbox.MaxLength = value;
  45. }
  46. public override void ApplyStyle(ToolStripProfessionalRenderer r)
  47. {
  48. textbox.Resources["TextBox.ControlText"] = r.Foreground;
  49. textbox.Resources["TextBox.Static.Background"] = r.TextBoxStaticBackground;
  50. textbox.Resources["TextBox.Static.Border"] = r.ComboBoxStaticBorder;
  51. textbox.Resources["TextBox.MouseOver.Border"] = r.ComboBoxMouseOverBorder;
  52. textbox.Resources["TextBox.Disabled.Border"] = r.ComboBoxDisabledBorder;
  53. }
  54. public ToolStripTextBox()
  55. {
  56. textbox = new();
  57. SetControl(textbox);
  58. textbox.VerticalAlignment = VerticalAlignment.Center;
  59. textbox.TextChanged += (s, e) => OnTextChanged(e);
  60. AutoSize = false;
  61. }
  62. }
  63. }