Skip to content

Commit e9badd9

Browse files
authored
[release/8.0] FontStyle.Bold Not Visually Applied to LinkLabel at Runtime 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
2 parents 939d6e0 + d4f21fb commit e9badd9

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewLinkCell.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1009,7 +1009,7 @@ private Rectangle PaintPrivate(Graphics g,
10091009
Font getHoverFont = null;
10101010
bool isActive = (LinkState & LinkState.Active) == LinkState.Active;
10111011

1012-
LinkUtilities.EnsureLinkFonts(cellStyle.Font, LinkBehavior, ref getLinkFont, ref getHoverFont, isActive);
1012+
LinkUtilities.EnsureLinkFonts(cellStyle.Font, LinkBehavior, ref getLinkFont, ref getHoverFont);
10131013
TextFormatFlags flags = DataGridViewUtilities.ComputeTextFormatFlagsForCellStyleAlignment(
10141014
DataGridView.RightToLeftInternal,
10151015
cellStyle.Alignment,
@@ -1088,6 +1088,18 @@ private Rectangle PaintPrivate(Graphics g,
10881088
valBounds,
10891089
linkColor,
10901090
flags);
1091+
1092+
// add a visiting effect.
1093+
if (isActive)
1094+
{
1095+
TextRenderer.DrawText(
1096+
g,
1097+
formattedValueStr,
1098+
LinkState == LinkState.Hover ? hoverFont : linkFont,
1099+
new Rectangle(valBounds.X + 1, valBounds.Y, valBounds.Width, valBounds.Height),
1100+
linkColor,
1101+
flags);
1102+
}
10911103
}
10921104
}
10931105
else if (cellCurrent &&

src/System.Windows.Forms/src/System/Windows/Forms/LinkUtilities.cs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,7 @@ public static void EnsureLinkFonts(
161161
Font baseFont,
162162
LinkBehavior link,
163163
[AllowNull] ref Font linkFont,
164-
[AllowNull] ref Font hoverLinkFont,
165-
bool isActive = false)
164+
[AllowNull] ref Font hoverLinkFont)
166165
{
167166
if (linkFont is not null && hoverLinkFont is not null)
168167
{
@@ -209,15 +208,6 @@ public static void EnsureLinkFonts(
209208
style &= ~FontStyle.Underline;
210209
}
211210

212-
if (isActive)
213-
{
214-
style |= FontStyle.Bold;
215-
}
216-
else
217-
{
218-
style &= ~FontStyle.Bold;
219-
}
220-
221211
hoverLinkFont = new Font(f, style);
222212
linkFont = hoverLinkFont;
223213
}

0 commit comments

Comments
 (0)