[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 200
  • Last Modified:

form tags

Hi. I want to assign form's tag values dynamically during application main form load. Like that, form1.tag = 1, form2.tag =2, form3.tag = 3, ....
without opening these forms. I will use the tags values for the control purpose later on. Is it possible?
thanks
0
gokhanoz
Asked:
gokhanoz
  • 5
  • 2
1 Solution
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
It's possible if you have VB.Net 2005 and are using the "default instances" of the forms...
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Couldn't you just set the Tags at design-time in the IDE?

How are you going to use the Tags?
0
 
gokhanozAuthor Commented:
I want to dig some importan information about the user rights here. so everytime user wants to open the form, application will use that information to adjust the controls in the form. Can you give some examples of default instance because I am using VB.NET 2005 and because of this reason I can't set the values at design time?
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
Mike TomlinsonMiddle School Assistant TeacherCommented:
You use the default instance by using the Forms name:

Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Form2.Tag = 911
        Form2.Show()
    End Sub
End Class

Public Class Form2
    Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        MsgBox(Me.Tag)
    End Sub
End Class
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Or you could pass in the code to the constructor and use that value in the Load() event:

Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim f2 As New Form2(3)
        f2.Show()
    End Sub
End Class

Public Class Form2
    Private code As Integer

    Public Sub New(ByVal code As Integer)
        InitializeComponent()

        Me.code = code
    End Sub

    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If code > 1 Then
            Button1.Enabled = False
        End If
    End Sub
End Class

0
 
gokhanozAuthor Commented:
Thanks Idle_mind, I guess I can not make it without openning the forms. If you have something similar, what would you suggest me (Because I cannot use your second example)? I guess that the easiest way is to assign tags to the childs during the mdiparent load, but seems not the easiest.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
It makes sense to me to assign the priviledge level to the form when you create it from the MdiParent...
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now