mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-05-08 02:34:06 +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.Drawing;
|
||||
using System.Windows.Forms;
|
||||
using TweetDuck.Core.Controls;
|
||||
using TweetDuck.Core.Utils;
|
||||
|
||||
namespace TweetDuck.Core.Other{
|
||||
sealed partial class FormMessage : Form{
|
||||
@ -13,8 +15,13 @@ private int ClientWidth{
|
||||
set => ClientSize = new Size(value, ClientSize.Height);
|
||||
}
|
||||
|
||||
private int ButtonDistance{
|
||||
get => BrowserUtils.Scale(96, dpiScale);
|
||||
}
|
||||
|
||||
private readonly Icon icon;
|
||||
private readonly bool isReady;
|
||||
private readonly float dpiScale;
|
||||
|
||||
private int realFormWidth, minFormWidth;
|
||||
private int buttonCount;
|
||||
@ -24,9 +31,11 @@ private int ClientWidth{
|
||||
public FormMessage(string caption, string text, MessageBoxIcon messageIcon){
|
||||
InitializeComponent();
|
||||
|
||||
this.dpiScale = this.GetDPIScale();
|
||||
|
||||
this.prevLabelWidth = labelMessage.Width;
|
||||
this.prevLabelHeight = labelMessage.Height;
|
||||
this.minFormWidth = 40;
|
||||
this.minFormWidth = BrowserUtils.Scale(40, dpiScale);
|
||||
|
||||
switch(messageIcon){
|
||||
case MessageBoxIcon.Information:
|
||||
@ -66,7 +75,7 @@ public Button AddButton(string title, DialogResult result = DialogResult.OK){
|
||||
Anchor = AnchorStyles.Bottom,
|
||||
Font = SystemFonts.MessageBoxFont,
|
||||
Location = new Point(0, 12),
|
||||
Size = new Size(88, 26),
|
||||
Size = new Size(BrowserUtils.Scale(88, dpiScale), BrowserUtils.Scale(26, dpiScale)),
|
||||
TabIndex = buttonCount,
|
||||
Text = title,
|
||||
UseVisualStyleBackColor = true
|
||||
@ -81,7 +90,7 @@ public Button AddButton(string title, DialogResult result = DialogResult.OK){
|
||||
panelActions.Controls.Add(button);
|
||||
++buttonCount;
|
||||
|
||||
minFormWidth += 96;
|
||||
minFormWidth += ButtonDistance;
|
||||
ClientWidth = Math.Max(realFormWidth, minFormWidth);
|
||||
RecalculateButtonLocation();
|
||||
|
||||
@ -90,15 +99,20 @@ public Button AddButton(string title, DialogResult result = DialogResult.OK){
|
||||
|
||||
public void AddActionControl(Control 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;
|
||||
ClientWidth = Math.Max(realFormWidth, minFormWidth);
|
||||
}
|
||||
|
||||
private void RecalculateButtonLocation(){
|
||||
int dist = ButtonDistance;
|
||||
int start = ClientWidth-dist-BrowserUtils.Scale(1, dpiScale);
|
||||
|
||||
for(int index = 0; index < buttonCount; 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;
|
||||
int labelOffset = BrowserUtils.Scale(8, dpiScale);
|
||||
|
||||
if (isMultiline && !wasLabelMultiline){
|
||||
labelMessage.Location = new Point(labelMessage.Location.X, labelMessage.Location.Y-8);
|
||||
prevLabelHeight += 8;
|
||||
labelMessage.Location = new Point(labelMessage.Location.X, labelMessage.Location.Y-labelOffset);
|
||||
prevLabelHeight += labelOffset;
|
||||
}
|
||||
else if (!isMultiline && wasLabelMultiline){
|
||||
labelMessage.Location = new Point(labelMessage.Location.X, labelMessage.Location.Y+8);
|
||||
prevLabelHeight -= 8;
|
||||
labelMessage.Location = new Point(labelMessage.Location.X, labelMessage.Location.Y+labelOffset);
|
||||
prevLabelHeight -= labelOffset;
|
||||
}
|
||||
|
||||
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){
|
||||
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 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,
|
||||
Enabled = loggedSuccessfully,
|
||||
Font = SystemFonts.MessageBoxFont,
|
||||
Location = new Point(6, 12),
|
||||
Location = new Point(9, 12),
|
||||
Margin = new Padding(0, 0, 48, 0),
|
||||
Size = new Size(88, 26),
|
||||
Size = new Size(106, 26),
|
||||
Text = "Show Error Log",
|
||||
UseVisualStyleBackColor = true
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user