CommandDialog.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. using BulePointLilac.Controls;
  2. using BulePointLilac.Methods;
  3. using System;
  4. using System.Drawing;
  5. using System.Windows.Forms;
  6. namespace ContextMenuManager.Controls
  7. {
  8. sealed class CommandDialog : CommonDialog
  9. {
  10. public string Command { get; set; }
  11. public string Arguments { get; set; }
  12. public override void Reset() { }
  13. protected override bool RunDialog(IntPtr hwndOwner)
  14. {
  15. using(CommandForm frm = new CommandForm())
  16. {
  17. frm.Command = this.Command;
  18. frm.Arguments = this.Arguments;
  19. bool flag = frm.ShowDialog() == DialogResult.OK;
  20. if(flag)
  21. {
  22. this.Command = frm.Command;
  23. this.Arguments = frm.Arguments;
  24. }
  25. return flag;
  26. }
  27. }
  28. sealed class CommandForm : ResizbleForm
  29. {
  30. public CommandForm()
  31. {
  32. this.AcceptButton = btnOk;
  33. this.CancelButton = btnCancel;
  34. this.VerticalResizable = false;
  35. this.Font = SystemFonts.MessageBoxFont;
  36. this.Text = AppString.Menu.ChangeCommand;
  37. this.SizeGripStyle = SizeGripStyle.Hide;
  38. this.StartPosition = FormStartPosition.CenterParent;
  39. this.MaximizeBox = MinimizeBox = ShowIcon = ShowInTaskbar = false;
  40. InitializeComponents();
  41. }
  42. public string Command
  43. {
  44. get => txtCommand.Text;
  45. set => txtCommand.Text = value;
  46. }
  47. public string Arguments
  48. {
  49. get => txtArguments.Text;
  50. set => txtArguments.Text = value;
  51. }
  52. readonly Label lblCommand = new Label
  53. {
  54. Text = AppString.Dialog.ItemCommand,
  55. AutoSize = true
  56. };
  57. readonly Label lblArguments = new Label
  58. {
  59. Text = AppString.Dialog.CommandArguments,
  60. AutoSize = true
  61. };
  62. readonly TextBox txtCommand = new TextBox();
  63. readonly TextBox txtArguments = new TextBox();
  64. readonly Button btnOk = new Button
  65. {
  66. DialogResult = DialogResult.OK,
  67. Text = AppString.Dialog.Ok,
  68. AutoSize = true
  69. };
  70. readonly Button btnCancel = new Button
  71. {
  72. DialogResult = DialogResult.Cancel,
  73. Text = AppString.Dialog.Cancel,
  74. AutoSize = true
  75. };
  76. private void InitializeComponents()
  77. {
  78. this.Controls.AddRange(new Control[] { lblCommand, lblArguments, txtCommand, txtArguments, btnOk, btnCancel });
  79. int a = 20.DpiZoom();
  80. lblArguments.Left = lblCommand.Left = lblCommand.Top = txtCommand.Top = a;
  81. lblArguments.Top = txtArguments.Top = txtCommand.Bottom + a;
  82. btnOk.Top = btnCancel.Top = txtArguments.Bottom + a;
  83. int b = Math.Max(lblCommand.Width, lblArguments.Width) + 3 * a;
  84. this.ClientSize = new Size(250.DpiZoom() + b, btnOk.Bottom + a);
  85. btnOk.Anchor = btnCancel.Anchor = AnchorStyles.Right | AnchorStyles.Top;
  86. btnCancel.Left = this.ClientSize.Width - btnCancel.Width - a;
  87. btnOk.Left = btnCancel.Left - btnOk.Width - a;
  88. this.Resize += (sender, e) =>
  89. {
  90. txtArguments.Width = txtCommand.Width = this.ClientSize.Width - b;
  91. txtArguments.Left = txtCommand.Left = btnCancel.Right - txtCommand.Width;
  92. };
  93. this.OnResize(null);
  94. this.MinimumSize = this.Size;
  95. }
  96. }
  97. }
  98. }