在vb中共享表单之间的属性

时间:2015-11-09 16:08:47

标签: vb.net

我要在两个表单之间传递属性。在Form2中:我创建了属性IsFilterEnabled并在formmain中访问它

 Public Property IsFilterEnabled() As Boolean
        Get
            Return mIsEnabled
        End Get
        Set(ByVal Value As Boolean)
            mIsEnabled = Value
        End Set
    End Property
  Public Sub FilterButton_Click() Handles FilterButton.Click
        Dim currentRow As Data.DataRow
        If vessel_NameComboBox.SelectedIndex > -1 Then
            mIsEnabled = True
            formMain.LoadData()
        End If
    End Sub

Formmain

Dim frm2 As New Form2
If frm2.IsFilterEnabled = True Then End

数据丢失IsFilterEnabled属性为即时创建form2的新实例。如何在formmain中获取form2的相同实例以访问属性

2 个答案:

答案 0 :(得分:0)

在Form2的构造函数中传递属性。

    var app = angular.module('myIso', ['ngRoute']);
        app.config(function ($routeProvider) {
          "use strict";
            $routeProvider
          .when('/', {
            controller:
            'HomeController',
            templateUrl:
            'views/home.html'
          })
          .when('/map', {
            controller:
            'MapController',
            templateUrl:
            'views/map.html'
          })
          .otherwise({
            redirectTo: '/'
          });
        });

    app.controller('MapController', ['$scope', function ($scope) {
        "use strict";
      }]);

答案 1 :(得分:0)

在声明属性时,使用Shared关键字为您的属性提供全局范围,可在其他成员之间共享。

Public Class Form2 : Inherits Form

    Public Shared Property MyProperty As Object

End Class

然后您可以随时访问共享值:

Public Class Form1 : Inherits Form

    Form2.MyProperty = "1st Hello World!"

    Dim f As New Form2
    f.MyProperty = "2nd Hello World!"
    f.Show()
    f.Dispose()

    MsgBox(Form2.MyProperty.ToString)

End Class