我有一个简单的翻译程序,我在vb2010工作。
我有一个组合框,一个文本框和一个按钮。
到目前为止,我所做的是,当您选择组合框中的选项时,将出现文本框和按钮。然后,当你输入一些东西时,它会在相同的文本框中用新的东西替换每个字母。
我想不出来的是如何使它在哪里,如果我再次点击按钮,它会将替换的字母翻译回原始字母。
如何做到这一点?
发布于 2012-02-11 14:35:16
尝试在替换之前将文本复制到字符串中,然后在单击第二个按钮时将文本框中的文本替换为字符串的内容。
Public Class Form1
Dim backingString As String
Dim bConverted As Boolean
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
If Not bConverted Then
backingString = TextBox1.Text
bConverted = True
If TextBox1.Text.Contains("A") Then
TextBox1.Text = TextBox1.Text.Replace("A", "/-\")
End If
Else
TextBox1.Text = backingString
backingString = ""
bConverted = False
End If
End Sub
End Class发布于 2012-02-11 15:26:57
当用户输入内容时,他们输入的内容是否会被“隐藏”的文本框捕获,而您的可见文本框就是正在显示的内容(我假设这是翻译)。然后,一旦用户点击按钮来显示他们发布的内容,你就可以隐藏翻译后的文本框,并显示隐藏的带有原始文本的文本框。它看起来像这样:
Private Sub Button1_Click()
TextBox1.Visible = False
TextBox2.Visible = True
End Sub当然,再次单击它不会反转它,所以我建议使用两个按钮的策略(一个隐藏,一个可见)。然后,当用户单击按钮以显示他们键入的内容时,隐藏的按钮将出现,因此将如下所示:
Private Sub Button1_Click()
TextBox1.Visible = False
TextBox2.Visible = True
Button1.Visible = False
Button2.Visible = True
End Sub
Private Sub Button2_Click()
TextBox1.Visible = True
TextBox2.Visible = False
Button1.Visible = True
Button2.Visible = False
End Sub发布于 2014-04-02 00:44:36
公共类Form1
这就是我怎么做的,我认为这是最简单的方法。
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Static buttonHits As Integer
buttonHits += 1
If IsOdd(buttonHits) = True Then
Button1.Text = "New"
Else
Button1.Text = "Original"
End If
End Sub
Function IsOdd(ByVal iNum As Integer) As Boolean
IsOdd = ((iNum \ 2) * 2 <> iNum)
End Function
End Classhttps://stackoverflow.com/questions/9238333
复制相似问题