形式传递参数 [英] passing parameter in forms

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

问题描述



我正在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

推荐答案

每次创建新实例的形式都会打开一个新实例.

解决该问题的最佳方法是允许另一个类(让我们说一个控制器类)为您打开这两种形式.您可以跟踪其中打开的表单的数量,并控制要在屏幕上看到的打开表单的数量.
Everytime you create a new instance of the form a new one will open.

The best way to handle the problem is to allow another class (lets just say a controller class) to open both these forms for you. You can keep a track of the number of open forms inside this and control the number you want to be seen open on the screen.


感谢您的解决方案..

但是我已经完成了下面的解决方案

thanks for the solution..

but i have done with my below solution

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()


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

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