WIP] First attempt at tablelayout

This commit is contained in:
Terry MacDonald 2021-05-11 15:59:53 +12:00
parent 7534fe6fc6
commit 6131833b25
4 changed files with 102 additions and 29 deletions

View File

@ -128,6 +128,7 @@
</Compile>
<Compile Include="ShortcutItem.cs" />
<Compile Include="ShortcutRepository.cs" />
<Compile Include="TableLayoutHelper.cs" />
<Compile Include="UIForms\ApplyingProfileForm.cs">
<SubType>Form</SubType>
</Compile>

View File

@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Text;
using System.Threading.Tasks;
namespace DisplayMagician
{
public static class TableLayoutHelper
{
public static void RemoveArbitraryRow(TableLayoutPanel panel, int rowIndex)
{
if (rowIndex >= panel.RowCount)
{
return;
}
// delete all controls of row that we want to delete
for (int i = 0; i < panel.ColumnCount; i++)
{
var control = panel.GetControlFromPosition(i, rowIndex);
panel.Controls.Remove(control);
}
// move up row controls that comes after row we want to remove
for (int i = rowIndex + 1; i < panel.RowCount; i++)
{
for (int j = 0; j < panel.ColumnCount; j++)
{
var control = panel.GetControlFromPosition(j, i);
if (control != null)
{
panel.SetRow(control, i - 1);
}
}
}
var removeStyle = panel.RowCount - 1;
if (panel.RowStyles.Count > removeStyle)
panel.RowStyles.RemoveAt(removeStyle);
panel.RowCount--;
}
}
}

View File

@ -68,7 +68,6 @@ namespace DisplayMagician.UIForms
this.rb_change_audio = new System.Windows.Forms.RadioButton();
this.rb_no_change_audio = new System.Windows.Forms.RadioButton();
this.tabp_before = new System.Windows.Forms.TabPage();
this.pnl_start_programs = new System.Windows.Forms.Panel();
this.tabp_game = new System.Windows.Forms.TabPage();
this.lbl_no_game_libraries = new System.Windows.Forms.Label();
this.p_standalone = new System.Windows.Forms.Panel();
@ -119,6 +118,7 @@ namespace DisplayMagician.UIForms
this.cb_autosuggest = new System.Windows.Forms.CheckBox();
this.btn_hotkey = new System.Windows.Forms.Button();
this.lbl_hotkey_assigned = new System.Windows.Forms.Label();
this.tlp_start_programs = new System.Windows.Forms.TableLayoutPanel();
this.tabc_shortcut.SuspendLayout();
this.tabp_display.SuspendLayout();
this.tabp_audio.SuspendLayout();
@ -616,7 +616,7 @@ namespace DisplayMagician.UIForms
// tabp_before
//
this.tabp_before.BackColor = System.Drawing.Color.Black;
this.tabp_before.Controls.Add(this.pnl_start_programs);
this.tabp_before.Controls.Add(this.tlp_start_programs);
this.tabp_before.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.tabp_before.ForeColor = System.Drawing.Color.White;
this.tabp_before.Location = new System.Drawing.Point(4, 32);
@ -626,17 +626,6 @@ namespace DisplayMagician.UIForms
this.tabp_before.TabIndex = 1;
this.tabp_before.Text = "3. Choose what happens before";
//
// pnl_start_programs
//
this.pnl_start_programs.AutoScroll = true;
this.pnl_start_programs.AutoScrollMargin = new System.Drawing.Size(5, 5);
this.pnl_start_programs.AutoScrollMinSize = new System.Drawing.Size(5, 5);
this.pnl_start_programs.BackColor = System.Drawing.Color.White;
this.pnl_start_programs.Location = new System.Drawing.Point(38, 126);
this.pnl_start_programs.Name = "pnl_start_programs";
this.pnl_start_programs.Size = new System.Drawing.Size(1007, 446);
this.pnl_start_programs.TabIndex = 2;
//
// tabp_game
//
this.tabp_game.BackColor = System.Drawing.Color.Black;
@ -1259,6 +1248,24 @@ namespace DisplayMagician.UIForms
this.lbl_hotkey_assigned.Visible = false;
this.lbl_hotkey_assigned.Click += new System.EventHandler(this.lbl_hotkey_assigned_Click);
//
// tlp_start_programs
//
this.tlp_start_programs.AutoScroll = true;
this.tlp_start_programs.AutoScrollMinSize = new System.Drawing.Size(5, 0);
this.tlp_start_programs.BackColor = System.Drawing.Color.White;
this.tlp_start_programs.ColumnCount = 1;
this.tlp_start_programs.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tlp_start_programs.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tlp_start_programs.Dock = System.Windows.Forms.DockStyle.Bottom;
this.tlp_start_programs.Location = new System.Drawing.Point(3, 112);
this.tlp_start_programs.MinimumSize = new System.Drawing.Size(900, 150);
this.tlp_start_programs.Name = "tlp_start_programs";
this.tlp_start_programs.RowCount = 1;
this.tlp_start_programs.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tlp_start_programs.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tlp_start_programs.Size = new System.Drawing.Size(1076, 503);
this.tlp_start_programs.TabIndex = 0;
//
// ShortcutForm
//
this.AcceptButton = this.btn_save;
@ -1408,6 +1415,6 @@ namespace DisplayMagician.UIForms
private System.Windows.Forms.CheckBox cb_wait_alternative_game;
private System.Windows.Forms.Button btn_hotkey;
private System.Windows.Forms.Label lbl_hotkey_assigned;
private System.Windows.Forms.Panel pnl_start_programs;
private System.Windows.Forms.TableLayoutPanel tlp_start_programs;
}
}

View File

@ -456,7 +456,7 @@ namespace DisplayMagician.UIForms
// Scan through the list of
List<StartProgram> newStartPrograms = new List<StartProgram>() { };
foreach (StartProgramControl myStartProgramControl in pnl_start_programs.Controls)
foreach (StartProgramControl myStartProgramControl in tlp_start_programs.Controls)
{
newStartPrograms.Add(myStartProgramControl.StartProgram);
}
@ -1165,27 +1165,38 @@ namespace DisplayMagician.UIForms
if (_shortcutToEdit.StartPrograms is List<StartProgram> && _shortcutToEdit.StartPrograms.Count > 0)
{
int x = 5;
int y = 5;
//int x = 5;
//int y = 5;
Padding startProgramMargin = new Padding(10) { };
//Clear out the existing controls, we are generating a new table layout
tlp_start_programs.Controls.Clear();
//Clear out the existing row and column styles
tlp_start_programs.ColumnStyles.Clear();
tlp_start_programs.RowStyles.Clear();
int myIndex = 0;
// Order the inital list in order of priority
foreach (StartProgram myStartProgram in _shortcutToEdit.StartPrograms.OrderBy(sp => sp.Priority))
{
StartProgramControl startProgramControl = new StartProgramControl(myStartProgram);
startProgramControl.Dock = DockStyle.None;
startProgramControl.Margin = startProgramMargin;
startProgramControl.Width = pnl_start_programs.Width - 30;
//startProgramControl.Dock = DockStyle.None;
//startProgramControl.Margin = startProgramMargin;
startProgramControl.Width = tlp_start_programs.Width - 40;
//startProgramControl.Height = 170;
//startProgramControl.Height = pnl_start_programs.Height;
startProgramControl.Location = new Point(x, y);
//startProgramControl.Location = new Point(x, y);
// startProgramControl.BringToFront();
//startProgramControl.Margin = DefaultMargin;
//startProgramControl.Width = pnl_start_programs.Width;
pnl_start_programs.Controls.Add(startProgramControl);
tlp_start_programs.RowStyles.Add(new RowStyle(SizeType.Absolute, 170F));
tlp_start_programs.RowCount = myIndex + 1;
tlp_start_programs.Controls.Add(startProgramControl);
// Move the next line down
y += startProgramControl.Height + 5;
//y += startProgramControl.Height + 5;
}
}
@ -2018,20 +2029,26 @@ namespace DisplayMagician.UIForms
public void RemoveStartProgram(StartProgramControl startProgramControlToRemove)
{
int rowIndex = 1;
foreach (StartProgram startProgramToTest in _shortcutToEdit.StartPrograms)
{
{
if (startProgramControlToRemove.StartProgram.Equals(startProgramToTest))
{
// If we find the start program then we need to remove it from the list
_shortcutToEdit.StartPrograms.Remove(startProgramToTest);
// And we reove the program control passed in as well
pnl_start_programs.Controls.Remove(startProgramControlToRemove);
//_shortcutToEdit.StartPrograms.Remove(startProgramToTest);
// And we remove the program control passed in as well
tlp_start_programs.SuspendLayout();
// And we remove the row control passed in as well
TableLayoutHelper.RemoveArbitraryRow(tlp_start_programs, rowIndex);
tlp_start_programs.ResumeLayout();
//tlp_start_programs.PerformLayout();
break;
}
rowIndex++;
}
// And we redraw the panel again
pnl_start_programs.Refresh();
tlp_start_programs.Refresh();
}
private void btn_hotkey_Click(object sender, EventArgs e)