Skip to content

fix #13677 FontStyle.Bold Not Visually Applied to LinkLabel at Runtime via Code #13681

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 15, 2025

Conversation

Epica3055
Copy link
Member

@Epica3055 Epica3055 commented Jul 7, 2025

Fixes #13677

Root cause

This issue was introduced by PR6250 to fix Issue6116

This is one of it's changes.
image

The new parameter isActive is to address DataGridViewLinkCell issue, but it also break other cases.

Proposed changes

  • make it bold by painting it again

Regression?

  • Yes

Screenshots

Before

Image

After

13677_01

Microsoft Reviewers: Open in CodeFlow

Copy link

codecov bot commented Jul 7, 2025

Codecov Report

Attention: Patch coverage is 9.09091% with 10 lines in your changes missing coverage. Please review.

Project coverage is 76.75799%. Comparing base (285f3b4) to head (49cd1c7).
Report is 25 commits behind head on main.

Additional details and impacted files
@@                 Coverage Diff                  @@
##                main      #13681          +/-   ##
====================================================
- Coverage   97.41503%   76.75799%   -20.65704%     
====================================================
  Files           1192        3256        +2064     
  Lines         353853      642010      +288157     
  Branches        5435       47549       +42114     
====================================================
+ Hits          344706      492794      +148088     
- Misses          8378      145554      +137176     
- Partials         769        3662        +2893     
Flag Coverage Δ
Debug 76.75799% <9.09091%> (-20.65704%) ⬇️
integration 18.99435% <0.00000%> (?)
production 51.32440% <9.09091%> (?)
test 97.41712% <ø> (+0.00208%) ⬆️
unit 48.73051% <9.09091%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@LeafShi1 LeafShi1 requested a review from Copilot July 7, 2025 09:20
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR addresses issue #13677 by restoring the visual Bold style on LinkLabel when set via code by making the isActive parameter nullable and only applying bold adjustments when it is explicitly true or false.

  • Changed EnsureLinkFonts signature to accept bool? isActive instead of bool
  • Updated conditional logic to only modify FontStyle.Bold when isActive is non-null
Comments suppressed due to low confidence (2)

src/System.Windows.Forms/System/Windows/Forms/Controls/Labels/LinkUtilities.cs:167

  • Changing a public method’s signature from bool to bool? is a breaking API change. Consider adding an overload to preserve backward compatibility or document this change in the public API surface.
        bool? isActive = null)

src/System.Windows.Forms/System/Windows/Forms/Controls/Labels/LinkUtilities.cs:167

  • There don’t appear to be unit tests covering the new null case for isActive. Add tests to verify that leaving isActive as null does not alter the existing default styling behavior.
        bool? isActive = null)

LeafShi1
LeafShi1 previously approved these changes Jul 7, 2025
Copy link
Member

@LeafShi1 LeafShi1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@LeafShi1 LeafShi1 requested a review from KlausLoeffelmann July 8, 2025 00:39
@LeafShi1 LeafShi1 added priority-1 Work that is critical for the release, but we could probably ship without waiting-review This item is waiting on review by one or more members of team labels Jul 8, 2025
Copy link
Member

@KlausLoeffelmann KlausLoeffelmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks good to me. @LeafShi1 - I have a few thoughts, but really minor just to make sure we're on the safe side:

Maybe we want @Olina-Zhang have this tested also visually in High Contrast scenarios? Depending on how selection colors are applied, we could consider drawing the offset in the system’s SelectionForeColor (or even a semitransparent black/white shadow) rather than the link color itself, just to guarantee enough contrast under every A11Y theme. But this is only to make it perfect. Let's see, how it really looks, and for now, let's get it in quickly, and then IF we would need to do something, we do that later, in addition.

Disposal sanity check: Let's make sure that the getLinkFont / getHoverFont fields still get disposed when the cell/style gets torn down. (But this is just in case: since you haven’t changed that lifecycle, it should be fine, I assume.)

Nice job, thanks!

(I approve, to not block anything. Feel free to approve yourselves again, should you need to do additional changes, so we have the LinkLabel fix in quick - and then if necessary for additional A11Y scenarios, we do a follow up. @merriemcgaw FYI.)

@KlausLoeffelmann
Copy link
Member

@leaf, I usually wouldn't hit merge myself, but I want this in to have further testing.
So, I am going to merge myself - hope it's OK with you!

@KlausLoeffelmann KlausLoeffelmann merged commit 6dd129e into dotnet:main Jul 15, 2025
8 checks passed
@dotnet-policy-service dotnet-policy-service bot removed the waiting-review This item is waiting on review by one or more members of team label Jul 15, 2025
@artl93 artl93 added the servicing-approved .NET Shiproom approved the PR for merge label Jul 15, 2025
@LeafShi1
Copy link
Member

/backport to release/9.0

Copy link
Contributor

Started backporting to release/9.0: https://github.com/dotnet/winforms/actions/runs/16307848441

@LeafShi1
Copy link
Member

/backport to release/8.0

Copy link
Contributor

Started backporting to release/8.0: https://github.com/dotnet/winforms/actions/runs/16307852902

Copy link
Contributor

@LeafShi1 backporting to release/9.0 failed, the patch most likely resulted in conflicts:

$ git am --3way --ignore-whitespace --keep-non-patch changes.patch

Applying: fix #13677 FontStyle.Bold Not Visually Applied to LinkLabel at Runtime via Code
Using index info to reconstruct a base tree...
A	src/System.Windows.Forms/System/Windows/Forms/Controls/Labels/LinkUtilities.cs
Falling back to patching base and 3-way merge...
Auto-merging src/System.Windows.Forms/src/System/Windows/Forms/Controls/Labels/LinkUtilities.cs
Applying: Update LinkUtilities.cs
Using index info to reconstruct a base tree...
A	src/System.Windows.Forms/System/Windows/Forms/Controls/Labels/LinkUtilities.cs
Falling back to patching base and 3-way merge...
Auto-merging src/System.Windows.Forms/src/System/Windows/Forms/Controls/Labels/LinkUtilities.cs
Applying: Update LinkUtilities.cs
Using index info to reconstruct a base tree...
A	src/System.Windows.Forms/System/Windows/Forms/Controls/Labels/LinkUtilities.cs
Falling back to patching base and 3-way merge...
Auto-merging src/System.Windows.Forms/src/System/Windows/Forms/Controls/Labels/LinkUtilities.cs
Applying: use another approach
Using index info to reconstruct a base tree...
A	src/System.Windows.Forms/System/Windows/Forms/Controls/DataGridView/DataGridViewLinkCell.cs
A	src/System.Windows.Forms/System/Windows/Forms/Controls/Labels/LinkUtilities.cs
Falling back to patching base and 3-way merge...
Auto-merging src/System.Windows.Forms/src/System/Windows/Forms/Controls/DataGridView/DataGridViewLinkCell.cs
CONFLICT (content): Merge conflict in src/System.Windows.Forms/src/System/Windows/Forms/Controls/DataGridView/DataGridViewLinkCell.cs
Auto-merging src/System.Windows.Forms/src/System/Windows/Forms/Controls/Labels/LinkUtilities.cs
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Patch failed at 0004 use another approach
Error: The process '/usr/bin/git' failed with exit code 128

Please backport manually!

Copy link
Contributor

@LeafShi1 backporting to release/8.0 failed, the patch most likely resulted in conflicts:

$ git am --3way --ignore-whitespace --keep-non-patch changes.patch

Applying: fix #13677 FontStyle.Bold Not Visually Applied to LinkLabel at Runtime via Code
Using index info to reconstruct a base tree...
A	src/System.Windows.Forms/System/Windows/Forms/Controls/Labels/LinkUtilities.cs
Falling back to patching base and 3-way merge...
Auto-merging src/System.Windows.Forms/src/System/Windows/Forms/LinkUtilities.cs
Applying: Update LinkUtilities.cs
Using index info to reconstruct a base tree...
A	src/System.Windows.Forms/System/Windows/Forms/Controls/Labels/LinkUtilities.cs
Falling back to patching base and 3-way merge...
Auto-merging src/System.Windows.Forms/src/System/Windows/Forms/LinkUtilities.cs
Applying: Update LinkUtilities.cs
Using index info to reconstruct a base tree...
A	src/System.Windows.Forms/System/Windows/Forms/Controls/Labels/LinkUtilities.cs
Falling back to patching base and 3-way merge...
Auto-merging src/System.Windows.Forms/src/System/Windows/Forms/LinkUtilities.cs
Applying: use another approach
Using index info to reconstruct a base tree...
A	src/System.Windows.Forms/System/Windows/Forms/Controls/DataGridView/DataGridViewLinkCell.cs
A	src/System.Windows.Forms/System/Windows/Forms/Controls/Labels/LinkUtilities.cs
Falling back to patching base and 3-way merge...
Auto-merging src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewLinkCell.cs
CONFLICT (content): Merge conflict in src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewLinkCell.cs
Auto-merging src/System.Windows.Forms/src/System/Windows/Forms/LinkUtilities.cs
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Patch failed at 0004 use another approach
Error: The process '/usr/bin/git' failed with exit code 128

Please backport manually!

LeafShi1 added a commit that referenced this pull request Jul 16, 2025
…time via Code (#13702)

<!-- Please read CONTRIBUTING.md before submitting a pull request -->

Backport of #13681 to release/8.0

Fixes #13677


## Proposed changes

- Modified the signature of the `EnsureLinkFonts ` method, removed the
bool `isActive ` parameter, and adjusted the related conditional logic
and updated the text rendering method of **LinkLabel** in the Active
state, by moving the text 1 pixel to the right to achieve a bold effect.

<!-- We are in TELL-MODE the following section must be completed -->

## Customer Impact

- Allows users to correctly set the **LinkLabel** control to a bold font
through `FontStyle.Bold` at runtime

## Regression? 

- Yes, introduced in #6250

## Risk

- Low

<!-- end TELL-MODE -->


## Test methodology <!-- How did you ensure quality? -->

- Manual testing
LeafShi1 added a commit that referenced this pull request Jul 16, 2025
…time via Code (#13703)

<!-- Please read CONTRIBUTING.md before submitting a pull request -->

Backport of #13681 to release/9.0

Fixes #13677


## Proposed changes

- Modified the signature of the `EnsureLinkFonts ` method, removed the
bool `isActive ` parameter, and adjusted the related conditional logic
and updated the text rendering method of **LinkLabel** in the Active
state, by moving the text 1 pixel to the right to achieve a bold effect.

<!-- We are in TELL-MODE the following section must be completed -->

## Customer Impact

- Allows users to correctly set the **LinkLabel** control to a bold font
through `FontStyle.Bold` at runtime

## Regression? 

- Yes, introduced in #6250

## Risk

- Low

<!-- end TELL-MODE -->


## Test methodology <!-- How did you ensure quality? -->

- Manual testing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority-1 Work that is critical for the release, but we could probably ship without servicing-approved .NET Shiproom approved the PR for merge
Projects
None yet
5 participants