Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/258.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在没有阴影的情况下绘制自己的工具提示?_C#_Winforms_Tooltip - Fatal编程技术网

C# 如何在没有阴影的情况下绘制自己的工具提示?

C# 如何在没有阴影的情况下绘制自己的工具提示?,c#,winforms,tooltip,C#,Winforms,Tooltip,我正在尝试绘制自己的工具提示。但我无法摆脱标准阴影 Application.EnableVisualStyles(); 它是一个标准的WinForm应用程序,有很多表单。因此也是如此 Application.EnableVisualStyles(); 在应用程序启动时调用和需要。如果我把这行注释掉,它就行了。我在下面制作了一个最小的WinForm应用程序。如果EnableVisualStyles被注释掉,它只会绘制一个红色矩形。当我取消注释它时,它会绘制一个带阴影的红色矩形 Appli

我正在尝试绘制自己的工具提示。但我无法摆脱标准阴影

 Application.EnableVisualStyles();
它是一个标准的WinForm应用程序,有很多表单。因此也是如此

 Application.EnableVisualStyles();
在应用程序启动时调用和需要。如果我把这行注释掉,它就行了。我在下面制作了一个最小的WinForm应用程序。如果EnableVisualStyles被注释掉,它只会绘制一个红色矩形。当我取消注释它时,它会绘制一个带阴影的红色矩形

 Application.EnableVisualStyles();
有人知道怎么解决这个问题吗?如何让Application.EnableVisualStyles()和工具提示100%所有者绘制,而不使用任何标准阴影

 Application.EnableVisualStyles();

 Application.EnableVisualStyles();

 Application.EnableVisualStyles();
最小WinForm应用程序位于此处:

 Application.EnableVisualStyles();
using System;
using System.Drawing;
using System.Windows.Forms;

namespace ToolTipExample
{
  public class MainForm : Form
  {
      [STAThread]
      static void Main()
      {
          // Comment out below line and it works.
          Application.EnableVisualStyles();
          Application.Run(new MainForm());
      }

      private ToolTip toolTip;
      private Button button;

      public MainForm()
      {
          toolTip = new ToolTip();
          toolTip.OwnerDraw = true;
          toolTip.Draw += new DrawToolTipEventHandler(toolTip1_Draw);
          toolTip.Popup += new PopupEventHandler(toolTip1_Popup);

          button = new Button();
          button.Location = new Point(25, 25);
          button.Text = "Button";

          toolTip.SetToolTip(button, "Button tip text");

          Controls.AddRange(new Control[] { button });
      }

      private void toolTip1_Popup(object sender, PopupEventArgs e)
      {
          e.ToolTipSize = new Size(100, 100);
      }

      private void toolTip1_Draw(System.Object sender, DrawToolTipEventArgs e)
      {
          e.Graphics.FillRectangle(new SolidBrush(Color.Red), e.Bounds);
      }
  }
}

您可以使用
GetClassLong
获取
工具提示的类样式,然后从中删除
CS\u DROPSHADOW
样式,并再次设置
工具提示的类样式:

 Application.EnableVisualStyles();
//using System.Runtime.InteropServices;

public const int GCL_STYLE = -26;
public const int CS_DROPSHADOW = 0x20000;

[DllImport("user32.dll", EntryPoint = "GetClassLong")]
public static extern int GetClassLong(IntPtr hWnd, int nIndex);
[DllImport("user32.dll", EntryPoint = "SetClassLong")]
public static extern int SetClassLong(IntPtr hWnd, int nIndex, int dwNewLong);

private void toolTip1_Popup(object sender, PopupEventArgs e) 
{
    e.ToolTipSize = new Size(100, 100);
    var hwnd = (IntPtr)typeof(ToolTip).GetProperty("Handle",
        System.Reflection.BindingFlags.NonPublic |
        System.Reflection.BindingFlags.Instance).GetValue(toolTip);
    var cs = GetClassLong(hwnd, GCL_STYLE);
    if ((cs & CS_DROPSHADOW) == CS_DROPSHADOW)
    {
        cs = cs & ~CS_DROPSHADOW;
        SetClassLong(hwnd, GCL_STYLE, cs);
    }
}

. 从实现中派生出的草稿:a)获取内部(“TT…”)工具提示主机窗口的hWnd b)调用
GetClassLongPtr32
about
GCL\u样式
如果它具有
CS\u DROPSHADOW
样式,那么c)调用
SetClassLongPtr32
about
GCL\u样式
,原版风格减去CS_DROPSHADOW标志位。相关:太好了,谢谢!也谢谢你的链接。当我在谷歌上搜索时,我从来没有在搜索结果中看到过这些。谢谢!使用上面的代码就可以立即工作!我希望微软有时能对.Net WinForms控件进行重大更新,并解决所有类似的细节。嗯,我希望他们有这样的计划。无论如何,不客气:)