我是新来的,我做 VB.net 编程。
我想做一些非常具体的事情,但我不知道如何接近它。我有一个想要用于各种按钮的 ClickEvent。问题是我想让每个按钮更改一个文本框。我不想在 4 个单独的 ClickEvents 中执行此操作,因为我会重复很多代码。
这是我想做的:
Private Sub btnOpenDial1_Click(sender As Object, e As EventArgs) Handles btnOpenDial1.Click, btnOpenDial2.Click, btnOpenDial3.Click, btnOpenDial4.Click
Dim UnitLetter As String = Environment.CurrentDirectory.Substring(0, 3)
SaveFileDialog1.InitialDirectory = UnitLetter
SaveFileDialog1.Filter = "rtf file (*.rtf)|*.rtf"
If SaveFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
Try
'name is a TextBox variable that i have at the top of the program
name = SaveFileDialog1.FileName
If (name IsNot Nothing) Then
' I press btnOpenDial1, this textbox changes
txtDoc1.Text = nombre
' I press btnOpenDial2, this textbox changes
txtDoc2.Text = nombre
' I press btnOpenDial3, this textbox changes
txtDoc3.Text = nombre
' I press btnOpenDial4, this textbox changes
txtDoc4.Text = nombre
End If
Catch Ex As Exception
MessageBox.Show("No se ha podido grabar el archivo: " & Ex.Message)
End Try
End If
End Sub
我希望我解释得足够好。英语不是我的主要语言。我只是不想在我的程序上重复更多代码。提前致谢