ToolTip in Text inside RichTextBox

2019-06-09 14:59发布

im working with code editor and i just wanted to add tooltip for everytext that Ill inputed in richtextbox(served as code-editor) .

'till i see this guide right here:

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

its the same thing that I wanna find though the time I download it theres a file missing specifically its mainform .

so i just wanna ask if how to do it without using any .dll file .

sample: i type "abc" in rtb then when i mouse hover it a tooltip with text: this is an alphabet will appear . same as with "123" a when i mousehover tooltip with text: this is a number will appear .

really need a help and thanks a lot in advance .GodBless!

1条回答
做个烂人
2楼-- · 2019-06-09 16:02

You can try this Sample, One way to Achieve

   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);
            }

        }
    }
}

enter image description here

查看更多
登录 后发表回答