小编Ele*_*iac的帖子

显示鼠标悬停文本的工具提示

与此问题相关: 在鼠标悬停文本时显示工具提示

如何对 RichTextBox 中的关键字而不是链接执行相同的操作?

在 RichTextBox 中我输入:

Hello World, How are You?
Run Code Online (Sandbox Code Playgroud)

我将鼠标悬停在“世界”这个词上作为工具提示,当它悬停时,工具提示会出现“这就是世界”!

但如果它悬停在 RichTextBox 之外或“World”一词本身,工具提示就会消失。

c# tooltip winforms mousehover

5
推荐指数
1
解决办法
2528
查看次数

根据其内容的宽度调整标签宽度

我正在使用代码编辑器,并希望随着数字的增加自动调整标签的宽度。例如,对于 1-9(1 位数字),有一个特定的宽度。然后当它达到 10-99(2 位数)时,标签的宽度增加。然后又是 100-999(3 位数)等。

结果应该是这样的:

在此处输入图片说明

这是我的代码:

private void timer_countline_Tick(object sender, EventArgs e)
{
    updateNumberLabel();
}

private void updateNumberLabel()
{
    // we get index of first visible char and number of first visible line
    Point pos = new Point(0, 0);
    int firstIndex = rtb.GetCharIndexFromPosition(pos);
    int firstLine = rtb.GetLineFromCharIndex(firstIndex);

    // now we get index of last visible char and number of last visible line
    pos.X = ClientRectangle.Width;
    pos.Y = ClientRectangle.Height;
    int lastIndex = rtb.GetCharIndexFromPosition(pos);
    int lastLine = rtb.GetLineFromCharIndex(lastIndex);

    // …
Run Code Online (Sandbox Code Playgroud)

c# label width winforms

3
推荐指数
1
解决办法
8449
查看次数

标签 统计

c# ×2

winforms ×2

label ×1

mousehover ×1

tooltip ×1

width ×1