Skip to content

Commit

Permalink
fix #12358 [HDPI] The "document" text in the “Generating Previews” di…
Browse files Browse the repository at this point in the history
…alog is truncated at >200% DPI (#12363)
  • Loading branch information
Epica3055 authored Dec 18, 2024
1 parent af50c4b commit 7fb0606
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Drawing;

namespace System.Windows.Forms;

internal class FocusableLabel : Label
{
public bool UnderlineWhenFocused { get; set; } = true;

public FocusableLabel()
{
SetStyle(ControlStyles.Selectable, true);
TabStop = true;
}

protected override CreateParams CreateParams
{
get
{
CreateParams createParams = base.CreateParams;
createParams.ClassName = null;
return createParams;
}
}

protected override void OnClick(EventArgs e)
{
base.OnClick(e);

if (UnderlineWhenFocused)
{
Focus();
}
}

protected override void OnGotFocus(EventArgs e)
{
if (UnderlineWhenFocused)
{
Font = new Font(Font, FontStyle.Underline);
}

base.OnGotFocus(e);
}

protected override void OnLostFocus(EventArgs e)
{
if (UnderlineWhenFocused)
{
Font = new Font(Font, FontStyle.Regular);
}

base.OnLostFocus(e);
}

internal override bool SupportsUiaProviders => false;
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ private void Run()
private void ThreadUnsafeUpdateLabel()
{
// "page {0} of {1}"
_dialog!._cancellingTextBox.Text = string.Format(
_dialog!._messageLabel.Text = string.Format(
SR.PrintControllerWithStatusDialog_NowPrinting,
_parent._pageNumber,
_parent._document?.DocumentName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.Drawing;
using Windows.Win32.System.Variant;
using Windows.Win32.UI.Accessibility;

namespace System.Windows.Forms;

public partial class PrintControllerWithStatusDialog
{
private partial class StatusDialog : Form
{
internal TextBox _cancellingTextBox;
internal FocusableLabel _messageLabel;
private Button _cancelButton;
private TableLayoutPanel? _tableLayoutPanel;
private readonly BackgroundThread _backgroundThread;
Expand All @@ -24,7 +22,7 @@ internal StatusDialog(BackgroundThread backgroundThread, string dialogTitle)
MinimumSize = Size;
}

[MemberNotNull(nameof(_cancellingTextBox))]
[MemberNotNull(nameof(_messageLabel))]
[MemberNotNull(nameof(_cancelButton))]
private void InitializeComponent()
{
Expand All @@ -34,24 +32,19 @@ private void InitializeComponent()
RightToLeft = RightToLeft.Yes;
}

_cancellingTextBox = new TextBox()
_messageLabel = new FocusableLabel()
{
AutoSize = true,
Location = new Point(8, 16),
BorderStyle = BorderStyle.None,
ReadOnly = true,
TextAlign = HorizontalAlignment.Center,
TextAlign = ContentAlignment.MiddleCenter,
Size = new Size(240, 64),
TabIndex = 1,
Anchor = AnchorStyles.None
Anchor = AnchorStyles.None,
};

_cancellingTextBox.TextChanged += OnCancellingTextBoxTextChanged;

_cancelButton = new Button()
{
AutoSize = true,
Size = new Size(75, 23),
Size = ScaleHelper.ScaleToDpi(new Size(75, 23), ScaleHelper.InitialSystemDpi),
TabIndex = 0,
Text = SR.PrintControllerWithStatusDialog_Cancel,
Location = new Point(88, 88),
Expand All @@ -73,7 +66,7 @@ private void InitializeComponent()
_tableLayoutPanel.ColumnStyles.Add(new(SizeType.Percent, 100F));
_tableLayoutPanel.RowStyles.Add(new(SizeType.Percent, 50F));
_tableLayoutPanel.RowStyles.Add(new(SizeType.Percent, 50F));
_tableLayoutPanel.Controls.Add(_cancellingTextBox, 0, 0);
_tableLayoutPanel.Controls.Add(_messageLabel, 0, 0);
_tableLayoutPanel.Controls.Add(_cancelButton, 0, 1);

AutoScaleDimensions = new Size(6, 13);
Expand All @@ -91,22 +84,10 @@ private void InitializeComponent()
private void CancelClick(object? sender, EventArgs e)
{
_cancelButton.Enabled = false;
_cancellingTextBox.Text = SR.PrintControllerWithStatusDialog_Canceling;
_messageLabel.Text = SR.PrintControllerWithStatusDialog_Canceling;
_backgroundThread._canceled = true;
}

protected override AccessibleObject CreateAccessibilityInstance() => new StatusDialogAccessibility(this);

private void OnCancellingTextBoxTextChanged(object? sender, EventArgs e)
{
if (!_cancellingTextBox.IsAccessibilityObjectCreated)
{
return;
}

using var textVariant = (VARIANT)_cancellingTextBox.Text;
_cancellingTextBox.AccessibilityObject?.RaiseAutomationEvent(UIA_EVENT_ID.UIA_Text_TextChangedEventId);
_cancellingTextBox.AccessibilityObject?.RaiseAutomationPropertyChangedEvent(UIA_PROPERTY_ID.UIA_NamePropertyId, textVariant, textVariant);
}
}
}

0 comments on commit 7fb0606

Please sign in to comment.