Skip to content
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

Style ToolTip to make it dark enough in Dark mode #12420

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,13 @@ private unsafe void CreateHandle()
{
PInvoke.SetWindowTheme(HWND, string.Empty, string.Empty);
}

#pragma warning disable WFO5001
if (Application.IsDarkModeEnabled)
willibrandon marked this conversation as resolved.
Show resolved Hide resolved
{
PInvoke.SetWindowTheme(HWND, string.Empty, string.Empty);
}
#pragma warning restore WFO5001
}

// If in OwnerDraw mode, we don't want the default border.
Expand Down Expand Up @@ -770,15 +777,11 @@ private unsafe void CreateHandle()
// Set active status.
PInvokeCore.SendMessage(this, PInvoke.TTM_ACTIVATE, (WPARAM)(BOOL)_active);

if (BackColor != SystemColors.Info)
{
PInvokeCore.SendMessage(this, PInvoke.TTM_SETTIPBKCOLOR, (WPARAM)BackColor);
}
// Set background color.
PInvokeCore.SendMessage(this, PInvoke.TTM_SETTIPBKCOLOR, (WPARAM)_backColor);

if (ForeColor != SystemColors.InfoText)
{
PInvokeCore.SendMessage(this, PInvoke.TTM_SETTIPTEXTCOLOR, (WPARAM)ForeColor);
}
// Set text color.
PInvokeCore.SendMessage(this, PInvoke.TTM_SETTIPTEXTCOLOR, (WPARAM)_foreColor);

if (_toolTipIcon > 0 || !string.IsNullOrEmpty(_toolTipTitle))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,36 @@ public void ToolTip_ToString_Invoke_ReturnsExpected()
Assert.Equal("System.Windows.Forms.ToolTip InitialDelay: 500, ShowAlways: False", toolTip.ToString());
}

#pragma warning disable WFO5001
[WinFormsFact]
public void ToolTip_DarkMode_GetColors_ReturnsExpected()
{
if (SystemInformation.HighContrast)
{
// We don't run this test in HighContrast mode.
return;
}

SystemColorMode colorMode = Application.ColorMode;
Application.SetColorMode(SystemColorMode.Dark);

using SubToolTip toolTip = new();

Assert.NotEqual(IntPtr.Zero, toolTip.Handle); // A workaround to create the toolTip native window Handle
willibrandon marked this conversation as resolved.
Show resolved Hide resolved

var backgroundColor = PInvokeCore.SendMessage(toolTip, PInvoke.TTM_GETTIPBKCOLOR);
Color backColor = ColorTranslator.FromWin32((int)backgroundColor);

var textColor = PInvokeCore.SendMessage(toolTip, PInvoke.TTM_GETTIPTEXTCOLOR);
Color foreColor = ColorTranslator.FromWin32((int)textColor);

Assert.Equal(SystemColors.Info.ToArgb(), backColor.ToArgb());
Assert.Equal(SystemColors.InfoText.ToArgb(), foreColor.ToArgb());

Application.SetColorMode(colorMode);
willibrandon marked this conversation as resolved.
Show resolved Hide resolved
}
#pragma warning restore WFO5001

[WinFormsFact]
public void ToolTip_SetToolTipToControl_Invokes_SetToolTip_OfControl()
{
Expand Down