auto center labels in launch process dialog

This commit is contained in:
Kang Yu 2023-07-28 12:47:05 -07:00
parent bf2ea276af
commit 4ce7c99e46
4 changed files with 19 additions and 14 deletions

View file

@ -2,6 +2,8 @@
using System.Drawing; using System.Drawing;
using System.Windows.Forms; using System.Windows.Forms;
using PersistentWindows.Common.WinApiBridge;
namespace PersistentWindows.Common namespace PersistentWindows.Common
{ {
public partial class LaunchProcess : Form public partial class LaunchProcess : Form
@ -10,27 +12,33 @@ namespace PersistentWindows.Common
public LaunchProcess(string process, string title) public LaunchProcess(string process, string title)
{ {
User32.SetThreadDpiAwarenessContext(User32.DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
InitializeComponent(); InitializeComponent();
// Creating and setting the label // Creating and setting the label
Label process_name = new Label(); Label process_name = new Label();
process_name.Font = new Font("Calibri", 13); process_name.Font = new Font("Calibri", 13);
process_name.Location = new Point(Math.Max(50, 240 - process.Length * 4), 80);
process_name.AutoSize = true; process_name.AutoSize = true;
process_name.BorderStyle = BorderStyle.Fixed3D; process_name.BorderStyle = BorderStyle.Fixed3D;
process_name.Padding = new Padding(6); process_name.Padding = new Padding(6);
process_name.TextAlign = ContentAlignment.MiddleCenter;
process_name.Text = process; process_name.Text = process;
process_name.Top = 100;
process_name.Left = this.Width / 2 - process_name.PreferredWidth / 2;
//process_name.TextAlign = ContentAlignment.MiddleCenter;
this.Controls.Add(process_name); this.Controls.Add(process_name);
TextBox window_title = new TextBox(); Label window_title = new Label();
window_title.Font = new Font("Calibri", 13); window_title.Font = new Font("Calibri", 13);
window_title.Location = new Point(Math.Max(50, 240 - title.Length * 4), 130); window_title.AutoSize = true;
window_title.Width = Math.Min(400, title.Length * 10); window_title.BorderStyle = BorderStyle.Fixed3D;
window_title.TextAlign = HorizontalAlignment.Center; window_title.Padding = new Padding(6);
window_title.ReadOnly = true;
window_title.Text = title; window_title.Text = title;
window_title.Top = 150;
window_title.Left = this.Width / 2 - window_title.PreferredWidth / 2;
//window_title.TextAlign = ContentAlignment.MiddleCenter;
this.Controls.Add(window_title); this.Controls.Add(window_title);
} }
private void RunProcess_Load(object sender, EventArgs e) private void RunProcess_Load(object sender, EventArgs e)
@ -63,6 +71,5 @@ namespace PersistentWindows.Common
{ {
Button_Click(sender, e); Button_Click(sender, e);
} }
} }
} }

View file

@ -1809,7 +1809,7 @@ namespace PersistentWindows.Common
public string GetDisplayKey() public string GetDisplayKey()
{ {
int result = User32.SetThreadDpiAwarenessContext(User32.DPI_AWARENESS_CONTEXT_UNAWARE); User32.SetThreadDpiAwarenessContext(User32.DPI_AWARENESS_CONTEXT_UNAWARE);
DesktopDisplayMetrics metrics = new DesktopDisplayMetrics(); DesktopDisplayMetrics metrics = new DesktopDisplayMetrics();
metrics.AcquireMetrics(); metrics.AcquireMetrics();
return metrics.Key; return metrics.Key;
@ -1957,7 +1957,7 @@ namespace PersistentWindows.Common
private void CaptureApplicationsOnCurrentDisplays(string displayKey, bool saveToDB = false, bool immediateCapture = false) private void CaptureApplicationsOnCurrentDisplays(string displayKey, bool saveToDB = false, bool immediateCapture = false)
{ {
int result = User32.SetThreadDpiAwarenessContext(User32.DPI_AWARENESS_CONTEXT_UNAWARE); User32.SetThreadDpiAwarenessContext(User32.DPI_AWARENESS_CONTEXT_UNAWARE);
Log.Trace(""); Log.Trace("");
Log.Trace("Capturing windows for display setting {0}", displayKey); Log.Trace("Capturing windows for display setting {0}", displayKey);

View file

@ -35,11 +35,8 @@ namespace PersistentWindows.SystrayShell
Application.EnableVisualStyles(); Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false); Application.SetCompatibleTextRenderingDefault(false);
Console.WriteLine(Environment.Version);
Console.WriteLine(Environment.OSVersion.Platform.ToString());
Console.WriteLine(Environment.OSVersion.VersionString);
Log.Init(); Log.Init();
Log.Event($"OS version {Environment.OSVersion.VersionString}; .NET version {Environment.Version}");
pwp = new PersistentWindowProcessor(); pwp = new PersistentWindowProcessor();

View file

@ -55,6 +55,7 @@
<windowsSettings> <windowsSettings>
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware> <dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
<longPathAware xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">true</longPathAware> <longPathAware xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">true</longPathAware>
<!--<gdiScaling xmlns="http://schemas.microsoft.com/SMI/2017/WindowsSettings">true</gdiScaling>-->
</windowsSettings> </windowsSettings>
</application> </application>