从VB6到VB.NET的颜色代码模拟 [英] Color code analog from VB6 to VB.NET

查看:241
本文介绍了从VB6到VB.NET的颜色代码模拟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我是vb.net的新手,我试图做的是textbox3和texbox5有一个数据,我想做一个比较按钮,当我点击它,它将collor他们数据diffrences用红色,彩色数据将显示在texbox3中。来自vb6的代码(这些代码很好用):



Hello, im new at vb.net, what im trying to do is that textbox3 and texbox5 have a data, and i want to make a "compare" button, when i click it, it will collor they data diffrences with red, colored data will be shown in texbox3. the code from vb6(this codes works well btw):

Private Sub Command5_Click()
Dim a As Integer
Dim R1 As String
Dim r2 As String
Dim strimm As String
strimm = RichTextBox1.Text
 RichTextBox1 = Replace(strimm, vbCrLf, "")

strimm = RichTextBox2.Text
 RichTextBox2 = Replace(strimm, vbCrLf, "")
For a = 0 To Len(RichTextBox2)

RichTextBox1.SelStart = a
RichTextBox1.SelLength = 1
R1 = RichTextBox1.SelText
RichTextBox2.SelStart = a
RichTextBox2.SelLength = 1
r2 = RichTextBox2.SelText
If R1 <> r2 Then
RichTextBox1.SelColor = vbRed
End If
Next
End Sub





我尝试了什么:



我在VB.net中尝试的代码(它用红色来表示整个数据,如果只有1则不是eqaul,这是一个错误,我只需要差异数据颜色):





What I have tried:

The code i tried in VB.net( it colores whole data with red, if only 1 is not eqaul, thats an error, i need to only diffrence data colored):

Private Sub Command5_Click(sender As Object, e As EventArgs) Handles Command5.Click

        Dim a As Integer
        Dim R1 As String
        Dim r2 As String
        Dim strimm As String
        strimm = TextBox3.Text
        TextBox3.Text = Replace(strimm, vbCrLf, "")

        strimm = TextBox5.Text
        TextBox5.Text = Replace(strimm, vbCrLf, "")
        For a = 0 To TextBox5.TextLength


            TextBox3.SelectionStart = a
            TextBox3.SelectionLength = 1
            R1 = TextBox3.SelectedText
            TextBox5.SelectionStart = a
            TextBox5.SelectionLength = 1
            r2 = TextBox5.SelectedText
            If R1 <> r2 Then
                TextBox3.ForeColor = Color.Red
            End If
        Next
    End Sub

推荐答案

文本框除了作为一个整体之外不能被着色:它们没有任何单词格式化设施。

要做到这一点,你必须编写自己的TextBox控件 - 或者使用内置的RichTextBox控件,其工作方式与VB6代码中的控件大致相同...
Textboxes cannot be coloured except as a whole: they do not have any "individual word" formatting facilities.
To do that, you'd have to write your own TextBox control - or use the built in RichTextBox control which would work in much the same way as the one in your VB6 code...


这篇关于从VB6到VB.NET的颜色代码模拟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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