【问题标题】:ToolTip in Text inside RichTextBoxRichTextBox 内文本中的工具提示
【发布时间】:2020-03-01 06:21:39
【问题描述】:

我正在使用代码编辑器,我只想为 Ill 在richtextbox(用作代码编辑器)中输入的每个文本添加工具提示。

直到我在这里看到本指南:

http://www.codeproject.com/Articles/464085/WinForms-RichTextBox-ToolTip-like-Visual-Studios

这和我想找到的东西是一样的,虽然我下载它的时候有一个文件特别缺少它的主格式。

所以我只想问如果不使用任何 .dll 文件如何做到这一点。

示例:我在 rtb 中键入“abc”,然后当我将鼠标悬停在它上面时,会出现一个带有文本的工具提示:这是一个字母表。当我将鼠标悬停在带有文本的工具提示时,与“123”相同:这是一个数字。

【问题讨论】:

  • 你想要在 RTB 中,当我输入“C# is Awesome”时,你只需要在 Tooltip 或 Full Sentence 中获得 Awesome
  • 如果可能的话,我在 rtb 中输入的不同文本可能是。如果我输入带有消息“它真的很棒”的“C# is Awesome”工具提示将出现。类似的东西......就像链接中显示的那样,但如果它只是一个简单的工具提示并且没有边框,它对我来说没问题......
  • “它真的”是您在 RTB 中键入的 Last Word 必须附加的常用词。请告诉我示例输入和输出
  • rtb 中的输入文本-> abc = outputtext(当文本鼠标悬停时)-> 这是一个字母表。如果它的 123 -> inputtext(当文本鼠标悬停时)-> 这是一个数字。
  • 请检查答案,请告诉我这是您所期待的吗?

标签: c# visual-studio


【解决方案1】:

你可以试试这个示例,实现的一种方法

   using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication3
{
    public partial class Form1 : Form
    {
        public string rtbTypedText = "";
        public Form1()
        {
            InitializeComponent();
        }





        private void richTextBox1_Leave(object sender, EventArgs e)
        {


           // MessageBox.Show(text);

        }

        private void richTextBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (char.IsWhiteSpace(e.KeyChar))
            {
                int result = 0;
                string s = richTextBox1.Text;

                string text = "";
                string[] sp = s.Split(' ');

                if (sp.Length == 0)
                    rtbTypedText = s;
                else
                    rtbTypedText = sp[sp.Length - 1];


                bool typeStatus = int.TryParse(rtbTypedText, out result);
                if (typeStatus == true)
                    toolTip1.Show("It is a Number", richTextBox1);
                else
                    toolTip1.Show("It is an Alphabet", richTextBox1);
            }

        }
    }
}

【讨论】:

  • @Akyshay Joy rtbTypedText 不存在 maam
  • 请在全局区域声明strign变量
  • 我还添加了工具提示 toolTip1 = new ToolTip();它已经运行了,但没有任何变化...... :(
  • 请拖放工具箱中的工具提示组件。它在我的代码中运行良好。
  • 我应该在 rt 中输入什么?实现工具提示?
猜你喜欢
  • 2015-09-02
  • 1970-01-01
  • 1970-01-01
  • 2017-01-31
  • 1970-01-01
  • 2016-01-17
  • 1970-01-01
  • 1970-01-01
  • 2012-07-17
相关资源
最近更新 更多