mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-05-21 05:34:10 +02:00
Fix FormMessage not scaling well with high DPI
This commit is contained in:
parent
a714f3480a
commit
a7124e5449
@ -1,6 +1,8 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
using TweetDuck.Core.Controls;
|
||||||
|
using TweetDuck.Core.Utils;
|
||||||
|
|
||||||
namespace TweetDuck.Core.Other{
|
namespace TweetDuck.Core.Other{
|
||||||
sealed partial class FormMessage : Form{
|
sealed partial class FormMessage : Form{
|
||||||
@ -13,8 +15,13 @@ private int ClientWidth{
|
|||||||
set => ClientSize = new Size(value, ClientSize.Height);
|
set => ClientSize = new Size(value, ClientSize.Height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int ButtonDistance{
|
||||||
|
get => BrowserUtils.Scale(96, dpiScale);
|
||||||
|
}
|
||||||
|
|
||||||
private readonly Icon icon;
|
private readonly Icon icon;
|
||||||
private readonly bool isReady;
|
private readonly bool isReady;
|
||||||
|
private readonly float dpiScale;
|
||||||
|
|
||||||
private int realFormWidth, minFormWidth;
|
private int realFormWidth, minFormWidth;
|
||||||
private int buttonCount;
|
private int buttonCount;
|
||||||
@ -24,9 +31,11 @@ private int ClientWidth{
|
|||||||
public FormMessage(string caption, string text, MessageBoxIcon messageIcon){
|
public FormMessage(string caption, string text, MessageBoxIcon messageIcon){
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
|
this.dpiScale = this.GetDPIScale();
|
||||||
|
|
||||||
this.prevLabelWidth = labelMessage.Width;
|
this.prevLabelWidth = labelMessage.Width;
|
||||||
this.prevLabelHeight = labelMessage.Height;
|
this.prevLabelHeight = labelMessage.Height;
|
||||||
this.minFormWidth = 40;
|
this.minFormWidth = BrowserUtils.Scale(40, dpiScale);
|
||||||
|
|
||||||
switch(messageIcon){
|
switch(messageIcon){
|
||||||
case MessageBoxIcon.Information:
|
case MessageBoxIcon.Information:
|
||||||
@ -66,7 +75,7 @@ public Button AddButton(string title, DialogResult result = DialogResult.OK){
|
|||||||
Anchor = AnchorStyles.Bottom,
|
Anchor = AnchorStyles.Bottom,
|
||||||
Font = SystemFonts.MessageBoxFont,
|
Font = SystemFonts.MessageBoxFont,
|
||||||
Location = new Point(0, 12),
|
Location = new Point(0, 12),
|
||||||
Size = new Size(88, 26),
|
Size = new Size(BrowserUtils.Scale(88, dpiScale), BrowserUtils.Scale(26, dpiScale)),
|
||||||
TabIndex = buttonCount,
|
TabIndex = buttonCount,
|
||||||
Text = title,
|
Text = title,
|
||||||
UseVisualStyleBackColor = true
|
UseVisualStyleBackColor = true
|
||||||
@ -81,7 +90,7 @@ public Button AddButton(string title, DialogResult result = DialogResult.OK){
|
|||||||
panelActions.Controls.Add(button);
|
panelActions.Controls.Add(button);
|
||||||
++buttonCount;
|
++buttonCount;
|
||||||
|
|
||||||
minFormWidth += 96;
|
minFormWidth += ButtonDistance;
|
||||||
ClientWidth = Math.Max(realFormWidth, minFormWidth);
|
ClientWidth = Math.Max(realFormWidth, minFormWidth);
|
||||||
RecalculateButtonLocation();
|
RecalculateButtonLocation();
|
||||||
|
|
||||||
@ -90,15 +99,20 @@ public Button AddButton(string title, DialogResult result = DialogResult.OK){
|
|||||||
|
|
||||||
public void AddActionControl(Control control){
|
public void AddActionControl(Control control){
|
||||||
panelActions.Controls.Add(control);
|
panelActions.Controls.Add(control);
|
||||||
|
|
||||||
|
control.Size = new Size(BrowserUtils.Scale(control.Width, dpiScale), BrowserUtils.Scale(control.Height, dpiScale));
|
||||||
|
|
||||||
minFormWidth += control.Width+control.Margin.Horizontal;
|
minFormWidth += control.Width+control.Margin.Horizontal;
|
||||||
ClientWidth = Math.Max(realFormWidth, minFormWidth);
|
ClientWidth = Math.Max(realFormWidth, minFormWidth);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RecalculateButtonLocation(){
|
private void RecalculateButtonLocation(){
|
||||||
|
int dist = ButtonDistance;
|
||||||
|
int start = ClientWidth-dist-BrowserUtils.Scale(1, dpiScale);
|
||||||
|
|
||||||
for(int index = 0; index < buttonCount; index++){
|
for(int index = 0; index < buttonCount; index++){
|
||||||
Control control = panelActions.Controls[index];
|
Control control = panelActions.Controls[index];
|
||||||
control.Location = new Point(ClientWidth-97-index*96, control.Location.Y);
|
control.Location = new Point(start-index*dist, control.Location.Y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,14 +122,15 @@ private void labelMessage_SizeChanged(object sender, EventArgs e){
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool isMultiline = labelMessage.Height > labelMessage.MinimumSize.Height;
|
bool isMultiline = labelMessage.Height > labelMessage.MinimumSize.Height;
|
||||||
|
int labelOffset = BrowserUtils.Scale(8, dpiScale);
|
||||||
|
|
||||||
if (isMultiline && !wasLabelMultiline){
|
if (isMultiline && !wasLabelMultiline){
|
||||||
labelMessage.Location = new Point(labelMessage.Location.X, labelMessage.Location.Y-8);
|
labelMessage.Location = new Point(labelMessage.Location.X, labelMessage.Location.Y-labelOffset);
|
||||||
prevLabelHeight += 8;
|
prevLabelHeight += labelOffset;
|
||||||
}
|
}
|
||||||
else if (!isMultiline && wasLabelMultiline){
|
else if (!isMultiline && wasLabelMultiline){
|
||||||
labelMessage.Location = new Point(labelMessage.Location.X, labelMessage.Location.Y+8);
|
labelMessage.Location = new Point(labelMessage.Location.X, labelMessage.Location.Y+labelOffset);
|
||||||
prevLabelHeight -= 8;
|
prevLabelHeight -= labelOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
realFormWidth = ClientWidth-(icon == null ? 50 : 0)+labelMessage.Width-prevLabelWidth;
|
realFormWidth = ClientWidth-(icon == null ? 50 : 0)+labelMessage.Width-prevLabelWidth;
|
||||||
|
@ -46,7 +46,7 @@ public bool Log(string data){
|
|||||||
public void HandleException(string caption, string message, bool canIgnore, Exception e){
|
public void HandleException(string caption, string message, bool canIgnore, Exception e){
|
||||||
bool loggedSuccessfully = Log(e.ToString());
|
bool loggedSuccessfully = Log(e.ToString());
|
||||||
|
|
||||||
FormMessage form = new FormMessage(caption, message+"\r\nError: "+e.Message, canIgnore ? MessageBoxIcon.Warning : MessageBoxIcon.Error);
|
FormMessage form = new FormMessage(caption, message+Environment.NewLine+"Error: "+e.Message, canIgnore ? MessageBoxIcon.Warning : MessageBoxIcon.Error);
|
||||||
|
|
||||||
Button btnExit = form.AddButton("Exit");
|
Button btnExit = form.AddButton("Exit");
|
||||||
Button btnIgnore = form.AddButton("Ignore", DialogResult.Ignore);
|
Button btnIgnore = form.AddButton("Ignore", DialogResult.Ignore);
|
||||||
@ -59,9 +59,9 @@ public void HandleException(string caption, string message, bool canIgnore, Exce
|
|||||||
Anchor = AnchorStyles.Bottom | AnchorStyles.Left,
|
Anchor = AnchorStyles.Bottom | AnchorStyles.Left,
|
||||||
Enabled = loggedSuccessfully,
|
Enabled = loggedSuccessfully,
|
||||||
Font = SystemFonts.MessageBoxFont,
|
Font = SystemFonts.MessageBoxFont,
|
||||||
Location = new Point(6, 12),
|
Location = new Point(9, 12),
|
||||||
Margin = new Padding(0, 0, 48, 0),
|
Margin = new Padding(0, 0, 48, 0),
|
||||||
Size = new Size(88, 26),
|
Size = new Size(106, 26),
|
||||||
Text = "Show Error Log",
|
Text = "Show Error Log",
|
||||||
UseVisualStyleBackColor = true
|
UseVisualStyleBackColor = true
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user