Refactor the individual window panel into a separate form

This commit is contained in:
2025-08-31 20:27:45 +02:00
parent f234279135
commit 1f314d5c4b
5 changed files with 320 additions and 73 deletions

View File

@@ -76,82 +76,20 @@ namespace DD2Switcher {
if (window == null)
continue;
var windowPanel = CreateWindowPanel(i, window);
windowsPanel.Controls.Add(windowPanel);
var windowPanelForm = new WindowPanelForm();
windowPanelForm.WindowIndex = i;
windowPanelForm.WindowProcess = window;
windowPanelForm.IsFirst = (i == firstIndex);
windowPanelForm.IsLast = (i == lastIndex);
windowPanelForm.UpdateDisplay();
windowPanelForm.PickClicked += (sender, index) => PickButton_Click(sender, new EventArgs());
windowPanelForm.UntrackClicked += (sender, index) => UntrackButton_Click(sender, new EventArgs());
windowsPanel.Controls.Add(windowPanelForm);
}
}
private Panel CreateWindowPanel(int index, Process window) {
var panel = new Panel();
panel.Width = 520;
panel.Height = 80;
panel.BorderStyle = BorderStyle.FixedSingle;
panel.Margin = new Padding(5);
panel.BackColor = Color.LightGray;
// Index label
var indexLabel = new Label();
indexLabel.Text = $"Index: {index}";
indexLabel.Location = new Point(10, 5);
indexLabel.AutoSize = true;
indexLabel.Font = new Font("Segoe UI", 9F, FontStyle.Bold);
panel.Controls.Add(indexLabel);
// Process name
var nameLabel = new Label();
nameLabel.Text = $"Name: {window.ProcessName}";
nameLabel.Location = new Point(10, 25);
nameLabel.AutoSize = true;
nameLabel.Font = new Font("Segoe UI", 9F);
panel.Controls.Add(nameLabel);
// PID
var pidLabel = new Label();
pidLabel.Text = $"PID: {window.Id}";
pidLabel.Location = new Point(10, 45);
pidLabel.AutoSize = true;
pidLabel.Font = new Font("Segoe UI", 9F);
panel.Controls.Add(pidLabel);
// Window title
var titleLabel = new Label();
titleLabel.Text = $"Title: {window.MainWindowTitle}";
titleLabel.Location = new Point(200, 25);
titleLabel.AutoSize = true;
titleLabel.Font = new Font("Segoe UI", 9F);
titleLabel.MaximumSize = new Size(200, 0);
panel.Controls.Add(titleLabel);
// First/Last indicator
var firstLastLabel = new Label();
firstLastLabel.Text = GetFirstLastText(index);
firstLastLabel.Location = new Point(200, 45);
firstLastLabel.AutoSize = true;
firstLastLabel.Font = new Font("Segoe UI", 9F, FontStyle.Bold);
firstLastLabel.ForeColor = Color.DarkBlue;
panel.Controls.Add(firstLastLabel);
// Pick button
var pickButton = new Button();
pickButton.Text = "Pick";
pickButton.Location = new Point(420, 10);
pickButton.Size = new Size(50, 25);
pickButton.Tag = index;
pickButton.Click += PickButton_Click;
panel.Controls.Add(pickButton);
// Untrack button
var untrackButton = new Button();
untrackButton.Text = "Untrack";
untrackButton.Location = new Point(420, 45);
untrackButton.Size = new Size(50, 25);
untrackButton.Tag = index;
untrackButton.Click += UntrackButton_Click;
panel.Controls.Add(untrackButton);
return panel;
}
private string GetFirstLastText(int index) {
if (index == firstIndex && index == lastIndex) {
return "First & Last";