[WIP] Basic partially working panel

The panel successfully has the usercontrols
put into it, but it doesn't reorganise the rest
of the usercontrols when one is deleted up
to head of the list. I've done some research
and the internet tells me to move from a panel
container to a FlowLayoutPanel or a
TableLayoutPanel to get the automatic redrawing
functionality. It's apparently far easier to swap
than to write the redrawing code yourself.

So thats the plan for later this week.
This commit is contained in:
Terry MacDonald 2021-05-09 21:43:06 +12:00
parent 84c9338be4
commit 7534fe6fc6
8 changed files with 91 additions and 50 deletions

View File

@ -78,6 +78,7 @@
<ItemGroup>
<Reference Include="Microsoft.CSharp" />
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Data" />

View File

@ -43,7 +43,7 @@ namespace DisplayMagician
public struct StartProgram
{
public int Priority;
public bool Enabled;
public bool Disabled;
public string Executable;
public string Arguments;
public bool ExecutableArgumentsRequired;

View File

@ -773,7 +773,7 @@ namespace DisplayMagician
// Now run the pre-start applications
List<Process> startProgramsToStop = new List<Process>();
List<StartProgram> startProgramsToStart = shortcutToUse.StartPrograms.Where(program => program.Enabled == true).OrderBy(program => program.Priority).ToList();
List<StartProgram> startProgramsToStart = shortcutToUse.StartPrograms.Where(program => program.Disabled == true).OrderBy(program => program.Priority).ToList();
if (startProgramsToStart.Count > 0)
{
logger.Info($"ShortcutRepository/RunShortcut: Starting {startProgramsToStart.Count} programs before the main game or executable");

View File

@ -629,10 +629,12 @@ namespace DisplayMagician.UIForms
// 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(58, 65);
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(987, 507);
this.pnl_start_programs.Size = new System.Drawing.Size(1007, 446);
this.pnl_start_programs.TabIndex = 2;
//
// tabp_game

View File

@ -1165,20 +1165,27 @@ namespace DisplayMagician.UIForms
if (_shortcutToEdit.StartPrograms is List<StartProgram> && _shortcutToEdit.StartPrograms.Count > 0)
{
int x = 0;
int y = 0;
int x = 5;
int y = 5;
Padding startProgramMargin = new Padding(10) { };
// 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.Height = pnl_start_programs.Height;
startProgramControl.Location = new Point(x, y);
startProgramControl.BringToFront();
startProgramControl.Margin = DefaultMargin;
startProgramControl.Width = pnl_start_programs.Width;
// startProgramControl.BringToFront();
//startProgramControl.Margin = DefaultMargin;
//startProgramControl.Width = pnl_start_programs.Width;
pnl_start_programs.Controls.Add(startProgramControl);
y += startProgramControl.Height;
// Move the next line down
y += startProgramControl.Height + 5;
}
}
@ -2009,6 +2016,24 @@ namespace DisplayMagician.UIForms
}
}
public void RemoveStartProgram(StartProgramControl startProgramControlToRemove)
{
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);
break;
}
}
// And we redraw the panel again
pnl_start_programs.Refresh();
}
private void btn_hotkey_Click(object sender, EventArgs e)
{
Keys testHotkey;

View File

@ -36,7 +36,8 @@ namespace DisplayMagician.UIForms
this.txt_start_program_args = new System.Windows.Forms.TextBox();
this.cb_start_program_pass_args = new System.Windows.Forms.CheckBox();
this.btn_delete = new System.Windows.Forms.Button();
this.cb_start_program = new System.Windows.Forms.CheckBox();
this.cb_disable_start_program = new System.Windows.Forms.CheckBox();
this.lbl_start_program = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// cb_dont_start_if_running
@ -44,7 +45,7 @@ namespace DisplayMagician.UIForms
this.cb_dont_start_if_running.AutoSize = true;
this.cb_dont_start_if_running.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.cb_dont_start_if_running.ForeColor = System.Drawing.Color.White;
this.cb_dont_start_if_running.Location = new System.Drawing.Point(135, 97);
this.cb_dont_start_if_running.Location = new System.Drawing.Point(78, 91);
this.cb_dont_start_if_running.Name = "cb_dont_start_if_running";
this.cb_dont_start_if_running.Size = new System.Drawing.Size(289, 24);
this.cb_dont_start_if_running.TabIndex = 26;
@ -57,9 +58,9 @@ namespace DisplayMagician.UIForms
this.txt_start_program.BackColor = System.Drawing.Color.White;
this.txt_start_program.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.txt_start_program.ForeColor = System.Drawing.Color.Black;
this.txt_start_program.Location = new System.Drawing.Point(268, 20);
this.txt_start_program.Location = new System.Drawing.Point(221, 17);
this.txt_start_program.Name = "txt_start_program";
this.txt_start_program.Size = new System.Drawing.Size(535, 26);
this.txt_start_program.Size = new System.Drawing.Size(503, 26);
this.txt_start_program.TabIndex = 25;
//
// cb_start_program_close
@ -67,7 +68,7 @@ namespace DisplayMagician.UIForms
this.cb_start_program_close.AutoSize = true;
this.cb_start_program_close.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.cb_start_program_close.ForeColor = System.Drawing.Color.White;
this.cb_start_program_close.Location = new System.Drawing.Point(515, 97);
this.cb_start_program_close.Location = new System.Drawing.Point(422, 91);
this.cb_start_program_close.Name = "cb_start_program_close";
this.cb_start_program_close.Size = new System.Drawing.Size(398, 24);
this.cb_start_program_close.TabIndex = 24;
@ -77,10 +78,11 @@ namespace DisplayMagician.UIForms
//
// btn_start_program
//
this.btn_start_program.Anchor = System.Windows.Forms.AnchorStyles.None;
this.btn_start_program.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btn_start_program.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.btn_start_program.ForeColor = System.Drawing.Color.White;
this.btn_start_program.Location = new System.Drawing.Point(819, 19);
this.btn_start_program.Location = new System.Drawing.Point(730, 17);
this.btn_start_program.Name = "btn_start_program";
this.btn_start_program.Size = new System.Drawing.Size(85, 27);
this.btn_start_program.TabIndex = 23;
@ -93,9 +95,9 @@ namespace DisplayMagician.UIForms
this.txt_start_program_args.BackColor = System.Drawing.Color.White;
this.txt_start_program_args.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.txt_start_program_args.ForeColor = System.Drawing.Color.Black;
this.txt_start_program_args.Location = new System.Drawing.Point(365, 60);
this.txt_start_program_args.Location = new System.Drawing.Point(309, 56);
this.txt_start_program_args.Name = "txt_start_program_args";
this.txt_start_program_args.Size = new System.Drawing.Size(540, 26);
this.txt_start_program_args.Size = new System.Drawing.Size(506, 26);
this.txt_start_program_args.TabIndex = 22;
//
// cb_start_program_pass_args
@ -103,7 +105,7 @@ namespace DisplayMagician.UIForms
this.cb_start_program_pass_args.AutoSize = true;
this.cb_start_program_pass_args.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.cb_start_program_pass_args.ForeColor = System.Drawing.Color.White;
this.cb_start_program_pass_args.Location = new System.Drawing.Point(135, 62);
this.cb_start_program_pass_args.Location = new System.Drawing.Point(79, 58);
this.cb_start_program_pass_args.Name = "cb_start_program_pass_args";
this.cb_start_program_pass_args.Size = new System.Drawing.Size(228, 24);
this.cb_start_program_pass_args.TabIndex = 21;
@ -114,10 +116,11 @@ namespace DisplayMagician.UIForms
//
// btn_delete
//
this.btn_delete.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.btn_delete.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btn_delete.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.btn_delete.ForeColor = System.Drawing.Color.White;
this.btn_delete.Location = new System.Drawing.Point(933, 3);
this.btn_delete.Location = new System.Drawing.Point(868, 3);
this.btn_delete.Name = "btn_delete";
this.btn_delete.Size = new System.Drawing.Size(29, 27);
this.btn_delete.TabIndex = 27;
@ -127,24 +130,35 @@ namespace DisplayMagician.UIForms
//
// cb_start_program
//
this.cb_start_program.AutoSize = true;
this.cb_start_program.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.cb_start_program.ForeColor = System.Drawing.Color.White;
this.cb_start_program.Location = new System.Drawing.Point(34, 21);
this.cb_start_program.Name = "cb_start_program";
this.cb_start_program.Size = new System.Drawing.Size(222, 24);
this.cb_start_program.TabIndex = 28;
this.cb_start_program.Text = "Start the following program:";
this.cb_start_program.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
this.cb_start_program.UseVisualStyleBackColor = true;
this.cb_start_program.CheckedChanged += new System.EventHandler(this.cb_start_program_CheckedChanged);
this.cb_disable_start_program.AutoSize = true;
this.cb_disable_start_program.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.cb_disable_start_program.ForeColor = System.Drawing.Color.White;
this.cb_disable_start_program.Location = new System.Drawing.Point(78, 121);
this.cb_disable_start_program.Name = "cb_start_program";
this.cb_disable_start_program.Size = new System.Drawing.Size(312, 24);
this.cb_disable_start_program.TabIndex = 28;
this.cb_disable_start_program.Text = "Temporarily disable starting this program";
this.cb_disable_start_program.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
this.cb_disable_start_program.UseVisualStyleBackColor = true;
this.cb_disable_start_program.CheckedChanged += new System.EventHandler(this.cb_start_program_CheckedChanged);
//
// lbl_start_program
//
this.lbl_start_program.AutoSize = true;
this.lbl_start_program.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lbl_start_program.Location = new System.Drawing.Point(75, 19);
this.lbl_start_program.Name = "lbl_start_program";
this.lbl_start_program.Size = new System.Drawing.Size(140, 20);
this.lbl_start_program.TabIndex = 29;
this.lbl_start_program.Text = "Start this program:";
//
// StartProgramControl
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit;
this.AutoSize = true;
this.BackColor = System.Drawing.Color.Black;
this.Controls.Add(this.cb_start_program);
this.Controls.Add(this.lbl_start_program);
this.Controls.Add(this.cb_disable_start_program);
this.Controls.Add(this.btn_delete);
this.Controls.Add(this.cb_dont_start_if_running);
this.Controls.Add(this.txt_start_program);
@ -153,8 +167,9 @@ namespace DisplayMagician.UIForms
this.Controls.Add(this.txt_start_program_args);
this.Controls.Add(this.cb_start_program_pass_args);
this.ForeColor = System.Drawing.Color.White;
this.Margin = new System.Windows.Forms.Padding(10);
this.Name = "StartProgramControl";
this.Size = new System.Drawing.Size(965, 136);
this.Size = new System.Drawing.Size(900, 150);
this.ResumeLayout(false);
this.PerformLayout();
@ -169,6 +184,7 @@ namespace DisplayMagician.UIForms
private System.Windows.Forms.TextBox txt_start_program_args;
private System.Windows.Forms.CheckBox cb_start_program_pass_args;
private System.Windows.Forms.Button btn_delete;
private System.Windows.Forms.CheckBox cb_start_program;
private System.Windows.Forms.CheckBox cb_disable_start_program;
private System.Windows.Forms.Label lbl_start_program;
}
}

View File

@ -48,7 +48,7 @@ namespace DisplayMagician.UIForms
{
// Now populate the controls with the start program data
txt_start_program.Text = myStartProgram.Executable;
cb_start_program.Checked = myStartProgram.Enabled;
cb_disable_start_program.Checked = myStartProgram.Disabled;
cb_start_program_pass_args.Checked = myStartProgram.ExecutableArgumentsRequired;
txt_start_program_args.Text = myStartProgram.Arguments;
cb_start_program_close.Checked = myStartProgram.CloseOnFinish;
@ -64,12 +64,13 @@ namespace DisplayMagician.UIForms
private void cb_start_program_CheckedChanged(object sender, EventArgs e)
{
// Disable the start program 1 fields
if (cb_start_program.Checked)
// Disable the start program fields
if (!cb_disable_start_program.Checked)
{
// Enable the Executable Arguments Text field
txt_start_program.Visible = true;
btn_start_program.Visible = true;
txt_start_program_args.Visible = true;
cb_start_program_pass_args.Visible = true;
cb_start_program_close.Visible = true;
cb_dont_start_if_running.Visible = true;
@ -79,6 +80,7 @@ namespace DisplayMagician.UIForms
// Disable the Executable Arguments Text field
txt_start_program.Visible = false;
btn_start_program.Visible = false;
txt_start_program_args.Visible = false;
cb_start_program_pass_args.Visible = false;
cb_start_program_close.Visible = false;
cb_dont_start_if_running.Visible = false;
@ -123,18 +125,10 @@ namespace DisplayMagician.UIForms
return textToReturn;
}
private void lbl_start_program_Click(object sender, EventArgs e)
{
if (!cb_start_program.Checked)
cb_start_program.CheckState = CheckState.Checked;
else
cb_start_program.CheckState = CheckState.Unchecked;
}
private void btn_delete_Click(object sender, EventArgs e)
{
((ShortcutForm)this.Parent.Parent.Parent.Parent).RemoveStartProgram(this);
//this.Parent.Controls.Remove(this);
}
}

View File

@ -117,4 +117,7 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="$this.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
</root>