VB.NET

Moderators: seancampbell
Number of threads: 4020
Number of posts: 10026

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
List of ALL Controls in PROJECT - VB.net Posted by fabiocrj on 16 Mar 2011 at 6:36 AM
Hi all,

I don´t know if this is the right area. Please sorry if not.
Well, first of all, thanx for your attention. I´ve searched the whole web (at last where google can see) for a solution, but i just can´t find.
The problem is the following: I want a list of all controlls in my project, not only on open forms. The reason is that i want to make an access control, and the admin will set which buttons each users can use.

what i´ve got so far is:

Public Sub getallforms(ByVal sender As Object)
Dim Forms As New List(Of Form)()
Dim formType As Type = Type.GetType("System.Windows.Forms.Form")
For Each t As Type In sender.GetType().Assembly.GetTypes()
If UCase(t.BaseType.ToString) = "SYSTEM.WINDOWS.FORMS.FORM" Then
MsgBox(t.Name)
End If
Next
End Sub


This shows me all forms in project. But i cant access their controls. to you have any ideia of how doing what i want?
Thank you very much!
Report
Re: List of ALL Controls in PROJECT - VB.net Posted by DaiMitnick on 17 Mar 2011 at 5:19 AM
Yes, getting the controls in VB.NET is a very tricky thing indeed, one of the few disadvantages of .NET compared to Classic. The following page gives one of the easiest methods I've found for doing it:



http://www.codeproject.com/KB/vb/control_arrays_in_vbnet.aspx

Hope this will help you to achieve what you need. Dai


------------------------------------------
Do or do not, there is no try. |
------------------------------------------
Report
Re: List of ALL Controls in PROJECT - VB.net Posted by fabiocrj on 17 Mar 2011 at 7:09 AM
Sorry, but i couldn´t find the link...
Report
Re: List of ALL Controls in PROJECT - VB.net Posted by DaiMitnick on 18 Mar 2011 at 6:01 AM
That's strange, I used the link command and that actually stopped the link displaying, never mind, have pasted the link text again. Regards, Dai


------------------------------------------
Do or do not, there is no try. |
------------------------------------------
Report
Re: List of ALL Controls in PROJECT - VB.net Posted by BillyLunchMoni on 4 Apr 2011 at 7:07 AM
Hi,
You might want to try this peace of code I came across. It'll find the object by string/name and return the object which you can iterate through if you need.

Private Function getfromFromName(ByVal FormName As String) As Object
Dim oRetForm As Object = Nothing
Dim oType As Type = _
Assembly.GetExecutingAssembly().GetType(FormName)
If oType IsNot Nothing Then
oRetForm = Activator.CreateInstance(oType)
End If

Return oRetForm

End Function




Report
This post has been deleted. Posted by BillyLunchMoni on 4 Apr 2011 at 7:07 AM
This post has been deleted.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.