日期:2014-05-18  浏览次数:20938 次

c# winform tooltip显示问题
win7 32位 旗舰版下 tooltip背景色无效 求解释。

------解决方案--------------------
首先设置tooltip控件的OwnerDraw属性为True(由用户自己来绘制,不使用系统绘制)
然后在tooltip的Draw事件下加入自绘制代码,下面五行

Graphics g = e.Graphics;
g.FillRectangle(new SolidBrush(this.toolTip1.BackColor), g.ClipBounds);
e.Graphics.DrawLines(SystemPens.ControlLightLight, new Point[] { new Point(0, e.Bounds.Height - 1), new Point(0, 0), new Point(e.Bounds.Width - 1, 0) });
e.Graphics.DrawLines(SystemPens.ControlDarkDark, new Point[] { new Point(0, e.Bounds.Height - 1), new Point(e.Bounds.Width - 1, e.Bounds.Height - 1), new Point(e.Bounds.Width - 1, 0) });
TextFormatFlags sf = TextFormatFlags.VerticalCenter | TextFormatFlags.HorizontalCenter | TextFormatFlags.NoFullWidthCharacterBreak;
e.DrawText(sf);