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

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()
	MyForm.SetButonVisibility(False)
	'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
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.