本文介绍了形式传递参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在VB.Net中的窗口应用程序上工作.我的form.show()确实有问题.
场景是-

假设我有带两个按钮的form1
button1.text =一个"
button2.text =一个"

我还有另一个表格2
我想打开每个在form1上单击的按钮的form2.

Hi,

I am working on window application in VB.Net. I do have a problem with form.show().
The scenario is-

suppose i have form1 with two buttons
button1.text = "one"
button2.text = "one"

I have another form2
i want to open form2 on each button click present on form1.

'click event on button1
Dim obj As New form2(button1.text)
obj.Show()





'click event on button2
Dim obj As New form2(button2.text)
obj.Show()



在form2



on form2

Public Sub New(ByVal ReceiveValue As String)
  MyBase.New()
  InitializeComponent()
End Sub



现在,每次我单击button1或button2时,都会打开一个新的form2.

我想为button1打开1个表单,为button2打开1个表单.
如果表单已经打开,如何防止每个button1和button2出现重复的表单.

Thanks



Now every time i click on button1 or button2 a new form2 is open.

I want to open 1 form for button1 and 1 form for button2.
How do i prevent duplicate forms for each button1 and button2 if form is already open.

thanks

推荐答案


For Each CurrentForm As Form In Application.OpenForms
            If CurrentForm.Name = "form2" Then
              Dim Form2Instance As form2 = DirectCast(CurrentForm, form2)
              If Form2Instance.TextBox1.Text = "some text" Then
                Form2Instance.BringToFront()
                Exit Sub
              End If
            End If
          Next

          Dim form As New form2("some text")
          form.Show()


这篇关于形式传递参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-21 13:42