如何调整或设置DrawToolTipEventArgs的Bounds成员

问题描述 投票:0回答:1

我添加了一个 Draw 处理程序来在应用程序中绘制工具提示,Draw 函数设置了固定的间距字体和大小,但结果是通过 DrawToolTipEventArgs 参数传入的边界矩形需要调整。

我需要修改它,因为调用函数

DrawBackground
DrawBorder
使用了错误的边界矩形。

如何调整事件中的边界矩形?

这是我设置 ToolTip 控件的代码:

this.ToolTip1.Draw += ToolTip1_Draw;
this.ToolTip1.Popup += ToolTip1_Popup;
this.ToolTip1.OwnerDraw = true;
this.ToolTip1.ReshowDelay = 10;

我可以看到

ToolTip1_Draw
正在被调用,但是
ToolTip1_Popup
从未被调用。 处理者:

        private void ToolTip1_Draw(object sender, DrawToolTipEventArgs e) {
            using (Graphics g = this.CreateGraphics()) {
                using (StringFormat sf = new StringFormat()) {
                    sf.Alignment = StringAlignment.Center;
                    sf.LineAlignment = StringAlignment.Near;
                    sf.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.None;
                    sf.FormatFlags = StringFormatFlags.NoWrap;
                    using (Font f = new Font("Courier New", 8)) {   
                        
                        e.DrawBackground();
                        e.DrawBorder();
                        e.Graphics.DrawString(e.ToolTipText, f
                                            , SystemBrushes.ActiveCaptionText
                                            , e.Bounds, sf);
                    }
                }
            }
        }
        private void ToolTip1_Popup(object sender, PopupEventArgs e) {
            using (Font f = new Font("Courier New", 8)) {
                e.ToolTipSize = TextRenderer.MeasureText(
                    ToolTip1.GetToolTip(e.AssociatedControl), f);
            }
        }

有人能明白为什么

ToolTip1_Popup
没有被调用吗?

[编辑] 在 IDE 中,我在

ToolTip1_Popup
中有一个断点,上面有一个感叹号,上面写着:

The breakpoint will not currently be hit. No executable code of the debugger's target code type is associated with this line.
Possible causes include: conditional compilation, compiler optimizations, or the target architecture of this line is not supported by the current debugger code type.

我正在使用的 IDE 的一些信息:

Microsoft Visual Studio Professional 2022 (64-Bit) - Current
Version 17.8.6

操作系统:

Microsoft Windows [Version 10.0.19045.4291]
c# tooltip
1个回答
0
投票

找到这个帖子: Windows 窗体工具提示在首次使用后不会重新出现

答案对我有用,它是一个修复并解决一个非常老的错误的冰箱。

© www.soinside.com 2019 - 2024. All rights reserved.