i am working on a database application project and i need to put some user authorization where it will change the visibility of button based on the role.

so i save all related form name in the database

then i retrieve all the form name from the database into my application

but i stuck with how to retrieve the button from only form name

my current code :

Function GetFormByName(ByVal FormName As String) As Form
        Dim Fullname As String = Application.ProductName & "." & FormName
        Return Activator.CreateInstance(Type.GetType(Fullname, True, True))
End Function

Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
dim MyForm as new form
MyForm = GetFormByName("<formname>")
dim Mybutton as new button
Mybutton = Myform.control("<buttonname>")
Mybutton .visible = false

thanks in advance

5 Years
Discussion Span
Last Post by Mitja Bonca

I dount this is how you can set some property over forms. Even if you will set the property to false, but button will not be dissapear at that moment (it will be visible until that form will get focus).
So I suggest you some other way. To Call a method on that Form, and there set the visiblility to false.
So, Create a method, which will set that button` property Visible to false on that form where button is. When retreiving the Form name from that your method, use the form`s reference, and call that method on that form:

'on this form:
Private Sub SomeMethod()
	Dim MyForm As New Form2()
	'and use this same code some where else to make it visible (use ture parameter)
End Sub

'on other form:
Public Sub SetButonVisibility(myValue As Boolean)
	myButton.Visible = myValue
End Sub
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.