突出显示文本框中的数值。 [英] Highlight numeric value in a textbox.

查看:81
本文介绍了突出显示文本框中的数值。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用visual studio 2010(vb.net- windows窗体)。



我有一个文本框,其中包含数字的日期和字符串。

i需要突出显示该文本框中的所有数值和日期,并需要一个选项来更改鼠标单击时的值。 (即字符串内容没有变化)



例如



让文本框中的值为



我的名字是Sidharth。我26岁。我的dob是22/03/1990



当值加载到文本框时

它应显示为



我的名字是Sidharth。我是 26岁。我的dob 22/03/1990



鼠标点击或鼠标焦点我需要一个更改选项。



I am using visual studio 2010 (vb.net- windows form ).

I have a text box which consist of number's date and string.
i need to highlight all numeric values and date in that text box and need an option to change the value on mouse click . (ie No changes in string content)

for example

let value in text box be

"Hi my name is Sidharth. I'm 26 yr old . my dob is 22/03/1990"

when value is loaded to text box
it should display as

"Hi my name is Sidharth. I'm 26 yr old . my dob is 22/03/1990"

on mouse click or mouse focus i need an option to change.

Dim TextToFormat As Integer
       Dim TextFormat As String
       TextFormat = 1
       TextToFormat = "Hi my name is Sidharth. I'm 26 yr old . my dob is 22/03/1990"
       Dim count As New List(Of Integer)()
       For i As Integer = 0 To rText.Text.Length - 1
           If rText.Text.IndexOf(TextToFormat, i) <> -1 Then
               'If the word is found add the index to the list
               count.Add(rText.Text.IndexOf(TextToFormat, i))
           End If
       Next

       Try
           For i As Integer = 0 To count.Count - 1
               rText.[Select](count(i), TextToFormat.Length)
               Select Case TextFormat
                   Case 1
                       rText.SelectionFont = New Font(rText.Font.FontFamily, rText.Font.Size, FontStyle.Italic)

                   Case 2
                       rText.SelectionFont = New Font(rText.Font.FontFamily, rText.Font.Size, FontStyle.Italic)
               End Select
               count.RemoveAt(i)
           Next
       Catch
       End Try



在此搜索txtbox中的文本并格式化文本

bt我需要获取所有数值。


in this im searching a text in txtbox and formatting the text
bt i need to get all numerical values.

推荐答案

实现这一目标的最佳方法是使用Regex [ ^ ] with pattern [ ^ ]: \d {1,} 仅查找数值。



注意:上述模式不支持 / 和任何其他非数字。您需要找到符合您需求的模式。
The best way to achieve that is to use Regex[^] with pattern[^]: \d{1,} to find only numeric values.

Note: above pattern does not supports "/" and any other non-digits. You need to find pattern which meet your needs.


这篇关于突出显示文本框中的数值。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆