93 private readonly System.Windows.Forms.ToolTip _toolTip =
new System.Windows.Forms.ToolTip
128 return FormSettings.myForm.FormName;
132 FormSettings.myForm.FormName = value;
136 private FormSettings FormSettings {
get;
set; }
140 FormSettings =
new FormSettings();
141 FormSettings.myForm =
new GPALFormForm()
143 ControlList =
new List<GPALControl>(),
146 FormSettings.myForm.SuspendLayout();
147 FormSettings.myForm.Left = FormSettings.left;
148 FormSettings.myForm.Top = FormSettings.top;
149 FormSettings.myForm.Width = FormSettings.width;
150 FormSettings.myForm.Height = FormSettings.height;
151 FormSettings.myForm.InitialSize =
new Size(FormSettings.width, FormSettings.height);
153 FormSettings.myForm.AutoSize =
true;
155 Size _initialPreferredSize = FormSettings.myForm.Size;
157 FormSettings.TableLayoutPanel =
new TableLayoutPanel()
160 Dock = DockStyle.Fill,
164 FormSettings.myForm.Controls.Add(FormSettings.TableLayoutPanel);
166 System.Windows.Forms.Application.EnableVisualStyles();
170 internal GPALFormForm Form
174 return FormSettings.myForm;
177 internal List<GPALControl> ControlList
181 return FormSettings.myForm.ControlList;
191 FormSettings.width = width;
192 FormSettings.myForm.Width = width;
195 if (FormSettings.left > (Screen.PrimaryScreen.Bounds.Width - width))
196 FormSettings.left = Screen.PrimaryScreen.Bounds.Width - width - 2;
198 FormSettings.myForm.InitialSize =
new Size(FormSettings.myForm.Width, FormSettings.myForm.Height);
214 FormSettings.buttonWidth = width;
216 foreach (
GPALControl gPALControl
in FormSettings.myForm.ControlList)
218 && 0 >= gPALButton.
Width
219 && gPALButton.WindowsControl is Control windowsControl)
222 ApplyWidth(width, windowsControl);
227 windowsControl.Anchor = windowsControl.Anchor | AnchorStyles.Left | AnchorStyles.Right);
239 FormSettings.height = height;
240 FormSettings.myForm.Height = height;
242 if (FormSettings.top > (Screen.PrimaryScreen.Bounds.Height - height))
243 FormSettings.top = Screen.PrimaryScreen.Bounds.Height - height - 2;
245 FormSettings.top = (Screen.PrimaryScreen.Bounds.Height - height) / 2;
247 FormSettings.myForm.InitialSize =
new Size(FormSettings.myForm.Width, FormSettings.myForm.Height);
258 FormSettings.top = top;
259 FormSettings.myForm.Top = top;
269 FormSettings.left = left;
270 FormSettings.myForm.Left = left;
276 public int Left => FormSettings.myForm.Left;
280 public int Top => FormSettings.myForm.Top;
284 public int Width => FormSettings.myForm.Width;
288 public int Height => FormSettings.myForm.Height;
298 FormSettings.myForm.CallAfterFillIn = callAfterFillIn;
301 #endregion <Settings>
302 #region <Forms Actions>
319 return gPALControl
switch
359 FormSettings.myForm.FormTitle = title;
360 FormSettings.myForm.Text = title;
372 FormSettings.myForm.InputDatabase = inputDatabase;
373 DatabaseHelper.TokenizeDatabase(inputDatabase);
374 FormHelper.FillInWithTokens(
this,
new List<IGPALGrid<string>> { inputDatabase.Tokens }, WriteMode.Overwrite);
386 FormSettings.myForm.InputDatabase = inputDatabase;
387 DatabaseHelper.TokenizeDatabase(inputDatabase);
388 FormHelper.FillInWithTokens(
this,
new List<IGPALGrid<string>> { inputDatabase.Tokens }, WriteMode.Append);
400 FormSettings.myForm.InputDatabase = inputDatabase;
401 DatabaseHelper.TokenizeDatabase(inputDatabase);
402 FormHelper.FillInWithTokens(
this,
new List<IGPALGrid<string>> { inputDatabase.Tokens }, WriteMode.Insert);
414 FormSettings.myForm.InputFile = inputFile;
415 if (
false ==
FileHelper.TokenizeFile(inputFile))
417 GPAL.
PublishSimpleEvent(GPALEventType.ERROR, $
"Unable to tokenize file [{inputFile.Filename}]. Continuing.", inputFile, GPALObjectType.GPALFile);
420 FormHelper.FillInWithTokens(
this, ((IGPALFileInternal)inputFile).TokenList, WriteMode.Overwrite);
432 FormSettings.myForm.InputFile = inputFile;
433 if (
false ==
FileHelper.TokenizeFile(inputFile))
435 GPAL.
PublishSimpleEvent(GPALEventType.ERROR, $
"Unable to tokenize file [{inputFile.Filename}]. Continuing.", inputFile, GPALObjectType.GPALFile);
438 FormHelper.FillInWithTokens(
this, ((IGPALFileInternal)inputFile).TokenList, WriteMode.Append);
450 FormSettings.myForm.InputFile = inputFile;
451 if (
false ==
FileHelper.TokenizeFile(inputFile))
453 GPAL.
PublishSimpleEvent(GPALEventType.ERROR, $
"Unable to tokenize file [{inputFile.Filename}]. Continuing.", inputFile, GPALObjectType.GPALFile);
456 FormHelper.FillInWithTokens(
this, ((IGPALFileInternal)inputFile).TokenList, WriteMode.Insert);
468 FormHelper.FillInWithTokens(
this,
new List<IGPALGrid<string>> { inputGrid }, WriteMode.Overwrite);
480 FormHelper.FillInWithTokens(
this,
new List<IGPALGrid<string>> { inputGrid }, WriteMode.Append);
492 FormHelper.FillInWithTokens(
this,
new List<IGPALGrid<string>> { inputGrid }, WriteMode.Insert);
499 private static bool workflowFailureHandled =
false;
501 private void KeepFormAliveOnWorkflowFailure()
503 if (
true == workflowFailureHandled)
return;
505 workflowFailureHandled =
true;
509 System.Windows.Forms.Application.ThreadException += (sender, args) =>
510 GPAL.
PublishSimpleEvent(GPALEventType.EXCEPTION, $
"The form kept going after [{args.Exception?.GetType().Name}]",
null, GPALObjectType.GPALForm, args.Exception);
520 KeepFormAliveOnWorkflowFailure();
522 FormSettings.myForm.ResumeLayout();
523 if (
true == FormSettings.myForm.Visible)
524 FormSettings.myForm.Hide();
525 FormSettings.myForm.ShowDialog();
551 KeepFormAliveOnWorkflowFailure();
553 FormSettings.myForm.ResumeLayout();
554 if (
true == FormSettings.myForm.Visible)
555 FormSettings.myForm.Hide();
556 FormSettings.myForm.Show();
592 FormSettings.myForm.Hide();
595 #endregion <Forms Actions>
605 private static void ApplyWidth(
int width, Control control)
614 control.Width = width;
615 control.Anchor = control.Anchor & ~(AnchorStyles.Left | AnchorStyles.Right);
624 private void ApplyToolTip(
GPALControl gpalControl, Control winControl)
626 if (!
string.IsNullOrWhiteSpace(gpalControl.ToolTipText))
628 FormSettings.ToolTip.SetToolTip(winControl, gpalControl.ToolTipText);
629 if (gpalControl.ToolTipAutoPopDelayMs != 5000)
630 FormSettings.ToolTip.AutoPopDelay = gpalControl.ToolTipAutoPopDelayMs;
645 internal const string SetHeightMarker =
"gpal.height.set";
651 private static bool HasASetHeight(Control control, HashSet<string> sized)
653 return true == sized.Contains(control.Name ??
"")
654 || SetHeightMarker.Equals(control.Tag as
string);
657 private static bool GrowsWithTheForm(Control control, HashSet<string> sized)
661 if (
false == HasASetHeight(control, sized))
667 retVal = control is TabControl
668 || control is SplitContainer
671 || (control is TextBoxBase textBox &&
true == textBox.Multiline)
672 || control is ListView
673 || control is TreeView
674 || control is DataGridView
675 || control is ListBox;
695 private static void SettleRows(TableLayoutPanel panel, HashSet<string> sized)
697 if (
null == panel)
return;
699 SettleInside(panel, sized);
703 if (0 < panel.RowStyles.Count || 1 < panel.ColumnCount)
return;
706 Control[] inOrder = panel.Controls.Cast<Control>().ToArray();
708 if (1 > inOrder.Length)
return;
710 panel.SuspendLayout();
712 panel.ColumnCount = 1;
713 panel.ColumnStyles.Clear();
714 panel.ColumnStyles.Add(
new ColumnStyle(SizeType.Percent, 100f));
716 panel.RowCount = inOrder.Length;
718 for (
int row = 0; row < inOrder.Length; row++)
720 panel.SetCellPosition(inOrder[row],
new TableLayoutPanelCellPosition(0, row));
726 bool ownHeight = 0 < inOrder[row].Height
727 && (inOrder[row] is SplitContainer
728 ||
true == HasASetHeight(inOrder[row], sized));
730 panel.RowStyles.Add(
true == GrowsWithTheForm(inOrder[row], sized)
731 ?
new RowStyle(SizeType.Percent, 100f)
735 ?
new RowStyle(SizeType.Absolute, inOrder[row].Height
736 + inOrder[row].Margin.Top
737 + inOrder[row].Margin.Bottom)
738 :
new RowStyle(SizeType.AutoSize));
742 panel.ResumeLayout(
true);
751 panel.HandleCreated += (sender, args) => ScrollOnlyWhenNeeded(panel);
752 panel.SizeChanged += (sender, args) => ScrollOnlyWhenNeeded(panel);
753 panel.VisibleChanged += (sender, args) => ScrollOnlyWhenNeeded(panel);
755 ScrollOnlyWhenNeeded(panel);
761 private static void SettleInside(Control parent, HashSet<string> sized)
763 foreach (Control child
in parent.Controls)
764 if (child is TableLayoutPanel nested)
765 SettleRows(nested, sized);
767 SettleInside(child, sized);
772 private static readonly HashSet<TableLayoutPanel> settled =
new HashSet<TableLayoutPanel>();
775 private static void MeasureAgain(Control parent)
777 foreach (Control child
in parent.Controls)
779 if (child is TableLayoutPanel panel &&
true == settled.Contains(panel))
780 ScrollOnlyWhenNeeded(panel);
787 private static readonly HashSet<TableLayoutPanel> measuring =
new HashSet<TableLayoutPanel>();
789 private static void ScrollOnlyWhenNeeded(TableLayoutPanel panel)
791 if (
null == panel ||
false == panel.IsHandleCreated ||
true == measuring.Contains(panel))
return;
793 measuring.Add(panel);
800 int narrower = panel.ClientSize.Width - SystemInformation.VerticalScrollBarWidth;
801 int wanted = panel.GetPreferredSize(
new Size(0 < narrower ? narrower : panel.ClientSize.Width, 0)).Height;
802 int have = panel.ClientSize.Height;
803 bool overflowing = wanted > have;
810 bool mayScroll = panel.Parent is TabPage || panel.Parent is Form;
812 if (panel.AutoScroll != (overflowing && mayScroll))
813 panel.AutoScroll = overflowing && mayScroll;
818 panel.AutoScrollMinSize =
true == (overflowing && mayScroll) ?
new Size(0, wanted) : Size.Empty;
822 panel.PerformLayout();
826 measuring.Remove(panel);
831 private HashSet<string> ControlsWithASetHeight()
833 HashSet<string> retVal =
new HashSet<string>();
835 foreach (GPALControl entry
in FormSettings.myForm.ControlList)
836 if (0 < entry.
Height &&
false ==
string.IsNullOrEmpty(entry.
Name))
837 retVal.Add(entry.
Name);
846 private void SizeForm()
850 if (0 < FormSettings.top)
852 FormSettings.myForm.StartPosition = FormStartPosition.Manual;
853 FormSettings.myForm.Top = FormSettings.top;
855 if (0 < FormSettings.left)
857 FormSettings.myForm.StartPosition = FormStartPosition.Manual;
858 FormSettings.myForm.Left = FormSettings.left;
861 HashSet<string> sized = ControlsWithASetHeight();
863 foreach (Control child
in FormSettings.myForm.Controls)
864 if (child is TableLayoutPanel root)
865 SettleRows(root, sized);
867 if (0 == FormSettings.height)
868 FitHeightToContent();
873 FormSettings.myForm.Shown += (sender, args) => MeasureAgain(FormSettings.myForm);
878 private const int HeightToLayOutAt = 300;
886 private void FitHeightToContent()
888 GPALFormForm form = FormSettings.myForm;
889 TableLayoutPanel panel = form.Controls.OfType<TableLayoutPanel>().FirstOrDefault();
893 if (HeightToLayOutAt > form.Height)
894 form.Height = HeightToLayOutAt;
898 form.ResumeLayout(
true);
900 int strips = form.Controls.Cast<Control>()
901 .Where(control => control != panel && (DockStyle.Top == control.Dock || DockStyle.Bottom == control.Dock))
902 .Sum(control => control.Height);
903 int content = panel.GetPreferredSize(
new Size(panel.ClientSize.Width, 0)).Height;
904 int frame = form.Height - form.ClientSize.Height;
905 int height = Math.Min(content + strips + frame, Screen.PrimaryScreen.WorkingArea.Height);
907 form.InitialSize =
new Size(form.Width, height);
908 form.Height = height;
910 form.SuspendLayout();
920 private IAllowFormSettingsAndActions AddButton(GPALButton gPALButton)
922 FormSettings.myForm.ControlList.Add(gPALButton);
923 Button button =
new Button
925 Name = gPALButton.
Name,
926 Text = gPALButton.
Text,
931 Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right,
933 Height = 10 < gPALButton.Height ? gPALButton.Height : 20,
936 gPALButton.WindowsControl = button;
938 ApplyWidth(0 < gPALButton.
Width ? gPALButton.
Width : FormSettings.buttonWidth, button);
940 foreach (var (evt, handler) in gPALButton.Callbacks)
942 if (handler ==
null)
continue;
946 case ControlEventType.DoubleClick:
947 button.DoubleClick += (EventHandler)handler;
950 case ControlEventType.Default:
951 case ControlEventType.Click:
952 button.Click += (EventHandler)handler;
958 FormSettings.TableLayoutPanel.Controls.Add(button);
960 if (
true == gPALButton.IsDefault)
962 FormSettings.myForm.AcceptButton = button;
963 button.DialogResult = DialogResult.OK;
967 if (!
string.IsNullOrWhiteSpace(gPALButton.ToolTipText))
968 ApplyToolTip(gPALButton, button);
977 private IAllowFormSettingsAndActions AddChart(GPALChart gPALChart)
979 FormSettings.myForm.ControlList.Add(gPALChart);
985 FormSettings.TableLayoutPanel.Controls.Add((Chart)gPALChart.WindowsControl);
986 ((Chart)gPALChart.WindowsControl).
Height = 10 < gPALChart.Height ? gPALChart.Height : 150;
988 Chart chart = gPALChart.WindowsControl;
990 ApplyWidth(gPALChart.Width, chart);
992 foreach (var (evt, handler) in gPALChart.Callbacks)
994 if (handler ==
null)
continue;
998 case ControlEventType.DragDrop:
999 chart.DragDrop += (DragEventHandler)handler;
1002 case ControlEventType.DragEnter:
1003 chart.DragEnter += (DragEventHandler)handler;
1006 case ControlEventType.DragLeave:
1007 chart.DragLeave += (EventHandler)handler;
1010 case ControlEventType.DragOver:
1011 chart.DragOver += (DragEventHandler)handler;
1014 case ControlEventType.DoubleClick:
1015 chart.DoubleClick += (EventHandler)handler;
1018 case ControlEventType.Default:
1019 case ControlEventType.Click:
1020 chart.Click += (EventHandler)handler;
1026 if (!
string.IsNullOrWhiteSpace(gPALChart.ToolTipText))
1027 ApplyToolTip(gPALChart, chart);
1036 private IAllowFormSettingsAndActions AddCheckbox(GPALCheckbox gPALCheckbox)
1038 FormSettings.myForm.ControlList.Add(gPALCheckbox);
1039 CheckBox checkBox =
new CheckBox
1041 Name = gPALCheckbox.
Name,
1042 Text = gPALCheckbox.
Text,
1044 Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right,
1045 Checked = gPALCheckbox.
Checked,
1046 Enabled = gPALCheckbox.
Enabled,
1047 Height = 10 < gPALCheckbox.Height ? gPALCheckbox.Height : 20,
1049 gPALCheckbox.WindowsControl = checkBox;
1051 ApplyWidth(gPALCheckbox.
Width, checkBox);
1054 checkBox.CheckedChanged +=
new EventHandler(delegate (Object sender, EventArgs a) { gPALCheckbox.Checked = ((CheckBox)sender).Checked; });
1056 foreach (var (evt, handler) in gPALCheckbox.Callbacks)
1058 if (handler ==
null)
continue;
1062 case ControlEventType.Default:
1063 case ControlEventType.CheckedChanged:
1064 checkBox.CheckedChanged += (EventHandler)handler;
1067 case ControlEventType.DoubleClick:
1068 checkBox.DoubleClick += (EventHandler)handler;
1071 case ControlEventType.Click:
1072 checkBox.Click += (EventHandler)handler;
1078 FormSettings.TableLayoutPanel.Controls.Add(checkBox);
1080 if (!
string.IsNullOrWhiteSpace(gPALCheckbox.ToolTipText))
1081 ApplyToolTip(gPALCheckbox, checkBox);
1091 private static int FirstEnabledIndex(ComboBox combo, GPALComboBox gpalCombo)
1095 for (
int index = 0; index < combo.Items.Count && -1 == retVal; index++)
1096 if (
false == gpalCombo.disabledItems.Contains(combo.Items[index].ToString()))
1102 private IAllowFormSettingsAndActions AddComboBox(GPALComboBox gpalCombo)
1104 FormSettings.myForm.ControlList.Add(gpalCombo);
1106 var combo =
new ComboBox
1108 Name = gpalCombo.
Name,
1109 Enabled = gpalCombo.IsEnabled,
1110 DropDownStyle = ComboBoxStyle.DropDownList,
1111 Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right,
1112 Height = 10 < gpalCombo.Height ? gpalCombo.Height : 20,
1116 foreach (
string item
in gpalCombo.items)
1118 combo.Items.Add(item);
1122 if (!
string.IsNullOrEmpty(gpalCombo.selectedItem))
1124 int idx = combo.Items.IndexOf(gpalCombo.selectedItem);
1125 if (0 <= idx) combo.SelectedIndex = idx;
1127 else if (0 <= gpalCombo.selectedIndex && gpalCombo.selectedIndex < combo.Items.Count)
1129 combo.SelectedIndex = gpalCombo.selectedIndex;
1134 combo.DrawMode = DrawMode.OwnerDrawFixed;
1136 combo.DrawItem += (sender, args) =>
1138 if (0 > args.Index)
return;
1140 string text = combo.Items[args.Index].ToString();
1141 bool disabled =
true == gpalCombo.disabledItems.Contains(text);
1144 if (
false == disabled)
1145 args.DrawBackground();
1147 using (SolidBrush background =
new SolidBrush(SystemColors.Window))
1148 args.Graphics.FillRectangle(background, args.Bounds);
1150 using (SolidBrush foreground =
new SolidBrush(disabled ? SystemColors.GrayText : args.ForeColor))
1151 args.Graphics.DrawString(text, args.Font, foreground, args.Bounds);
1153 if (
false == disabled) args.DrawFocusRectangle();
1158 combo.SelectedIndexChanged += (sender, args) =>
1160 if (0 > combo.SelectedIndex)
return;
1162 string text = combo.Items[combo.SelectedIndex].ToString();
1164 if (
false == gpalCombo.disabledItems.Contains(text))
1166 gpalCombo.lastEnabledIndex = combo.SelectedIndex;
1170 GPAL.PublishSimpleEvent(Enums.GPALEventType.CAUTION, $
"[{text}] does not apply to what is selected, so it cannot be chosen",
null, Enums.GPALObjectType.GPALForm);
1172 combo.SelectedIndex = 0 <= gpalCombo.lastEnabledIndex && gpalCombo.lastEnabledIndex < combo.Items.Count
1173 ? gpalCombo.lastEnabledIndex
1174 : FirstEnabledIndex(combo, gpalCombo);
1177 gpalCombo.lastEnabledIndex = combo.SelectedIndex;
1179 gpalCombo.WindowsControl = combo;
1181 ApplyWidth(gpalCombo.
Width, combo);
1183 foreach (var (evt, handler) in gpalCombo.Callbacks)
1185 if (handler ==
null)
continue;
1189 case ControlEventType.Default:
1190 case ControlEventType.SelectedIndexChanged:
1191 combo.SelectedIndexChanged += (EventHandler)handler;
1194 case ControlEventType.ValueChanged:
1195 combo.SelectedValueChanged += (EventHandler)handler;
1198 case ControlEventType.Click:
1199 combo.Click += (EventHandler)handler;
1206 if (
false ==
string.IsNullOrEmpty(gpalCombo.ToolTipText))
1207 ApplyToolTip(gpalCombo, combo);
1209 FormSettings.TableLayoutPanel.Controls.Add(combo);
1218 private IAllowFormSettingsAndActions AddDataGridView(GPALDataGridView gPALDataGridView)
1220 FormSettings.myForm.ControlList.Add(gPALDataGridView);
1222 DataGridView dgv =
new DataGridView
1224 Name = gPALDataGridView.
Name,
1225 ReadOnly = gPALDataGridView.ReadOnly,
1227 Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Bottom | AnchorStyles.Right,
1228 Enabled = gPALDataGridView.IsEnabled,
1229 AllowUserToAddRows =
false,
1230 RowHeadersVisible =
false,
1232 Height = 10 < gPALDataGridView.Height ? gPALDataGridView.Height : 20,
1236 foreach (
string colName
in gPALDataGridView.
ColumnNames)
1238 dgv.Columns.Add(colName, colName);
1241 gPALDataGridView.WindowsControl = dgv;
1243 ApplyWidth(gPALDataGridView.
Width, dgv);
1246 foreach (var (evt, handler) in gPALDataGridView.Callbacks)
1248 if (handler ==
null)
continue;
1252 case ControlEventType.Default:
1253 case ControlEventType.CellValueChanged:
1254 case ControlEventType.Change:
1255 dgv.CellValueChanged += (DataGridViewCellEventHandler)handler;
1258 case ControlEventType.DoubleClick:
1259 dgv.DoubleClick += (EventHandler)handler;
1262 case ControlEventType.Click:
1263 dgv.Click += (EventHandler)handler;
1270 gPALDataGridView.SyncGridToControl();
1271 gPALDataGridView.ApplyColumnWidths();
1272 gPALDataGridView.ApplyWrap();
1274 FormSettings.TableLayoutPanel.Controls.Add(dgv);
1278 if (
true == gPALDataGridView.LastColumnFills)
1280 void fillLastColumn(
object s, EventArgs e) => gPALDataGridView.FillLastColumn();
1282 dgv.Resize += fillLastColumn;
1283 dgv.HandleCreated += fillLastColumn;
1287 dgv.RowsAdded += (s, e) => gPALDataGridView.FillLastColumn();
1288 dgv.RowsRemoved += (s, e) => gPALDataGridView.FillLastColumn();
1291 if (!
string.IsNullOrWhiteSpace(gPALDataGridView.ToolTipText))
1292 ApplyToolTip(gPALDataGridView, dgv);
1301 private IAllowFormSettingsAndActions AddDateTimePicker(GPALDateTimePicker gPALDateTimePicker)
1303 FormSettings.myForm.ControlList.Add(gPALDateTimePicker);
1305 DateTimePicker dtp =
new DateTimePicker
1307 Name = gPALDateTimePicker.
Name,
1308 Value = gPALDateTimePicker.
Value,
1309 Format = gPALDateTimePicker.
Format,
1311 Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right,
1312 Enabled = gPALDateTimePicker.IsEnabled,
1313 Height = 10 < gPALDateTimePicker.Height ? gPALDateTimePicker.Height : 10,
1316 gPALDateTimePicker.WindowsControl = dtp;
1318 ApplyWidth(gPALDateTimePicker.
Width, dtp);
1320 foreach (var (evt, handler) in gPALDateTimePicker.Callbacks)
1322 if (handler ==
null)
continue;
1326 case ControlEventType.Default:
1327 case ControlEventType.ValueChanged:
1328 case ControlEventType.Change:
1329 dtp.ValueChanged += (EventHandler)handler;
1332 case ControlEventType.Click:
1333 dtp.Click += (EventHandler)handler;
1339 FormSettings.TableLayoutPanel.Controls.Add(dtp);
1341 if (!
string.IsNullOrWhiteSpace(gPALDateTimePicker.ToolTipText))
1342 ApplyToolTip(gPALDateTimePicker, dtp);
1351 private IAllowFormSettingsAndActions AddFileSelector(GPALFileSelector gPALFileSelector)
1353 FormSettings.myForm.ControlList.Add(gPALFileSelector);
1355 if (gPALFileSelector._compact)
1356 return AddFileSelectorCompact(gPALFileSelector);
1358 Button browseButton =
new Button
1360 Name = gPALFileSelector.Name +
"_Browse",
1362 Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right,
1364 Enabled = gPALFileSelector.IsEnabled
1367 TextBox displayBox =
new TextBox
1369 Name = gPALFileSelector.Name +
"_Path",
1371 Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right,
1374 Text =
true ==
string.IsNullOrWhiteSpace(gPALFileSelector.SelectedPath)
1375 ?
"(click Browse to select)"
1376 : gPALFileSelector.SelectedPath,
1377 Enabled = gPALFileSelector.IsEnabled
1380 TableLayoutPanel container =
new TableLayoutPanel
1384 Dock = DockStyle.Top,
1387 Height = Math.Max(displayBox.PreferredHeight, browseButton.Height) + 4,
1388 Margin =
new Padding(0)
1390 container.RowStyles.Add(
new RowStyle(SizeType.Percent, 100));
1391 container.ColumnStyles.Add(
new ColumnStyle(SizeType.Absolute, 90));
1392 container.ColumnStyles.Add(
new ColumnStyle(SizeType.Percent, 100));
1393 container.Controls.Add(browseButton, 0, 0);
1394 container.Controls.Add(displayBox, 1, 0);
1396 gPALFileSelector.WindowsControl = container;
1402 foreach (var (evt, handler) in gPALFileSelector.Callbacks)
1404 if (handler ==
null)
continue;
1406 if (ControlEventType.TextChanged == evt)
1407 displayBox.TextChanged += (EventHandler)handler;
1411 browseButton.Click += (s, e) =>
1413 string[] selected = OpenBrowseDialog(gPALFileSelector);
1414 bool cancelled = selected ==
null || selected.Length == 0;
1415 gPALFileSelector.NotifySelection(cancelled, selected);
1416 displayBox.Text = cancelled ?
"(selection cancelled)" :
string.Join(
"; ", selected);
1419 FormSettings.TableLayoutPanel.Controls.Add(container);
1421 if (!
string.IsNullOrWhiteSpace(gPALFileSelector.ToolTipText))
1422 ApplyToolTip(gPALFileSelector, container);
1427 private IAllowFormSettingsAndActions AddFileSelectorCompact(GPALFileSelector gPALFileSelector)
1429 PlaceholderTextBox textBox =
new PlaceholderTextBox
1431 Name = gPALFileSelector.Name +
"_Path",
1432 Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right,
1433 Enabled = gPALFileSelector.IsEnabled,
1434 PlaceholderText = gPALFileSelector._placeholder,
1436 Text = gPALFileSelector.SelectedPath
1439 Button dotButton =
new Button
1441 Name = gPALFileSelector.Name +
"_Browse",
1444 Anchor = AnchorStyles.Top | AnchorStyles.Right,
1445 Enabled = gPALFileSelector.IsEnabled
1448 TableLayoutPanel container =
new TableLayoutPanel
1450 Name = gPALFileSelector.
Name,
1453 Dock = DockStyle.Top,
1457 Height = Math.Max(textBox.PreferredHeight, dotButton.Height) + 4,
1458 Margin =
new Padding(0)
1460 container.RowStyles.Add(
new RowStyle(SizeType.Percent, 100));
1461 container.ColumnStyles.Add(
new ColumnStyle(SizeType.Percent, 100));
1462 container.ColumnStyles.Add(
new ColumnStyle(SizeType.Absolute, 32));
1463 container.Controls.Add(textBox, 0, 0);
1464 container.Controls.Add(dotButton, 1, 0);
1467 gPALFileSelector.WindowsControl = textBox;
1473 foreach (var (evt, handler) in gPALFileSelector.Callbacks)
1475 if (handler ==
null)
continue;
1477 if (ControlEventType.TextChanged == evt)
1478 textBox.TextChanged += (EventHandler)handler;
1482 textBox.TextChanged += (s, e) => gPALFileSelector._selectedPath = textBox.Text;
1484 dotButton.Click += (s, e) =>
1486 string[] selected = OpenBrowseDialog(gPALFileSelector);
1487 bool cancelled = selected ==
null || selected.Length == 0;
1489 textBox.Text = selected[0];
1490 gPALFileSelector.NotifySelection(cancelled, selected);
1493 FormSettings.TableLayoutPanel.Controls.Add(container);
1495 if (!
string.IsNullOrWhiteSpace(gPALFileSelector.ToolTipText))
1496 ApplyToolTip(gPALFileSelector, container);
1501 private static string[] OpenBrowseDialog(GPALFileSelector gPALFileSelector)
1503 if (gPALFileSelector._selectFolder)
1505 using (FolderBrowserDialog fbd =
new FolderBrowserDialog())
1507 fbd.Description = gPALFileSelector._title;
1508 fbd.SelectedPath = gPALFileSelector._initialDirectory;
1509 return fbd.ShowDialog() == DialogResult.OK ?
new[] { fbd.SelectedPath } :
null;
1514 using (OpenFileDialog ofd =
new OpenFileDialog())
1516 ofd.Title = gPALFileSelector._title;
1517 ofd.InitialDirectory = gPALFileSelector._initialDirectory;
1518 ofd.Filter = gPALFileSelector._filter;
1519 ofd.Multiselect = gPALFileSelector._multiSelect;
1520 return ofd.ShowDialog() == DialogResult.OK ? ofd.FileNames :
null;
1529 private IAllowFormSettingsAndActions AddInput(GPALInput gPALInput)
1531 FormSettings.myForm.ControlList.Add(gPALInput);
1532 PlaceholderTextBox input =
new PlaceholderTextBox
1534 Name = gPALInput.
Name,
1535 Text = gPALInput.
Text,
1537 Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right,
1539 Height = 10 < gPALInput.Height ? gPALInput.Height : 20,
1542 if (!
string.IsNullOrEmpty(gPALInput.PlaceHolder))
1543 input.PlaceholderText = gPALInput.PlaceHolder;
1545 if (
true == gPALInput.InputIsPassword)
1546 input.PasswordChar =
'\u25CF';
1548 if (
true == gPALInput.IsReadOnly)
1549 input.ReadOnly =
true;
1551 gPALInput.WindowsControl = input;
1553 ApplyWidth(gPALInput.
Width, input);
1555 input.Text = gPALInput.
Text;
1557 input.TextChanged +=
new EventHandler(delegate (Object sender, EventArgs a) { gPALInput.Text = ((TextBox)sender).Text; });
1559 foreach (var (evt, handler) in gPALInput.Callbacks)
1561 if (handler ==
null)
continue;
1565 case ControlEventType.Default:
1566 case ControlEventType.TextChanged:
1567 input.TextChanged += (EventHandler)handler;
1570 case ControlEventType.DoubleClick:
1571 input.DoubleClick += (EventHandler)handler;
1574 case ControlEventType.Click:
1575 input.Click += (EventHandler)handler;
1578 case ControlEventType.KeyDown:
1579 input.KeyDown += (KeyEventHandler)handler;
1585 FormSettings.TableLayoutPanel.Controls.Add(input);
1587 if (!
string.IsNullOrWhiteSpace(gPALInput.ToolTipText))
1588 ApplyToolTip(gPALInput, input);
1611 private const int MinimumWidthToMeasure = 60;
1613 private void FitLabelHeight(Label label)
1618 if (MinimumWidthToMeasure < label.Width)
1620 Size measured = TextRenderer.MeasureText(label.Text, label.Font,
new Size(label.Width,
int.MaxValue),
1621 TextFormatFlags.WordBreak | TextFormatFlags.TextBoxControl);
1623 int wanted = 18 > measured.Height ? 18 : measured.Height;
1625 if (label.Height != wanted)
1626 label.Height = wanted;
1636 private IAllowFormSettingsAndActions AddSpacer(GPALSpacer gPALSpacer)
1638 FormSettings.myForm.ControlList.Add(gPALSpacer);
1639 Panel spacer =
new Panel
1641 Name = gPALSpacer.
Name,
1643 Margin = Padding.Empty,
1644 Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right,
1647 gPALSpacer.WindowsControl = spacer;
1649 FormSettings.TableLayoutPanel.Controls.Add(spacer);
1660 private IAllowFormSettingsAndActions AddLinkLabel(GPALLinkLabel gPALLinkLabel)
1662 FormSettings.myForm.ControlList.Add(gPALLinkLabel);
1663 LinkLabel link =
new LinkLabel
1665 Name = gPALLinkLabel.
Name,
1666 Enabled = gPALLinkLabel.IsEnabled,
1667 Text = gPALLinkLabel.
Text,
1669 Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right,
1673 link.Font =
new Font(gPALLinkLabel.
FontType.FontFamily, 10f, FontStyle.Regular);
1674 link.Height = 18 < gPALLinkLabel.Height ? gPALLinkLabel.Height : 18;
1677 if (18 >= gPALLinkLabel.
Height)
1678 link.SizeChanged += (sender, args) => FitLabelHeight(link);
1680 link.LinkClicked += (sender, args) => gPALLinkLabel.Open();
1682 gPALLinkLabel.WindowsControl = link;
1684 ApplyWidth(gPALLinkLabel.
Width, link);
1686 foreach (var (evt, handler) in gPALLinkLabel.Callbacks)
1688 if (handler ==
null)
continue;
1692 case ControlEventType.DoubleClick:
1693 link.DoubleClick += (EventHandler)handler;
1696 case ControlEventType.Default:
1697 case ControlEventType.Click:
1698 link.Click += (EventHandler)handler;
1704 FormSettings.TableLayoutPanel.Controls.Add(link);
1706 if (!
string.IsNullOrWhiteSpace(gPALLinkLabel.ToolTipText))
1707 ApplyToolTip(gPALLinkLabel, link);
1712 private IAllowFormSettingsAndActions AddLabel(GPALLabel gPALLabel)
1714 FormSettings.myForm.ControlList.Add(gPALLabel);
1715 Label label =
new Label
1717 Name = gPALLabel.
Name,
1718 Enabled = gPALLabel.IsEnabled,
1719 Text = gPALLabel.
Text,
1722 Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right,
1724 label.Font =
new Font(label.Font.FontFamily, 10f, FontStyle.Bold);
1726 label.AutoSize =
false;
1727 label.Height = 18 < gPALLabel.Height ? gPALLabel.Height : 18;
1732 if (18 >= gPALLabel.
Height)
1733 label.SizeChanged += (sender, args) => FitLabelHeight(label);
1735 gPALLabel.WindowsControl = label;
1737 ApplyWidth(gPALLabel.
Width, label);
1739 foreach (var (evt, handler) in gPALLabel.Callbacks)
1741 if (handler ==
null)
continue;
1745 case ControlEventType.DoubleClick:
1746 label.DoubleClick += (EventHandler)handler;
1749 case ControlEventType.Default:
1750 case ControlEventType.Click:
1751 label.Click += (EventHandler)handler;
1757 FormSettings.TableLayoutPanel.Controls.Add(label);
1759 if (!
string.IsNullOrWhiteSpace(gPALLabel.ToolTipText))
1760 ApplyToolTip(gPALLabel, label);
1769 private IAllowFormSettingsAndActions AddListView(GPALListView gPALListView)
1771 FormSettings.myForm.ControlList.Add(gPALListView);
1773 ListView listView =
new ListView
1775 Name = gPALListView.
Name,
1779 CheckBoxes = gPALListView.checkBoxes,
1780 Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Bottom | AnchorStyles.Right,
1781 Enabled = gPALListView.IsEnabled,
1782 Height = 10 < gPALListView.Height ? gPALListView.
Height: 150,
1786 foreach (
string header
in gPALListView.
Columns)
1788 listView.Columns.Add(header, -2, HorizontalAlignment.Left);
1791 gPALListView.WindowsControl = listView;
1793 ApplyWidth(gPALListView.
Width, listView);
1794 gPALListView.ApplyColumnWidths();
1798 listView.ItemSelectionChanged += (sender, args) =>
1800 if (
true == args.IsSelected && SystemColors.GrayText == args.Item.ForeColor)
1801 args.Item.Selected =
false;
1804 foreach (var (evt, handler) in gPALListView.Callbacks)
1806 if (handler ==
null)
continue;
1810 case ControlEventType.Default:
1811 case ControlEventType.SelectedIndexChanged:
1812 case ControlEventType.Change:
1813 listView.SelectedIndexChanged += (EventHandler)handler;
1816 case ControlEventType.DoubleClick:
1817 listView.DoubleClick += (EventHandler)handler;
1820 case ControlEventType.Click:
1821 listView.Click += (EventHandler)handler;
1826 case ControlEventType.ItemChecked:
1827 listView.ItemChecked += (ItemCheckedEventHandler)handler;
1833 FormSettings.TableLayoutPanel.Controls.Add(listView);
1837 var comparer =
new ListViewItemComparer();
1838 listView.ListViewItemSorter = comparer;
1839 listView.ColumnClick += (s, e) =>
1841 if (comparer.Column == e.Column)
1842 comparer.Order = comparer.Order == SortOrder.Ascending
1843 ? SortOrder.Descending : SortOrder.Ascending;
1846 comparer.Column = e.Column;
1847 comparer.Order = SortOrder.Ascending;
1857 foreach (var w
in weights) total += w;
1858 if (total <= 0) total = 1;
1860 void applyWeights(
object s, EventArgs e)
1862 int available = listView.ClientSize.Width - SystemInformation.VerticalScrollBarWidth;
1863 if (available <= 0)
return;
1864 for (
int i = 0; i < weights.Count && i < listView.Columns.Count; i++)
1865 listView.Columns[i].Width = (
int)(available * weights[i] / total);
1868 listView.Resize += applyWeights;
1869 listView.HandleCreated += applyWeights;
1875 if (
true == gPALListView.LastColumnFills)
1877 void layOutColumns(
object s, EventArgs e) => gPALListView.LayOutColumns();
1879 listView.Resize += layOutColumns;
1880 listView.HandleCreated += layOutColumns;
1883 if (!
string.IsNullOrWhiteSpace(gPALListView.ToolTipText))
1884 ApplyToolTip(gPALListView, listView);
1893 private IAllowFormSettingsAndActions AddNumericUpDown(GPALNumericUpDown gPALNumericUpDown)
1895 FormSettings.myForm.ControlList.Add(gPALNumericUpDown);
1897 NumericUpDown nud =
new NumericUpDown
1899 Name = gPALNumericUpDown.
Name,
1900 Value = gPALNumericUpDown.
Value,
1901 Minimum = gPALNumericUpDown.
Minimum,
1902 Maximum = gPALNumericUpDown.
Maximum,
1903 Increment = gPALNumericUpDown.
Increment,
1905 Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right,
1906 Enabled = gPALNumericUpDown.IsEnabled,
1907 Height = 10 < gPALNumericUpDown.Height ? gPALNumericUpDown.Height : 20,
1910 gPALNumericUpDown.WindowsControl = nud;
1912 ApplyWidth(gPALNumericUpDown.
Width, nud);
1914 foreach (var (evt, handler) in gPALNumericUpDown.Callbacks)
1916 if (handler ==
null)
continue;
1920 case ControlEventType.Default:
1921 case ControlEventType.ValueChanged:
1922 case ControlEventType.Change:
1923 nud.ValueChanged += (EventHandler)handler;
1926 case ControlEventType.Click:
1927 nud.Click += (EventHandler)handler;
1933 FormSettings.TableLayoutPanel.Controls.Add(nud);
1935 if (!
string.IsNullOrWhiteSpace(gPALNumericUpDown.ToolTipText))
1936 ApplyToolTip(gPALNumericUpDown, nud);
1945 private IAllowFormSettingsAndActions AddPicture(GPALPicture gPALPicture)
1947 FormSettings.myForm.ControlList.Add(gPALPicture);
1949 PictureBox pictureBox =
new PictureBox
1951 Name = gPALPicture.
Name,
1952 Enabled = gPALPicture.IsEnabled,
1953 Image = gPALPicture.
Image,
1955 Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right,
1956 Height = 10 < gPALPicture.Height ? gPALPicture.Height : 150,
1959 gPALPicture.WindowsControl = pictureBox;
1961 ApplyWidth(gPALPicture.
Width, pictureBox);
1963 foreach (var (evt, handler) in gPALPicture.Callbacks)
1965 if (handler ==
null)
continue;
1969 case ControlEventType.Default:
1970 case ControlEventType.Click:
1971 pictureBox.Click += (EventHandler)handler;
1974 case ControlEventType.DoubleClick:
1975 pictureBox.DoubleClick += (EventHandler)handler;
1982 FormSettings.TableLayoutPanel.Controls.Add(pictureBox);
1984 if (!
string.IsNullOrWhiteSpace(gPALPicture.ToolTipText))
1985 ApplyToolTip(gPALPicture, pictureBox);
1996 private IAllowFormSettingsAndActions AddSlider(GPALSlider gPALSlider)
1998 FormSettings.myForm.ControlList.Add(gPALSlider);
2000 TrackBar slider =
new TrackBar
2002 Name = gPALSlider.
Name,
2005 TickFrequency = 1 > gPALSlider.TickFrequency ? 1 : gPALSlider.
TickFrequency,
2007 Value = gPALSlider.
Value,
2008 Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right,
2009 Enabled = gPALSlider.IsEnabled,
2010 Height = 10 < gPALSlider.Height ? gPALSlider.Height : 45,
2013 gPALSlider.WindowsControl = slider;
2015 ApplyWidth(gPALSlider.
Width, slider);
2017 foreach (var (evt, handler) in gPALSlider.Callbacks)
2019 if (handler ==
null)
continue;
2023 case ControlEventType.Default:
2024 case ControlEventType.ValueChanged:
2025 case ControlEventType.Change:
2026 slider.ValueChanged += (EventHandler)handler;
2029 case ControlEventType.Scroll:
2030 slider.Scroll += (EventHandler)handler;
2033 case ControlEventType.Click:
2034 slider.Click += (EventHandler)handler;
2041 FormSettings.TableLayoutPanel.Controls.Add(slider);
2043 if (!
string.IsNullOrWhiteSpace(gPALSlider.ToolTipText))
2044 ApplyToolTip(gPALSlider, slider);
2054 private IAllowFormSettingsAndActions AddProgressBar(GPALProgressBar gPALProgressBar)
2056 FormSettings.myForm.ControlList.Add(gPALProgressBar);
2058 ProgressBar progressBar =
new ProgressBar
2060 Name = gPALProgressBar.
Name,
2061 Minimum = gPALProgressBar.
Minimum,
2062 Maximum = gPALProgressBar.
Maximum,
2063 Value = gPALProgressBar.
Value,
2064 Style = gPALProgressBar.
Style,
2065 Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right,
2066 Enabled = gPALProgressBar.IsEnabled,
2067 Height = 10 < gPALProgressBar.Height ? gPALProgressBar.Height : 20,
2070 gPALProgressBar.WindowsControl = progressBar;
2072 ApplyWidth(gPALProgressBar.
Width, progressBar);
2074 foreach (var (evt, handler) in gPALProgressBar.Callbacks)
2076 if (handler ==
null)
continue;
2080 case ControlEventType.Default:
2081 case ControlEventType.Click:
2082 progressBar.Click += (EventHandler)handler;
2089 FormSettings.TableLayoutPanel.Controls.Add(progressBar);
2091 if (!
string.IsNullOrWhiteSpace(gPALProgressBar.ToolTipText))
2092 ApplyToolTip(gPALProgressBar, progressBar);
2102 private IAllowFormSettingsAndActions AddRadioButton(GPALRadioButton gPALRadioButton)
2104 FormSettings.myForm.ControlList.Add(gPALRadioButton);
2105 RadioButton radioButton =
new RadioButton
2107 Name = gPALRadioButton.
Name,
2108 Text = gPALRadioButton.
Text,
2110 Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right,
2111 Checked = gPALRadioButton.
Checked,
2112 Enabled = gPALRadioButton.
Enabled,
2113 Height = 10 < gPALRadioButton.Height ? gPALRadioButton.Height : 20,
2115 gPALRadioButton.WindowsControl = radioButton;
2117 ApplyWidth(gPALRadioButton.
Width, radioButton);
2118 radioButton.CheckedChanged +=
new EventHandler(delegate (Object sender, EventArgs a) { gPALRadioButton.Checked = ((RadioButton)sender).Checked; });
2120 foreach (var (evt, handler) in gPALRadioButton.Callbacks)
2122 if (handler ==
null)
continue;
2126 case ControlEventType.Default:
2127 case ControlEventType.CheckedChanged:
2128 radioButton.CheckedChanged += (EventHandler)handler;
2131 case ControlEventType.Click:
2132 radioButton.Click += (EventHandler)handler;
2138 FormSettings.TableLayoutPanel.Controls.Add(radioButton);
2140 if (!
string.IsNullOrWhiteSpace(gPALRadioButton.ToolTipText))
2141 ApplyToolTip(gPALRadioButton, radioButton);
2150 private IAllowFormSettingsAndActions AddStatusStrip(GPALStatusStrip gPALStatusStrip)
2152 FormSettings.myForm.ControlList.Add(gPALStatusStrip);
2154 StatusStrip statusStrip =
new StatusStrip
2156 Name = gPALStatusStrip.
Name,
2157 Dock = DockStyle.Bottom,
2159 Enabled = gPALStatusStrip.IsEnabled,
2160 Height = 10 < gPALStatusStrip.Height ? gPALStatusStrip.Height : 20,
2163 ToolStripStatusLabel statusLabel =
new ToolStripStatusLabel
2165 Text = gPALStatusStrip.
Text,
2167 TextAlign = ContentAlignment.MiddleLeft,
2168 Height = 10 < gPALStatusStrip.Height ? gPALStatusStrip.Height : 20,
2171 statusStrip.Items.Add(statusLabel);
2173 gPALStatusStrip.WindowsControl = statusStrip;
2175 foreach (var (evt, handler) in gPALStatusStrip.Callbacks)
2177 if (handler ==
null)
continue;
2181 case ControlEventType.Click:
2182 case ControlEventType.Default:
2183 statusStrip.ItemClicked += (sender, e) => ((EventHandler)handler)(sender, e);
2191 FormSettings.myForm.Controls.Add(statusStrip);
2193 if (!
string.IsNullOrWhiteSpace(gPALStatusStrip.ToolTipText))
2194 ApplyToolTip(gPALStatusStrip, statusStrip);
2203 private IAllowFormSettingsAndActions AddMenuBar(GPALMenuBar gPALMenuBar)
2205 FormSettings.myForm.ControlList.Add(gPALMenuBar);
2207 MenuStrip menuStrip =
new MenuStrip
2209 Name = gPALMenuBar.
Name,
2210 Enabled = gPALMenuBar.IsEnabled,
2213 var topMenus =
new System.Collections.Generic.Dictionary<string, ToolStripMenuItem>();
2214 foreach (var (topMenu, item, isSeparator) in gPALMenuBar.menuEntries)
2216 string menuKey =
string.IsNullOrWhiteSpace(topMenu) ?
"" : topMenu;
2217 if (!topMenus.TryGetValue(menuKey, out ToolStripMenuItem topItem))
2219 topItem =
new ToolStripMenuItem(menuKey);
2220 topMenus[menuKey] = topItem;
2221 menuStrip.Items.Add(topItem);
2226 topItem.DropDownItems.Add(
new ToolStripSeparator());
2230 ToolStripMenuItem menuItem =
new ToolStripMenuItem(item.Text);
2231 if (item.Image !=
null)
2232 menuItem.Image = item.Image;
2233 if (item.ShortCutKey != System.Windows.Forms.Keys.None)
2235 menuItem.ShortcutKeys = item.ShortCutKey;
2236 menuItem.ShowShortcutKeys =
true;
2240 foreach (var (evt, handler) in item.Callbacks)
2242 if (
null == handler)
continue;
2246 case ControlEventType.Default:
2247 case ControlEventType.Click:
2248 menuItem.Click += (EventHandler)handler;
2251 case ControlEventType.DoubleClick:
2252 menuItem.DoubleClick += (EventHandler)handler;
2257 if (!
string.IsNullOrWhiteSpace(item.ToolTipText))
2258 menuItem.ToolTipText = item.ToolTipText;
2261 menuItem.Enabled = item.IsEnabled;
2262 item.WindowsControl = menuItem;
2263 topItem.DropDownItems.Add(menuItem);
2266 gPALMenuBar.WindowsControl = menuStrip;
2269 FormSettings.myForm.Controls.Add(menuStrip);
2270 FormSettings.myForm.MainMenuStrip = menuStrip;
2274 FormSettings.myForm.Controls.SetChildIndex(menuStrip, FormSettings.myForm.Controls.Count - 1);
2284 private IAllowFormSettingsAndActions AddToolbar(GPALToolbar gPALToolbar)
2286 FormSettings.myForm.ControlList.Add(gPALToolbar);
2288 ToolStrip toolStrip =
new ToolStrip
2290 Name = gPALToolbar.
Name,
2291 Enabled = gPALToolbar.IsEnabled,
2294 foreach (var (item, isSeparator) in gPALToolbar.toolbarEntries)
2298 toolStrip.Items.Add(
new ToolStripSeparator());
2302 ToolStripButton button =
new ToolStripButton(item.Text);
2303 if (item.Image !=
null)
2305 button.Image = item.Image;
2306 button.DisplayStyle =
string.IsNullOrWhiteSpace(item.Text)
2307 ? ToolStripItemDisplayStyle.Image
2308 : ToolStripItemDisplayStyle.ImageAndText;
2311 button.DisplayStyle = ToolStripItemDisplayStyle.Text;
2314 foreach (var (evt, handler) in item.Callbacks)
2316 if (
null == handler)
continue;
2320 case ControlEventType.Default:
2321 case ControlEventType.Click:
2322 button.Click += (EventHandler)handler;
2325 case ControlEventType.DoubleClick:
2326 button.DoubleClick += (EventHandler)handler;
2331 if (!
string.IsNullOrWhiteSpace(item.ToolTipText))
2332 button.ToolTipText = item.ToolTipText;
2334 button.Enabled = item.IsEnabled;
2335 item.WindowsControl = button;
2336 toolStrip.Items.Add(button);
2339 gPALToolbar.WindowsControl = toolStrip;
2342 FormSettings.myForm.Controls.Add(toolStrip);
2343 if (FormSettings.myForm.MainMenuStrip !=
null)
2344 FormSettings.myForm.Controls.SetChildIndex(FormSettings.myForm.MainMenuStrip, FormSettings.myForm.Controls.Count - 1);
2353 private IAllowFormSettingsAndActions AddTab(GPALTab gPALTab)
2355 if (
null == FormSettings.TabControl)
2357 FormSettings.TabControl =
new TabControl
2359 Name =
"tabControl",
2362 Dock = DockStyle.Fill,
2369 FormSettings.TabControl.Selecting += (sender, args) =>
2373 if (
null == FormSettings.TabControl.SelectedTab)
return;
2375 if (
null != args.TabPage &&
false == args.TabPage.Enabled) args.Cancel =
true;
2378 FormSettings.TableLayoutPanel.Controls.Add(FormSettings.TabControl);
2381 TabPage tabPage =
new TabPage
2383 Name = gPALTab.
Name,
2384 Text = gPALTab.
Text,
2387 Dock = DockStyle.Fill,
2388 Enabled = gPALTab.Enabled
2391 TableLayoutPanel tmpTableLayoutPanel =
new TableLayoutPanel
2394 Dock = DockStyle.Fill,
2402 gPALTab.WindowsControl = tabPage;
2404 FormSettings.myForm.ControlList.Add(gPALTab);
2406 foreach (var (evt, handler) in gPALTab.Callbacks)
2408 if (handler ==
null)
continue;
2412 case ControlEventType.Scroll:
2413 tabPage.Scroll += (ScrollEventHandler)handler;
2416 case ControlEventType.Click:
2419 tabPage.Click += (EventHandler)handler;
2422 case ControlEventType.Default:
2423 case ControlEventType.SelectedIndexChanged:
2424 case ControlEventType.Change:
2428 FormSettings.TabControl.Selected += (sender, args) =>
2430 if (args.TabPage == tabPage)
2431 ((EventHandler)handler)(gPALTab, args);
2438 tabPage.Controls.Add(tmpTableLayoutPanel);
2439 FormSettings.TabControl.Controls.Add(tabPage);
2440 FormSettings.TableLayoutPanel = tmpTableLayoutPanel;
2442 if (!
string.IsNullOrWhiteSpace(gPALTab.ToolTipText))
2443 ApplyToolTip(gPALTab, tabPage);
2455 private IAllowFormSettingsAndActions AddSplitter(GPALSplitter gPALSplitter)
2457 FormSettings.myForm.ControlList.Add(gPALSplitter);
2459 SplitContainer sc =
new SplitContainer
2461 Name = gPALSplitter.
Name,
2462 Enabled = gPALSplitter.IsEnabled,
2464 Orientation =
true == gPALSplitter.IsHorizontalSplit ? Orientation.Vertical : Orientation.Horizontal,
2472 Anchor = 10 < gPALSplitter.Height
2473 ? AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right
2474 : AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Bottom,
2475 Height = 10 < gPALSplitter.Height ? gPALSplitter.Height : 0,
2476 AutoScaleMode = AutoScaleMode.Inherit,
2479 Tag = 10 < gPALSplitter.Height ? SetHeightMarker :
null
2482 if (
true == gPALSplitter.IsPercentage)
2484 double pct = gPALSplitter.Percentage;
2487 sc.SizeChanged += (s, e) =>
2489 int along =
true == gPALSplitter.IsHorizontalSplit ? sc.Width : sc.Height;
2491 if (along > sc.Panel1MinSize + sc.Panel2MinSize + sc.SplitterWidth)
2492 sc.SplitterDistance = (int)(along * pct);
2496 sc.SplitterDistance = gPALSplitter.Dimension;
2498 gPALSplitter.WindowsControl = sc;
2502 foreach (var (evt, handler) in gPALSplitter.Callbacks)
2504 if (
null == handler)
continue;
2508 case ControlEventType.Default:
2509 case ControlEventType.SplitterMoved:
2510 sc.SplitterMoved += (SplitterEventHandler)handler;
2513 case ControlEventType.DoubleClick:
2514 sc.DoubleClick += (EventHandler)handler;
2517 case ControlEventType.Click:
2518 sc.Click += (EventHandler)handler;
2524 TableLayoutPanel firstPane = MakeSplitPaneTlp();
2525 TableLayoutPanel secondPane = MakeSplitPaneTlp();
2527 sc.Panel1.Controls.Add(firstPane);
2528 sc.Panel2.Controls.Add(secondPane);
2529 FormSettings.TableLayoutPanel.Controls.Add(sc);
2531 FillContainer(gPALSplitter.FormControls, firstPane, secondPane, gPALSplitter.
Name);
2537 if (10 >= gPALSplitter.
Height)
2542 Func<TableLayoutPanel, int> contentHeight = pane =>
2544 int total = pane.Padding.Top + pane.Padding.Bottom;
2546 foreach (Control child
in pane.Controls)
2547 total += child.Height + child.Margin.Bottom;
2553 sc.Height =
true == gPALSplitter.IsHorizontalSplit
2554 ? Math.Max(contentHeight(firstPane), contentHeight(secondPane))
2555 : contentHeight(firstPane) + contentHeight(secondPane) + sc.SplitterWidth;
2558 if (!
string.IsNullOrWhiteSpace(gPALSplitter.ToolTipText))
2559 ApplyToolTip(gPALSplitter, sc);
2565 private const int GroupBoxPadding = 3;
2568 private const int GroupBoxBottomClearance = 2;
2574 private IAllowFormSettingsAndActions AddGroupBox(GPALGroupBox gPALGroupBox)
2576 FormSettings.myForm.ControlList.Add(gPALGroupBox);
2578 GroupBox gb =
new GroupBox
2580 Name = gPALGroupBox.
Name,
2581 Text = gPALGroupBox.
Text,
2582 Enabled = gPALGroupBox.IsEnabled,
2586 Dock = DockStyle.Top,
2588 AutoSizeMode = AutoSizeMode.GrowAndShrink,
2592 Padding =
new Padding(GroupBoxPadding, GroupBoxPadding, GroupBoxPadding, GroupBoxPadding + GroupBoxBottomClearance),
2597 TableLayoutPanel inside =
new TableLayoutPanel
2599 Dock = DockStyle.Top,
2601 AutoSizeMode = AutoSizeMode.GrowAndShrink,
2605 inside.ColumnStyles.Add(
new ColumnStyle(SizeType.Percent, 100f));
2606 gb.Controls.Add(inside);
2607 FormSettings.TableLayoutPanel.Controls.Add(gb);
2609 gPALGroupBox.WindowsControl = gb;
2611 FillContainer(gPALGroupBox.FormControls, inside,
null, gPALGroupBox.
Name);
2613 if (!
string.IsNullOrWhiteSpace(gPALGroupBox.ToolTipText))
2614 ApplyToolTip(gPALGroupBox, gb);
2630 private void FillContainer(List<object> formControls, TableLayoutPanel firstPane, TableLayoutPanel secondPane,
string name)
2632 TableLayoutPanel outerPanel = FormSettings.TableLayoutPanel;
2633 TabControl outerTabControl = FormSettings.TabControl;
2634 TableLayoutPanel current = firstPane;
2635 bool markerSeen =
false;
2637 FormSettings.TabControl =
null;
2639 foreach (
object formControl
in formControls)
2641 if (formControl is GPALSpliter)
2643 if (
null == secondPane)
2644 GPAL.PublishSimpleEvent(GPALEventType.DEBUG, $
"[{name}] has no second pane, so the pane marker does nothing. Everything added stays in the one panel.");
2645 else if (
true == markerSeen)
2646 GPAL.PublishSimpleEvent(GPALEventType.DEBUG, $
"[{name}] has more than one pane marker and a splitter has only two panes, so everything after the first marker stays in the second.");
2649 current = secondPane;
2656 FormSettings.TableLayoutPanel = current;
2657 FormSettings.TabControl =
null;
2661 FormSettings.TableLayoutPanel = outerPanel;
2662 FormSettings.TabControl = outerTabControl;
2665 private TableLayoutPanel MakeSplitPaneTlp()
2667 var tlp =
new TableLayoutPanel
2669 Dock = DockStyle.Fill,
2673 tlp.ColumnStyles.Add(
new ColumnStyle(SizeType.Percent, 100f));
2682 private IAllowFormSettingsAndActions AddTableLayoutPanel(GPALTableLayoutPanel gPALTableLayoutPanel)
2684 FormSettings.myForm.ControlList.Add(gPALTableLayoutPanel);
2685 TableLayoutPanel tableLayoutPanel =
new TableLayoutPanel
2687 Name = gPALTableLayoutPanel.
Name,
2688 GrowStyle = gPALTableLayoutPanel.
GrowStyle,
2691 RowCount = gPALTableLayoutPanel.
RowCount,
2692 Enabled = gPALTableLayoutPanel.IsEnabled,
2693 Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right
2699 gPALTableLayoutPanel.WindowsControl = tableLayoutPanel;
2701 FormSettings.TableLayoutPanel.Controls.Add(tableLayoutPanel);
2703 if (!
string.IsNullOrWhiteSpace(gPALTableLayoutPanel.ToolTipText))
2704 ApplyToolTip(gPALTableLayoutPanel, tableLayoutPanel);
2714 private IAllowFormSettingsAndActions AddTextArea(GPALTextArea gPALTextArea)
2716 FormSettings.myForm.ControlList.Add(gPALTextArea);
2717 PlaceholderTextBox textBox =
new PlaceholderTextBox
2719 Name = gPALTextArea.
Name,
2720 Text = gPALTextArea.
Text,
2723 ScrollBars = ScrollBars.Both,
2724 Height = 10 < gPALTextArea.Height ? gPALTextArea.Height : 150,
2725 Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Bottom | AnchorStyles.Right,
2726 Enabled = gPALTextArea.Enabled
2728 if (
true == gPALTextArea.IsReadOnly)
2729 textBox.ReadOnly =
true;
2731 if (!
string.IsNullOrEmpty(gPALTextArea.PlaceHolder))
2732 textBox.PlaceholderText = gPALTextArea.PlaceHolder;
2734 gPALTextArea.WindowsControl = textBox;
2736 ApplyWidth(gPALTextArea.
Width, textBox);
2737 textBox.Text = gPALTextArea.
Text;
2739 textBox.TextChanged +=
new EventHandler(delegate (Object sender, EventArgs a) { gPALTextArea.Text = ((TextBox)sender).Text; });
2741 foreach (var (evt, handler) in gPALTextArea.Callbacks)
2743 if (handler ==
null)
continue;
2747 case ControlEventType.Default:
2748 case ControlEventType.TextChanged:
2749 textBox.TextChanged += (EventHandler)handler;
2752 case ControlEventType.Click:
2753 textBox.Click += (EventHandler)handler;
2759 FormSettings.TableLayoutPanel.Controls.Add(textBox);
2761 if (!
string.IsNullOrWhiteSpace(gPALTextArea.ToolTipText))
2762 ApplyToolTip(gPALTextArea, textBox);
2772 private IAllowFormSettingsAndActions AddRichTextBox(GPALRichTextBox gPALRichTextBox)
2774 FormSettings.myForm.ControlList.Add(gPALRichTextBox);
2775 RichTextBox richTextBox =
new RichTextBox
2777 Name = gPALRichTextBox.
Name,
2780 ReadOnly = gPALRichTextBox.IsReadOnly,
2781 ScrollBars = RichTextBoxScrollBars.Both,
2782 Height = 10 < gPALRichTextBox.Height ? gPALRichTextBox.Height : 150,
2783 Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Bottom | AnchorStyles.Right,
2784 Enabled = gPALRichTextBox.Enabled
2786 gPALRichTextBox.WindowsControl = richTextBox;
2788 ApplyWidth(gPALRichTextBox.
Width, richTextBox);
2789 GPALRichTextBox.RenderMarkdown(richTextBox, gPALRichTextBox.
Text);
2793 foreach (var (evt, handler) in gPALRichTextBox.Callbacks)
2795 if (handler ==
null)
continue;
2799 case ControlEventType.Default:
2800 case ControlEventType.TextChanged:
2801 richTextBox.TextChanged += (EventHandler)handler;
2804 case ControlEventType.DoubleClick:
2805 richTextBox.DoubleClick += (EventHandler)handler;
2808 case ControlEventType.Click:
2809 richTextBox.Click += (EventHandler)handler;
2812 case ControlEventType.KeyDown:
2813 richTextBox.KeyDown += (KeyEventHandler)handler;
2819 FormSettings.TableLayoutPanel.Controls.Add(richTextBox);
2821 if (!
string.IsNullOrWhiteSpace(gPALRichTextBox.ToolTipText))
2822 ApplyToolTip(gPALRichTextBox, richTextBox);
2831 private IAllowFormSettingsAndActions AddTreeView(GPALTreeView gPALTreeView)
2833 FormSettings.myForm.ControlList.Add(gPALTreeView);
2835 TreeView tv =
new TreeView
2837 Name = gPALTreeView.
Name,
2841 Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Bottom | AnchorStyles.Right,
2842 Enabled = gPALTreeView.IsEnabled,
2843 Height = 10 < gPALTreeView.Height ? gPALTreeView.Height : 150,
2847 tv.BeforeSelect += (sender, args) =>
2849 if (
null != args.Node && SystemColors.GrayText == args.Node.ForeColor) args.Cancel =
true;
2852 gPALTreeView.WindowsControl = tv;
2854 ApplyWidth(gPALTreeView.
Width, tv);
2856 foreach (var (evt, handler) in gPALTreeView.Callbacks)
2858 if (handler ==
null)
continue;
2862 case ControlEventType.Default:
2863 case ControlEventType.AfterSelect:
2864 case ControlEventType.Change:
2865 tv.AfterSelect += (TreeViewEventHandler)handler;
2868 case ControlEventType.DoubleClick:
2869 tv.DoubleClick += (EventHandler)handler;
2872 case ControlEventType.Click:
2873 tv.Click += (EventHandler)handler;
2879 FormSettings.TableLayoutPanel.Controls.Add(tv);
2881 if (!
string.IsNullOrWhiteSpace(gPALTreeView.ToolTipText))
2882 ApplyToolTip(gPALTreeView, tv);
2886 #endregion <private>