473,563 Members | 2,897 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

List All Form and All Control in each Form in a project

3 New Member
I'm using a assembly to load my apllication, and now I need to
list all forms in my apllication and list all controls.
I have read the topic on http://bytes.com/topic/c-sharp/answe...side-each-form and do like that, i only listed all form's name but i can't listed any control in any form. When i used the CreatInstance function to get the controls of the form, it always return null value.
Please help me!
Oct 21 '09 #1
5 5000
tlhintoq
3,525 Recognized Expert Specialist
I've read over the article you mentioned.
Would you provide the code that you actually using that gives you the error?

And just because I'm curious... What is the purpose/need for going through all this? If you are loading your application doesn't that mean you already have access to all the forms and controls in it?
Oct 21 '09 #2
nktt3514
3 New Member
Thank for your anwser.
Here is my code :

Expand|Select|Wrap|Line Numbers
  1. Assembly assembly = Assembly.GetExecutingAssembly();
  2.  
  3.             List<string> listAllForm = new List<string>();
  4.             List<string> listAllControl = new List<string>();
  5.             string control = string.Empty, form = string.Empty;
  6.  
  7.             foreach (Type assemblyType in assembly.GetTypes())
  8.             {
  9.                 if (assemblyType.IsSubclassOf(typeof(Form)))
  10.                 {
  11.                     AssemblyName[] name = assembly.GetReferencedAssemblies();
  12.  
  13.                     listAllForm.Add(assemblyType.Name);
  14.                     form += "\r\n" +  assemblyType.Name + "\r\n";
  15.  
  16.                     Form frm = (Form)assembly.CreateInstance(assemblyType.BaseType.Name,
  17.                                     false, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.InvokeMethod, null, null, CultureInfo.GetCultureInfo("en-us"), null);
  18.                     if (frm != null)
  19.                     {
  20.                         if (frm.Controls.Count > 0)
  21.                         {
  22.                             foreach (Control ctrl in frm.Controls)
  23.                             {
  24.                                 listAllControl.Add(ctrl.Name);
  25.                                 control += ctrl.Name;
  26.                                 control += "\r\n";
  27.                             }
  28.                         }
  29.                     }
  30.                     else
  31.                     {
  32.                         control = "Can't load";
  33.                     }
  34.                 }
  35.             }
  36.  
  37.             richTextBox1.Text = control;
  38.             richTextBox2.Text = form;
I'm trying to decentralize my application follow the function of the user logged in.So, I need to list all the controls (such as: Button, TextBox, ...) in the forms that the user can do action.
Please help me!
Oct 21 '09 #3
tlhintoq
3,525 Recognized Expert Specialist
TIP: When you are writing your question, there is a button on the tool bar that wraps the [code] tags around your copy/pasted code. It helps a bunch. Its the button with a '#' on it. More on tags. They're cool. Check'em out.
Oct 21 '09 #4
tlhintoq
3,525 Recognized Expert Specialist
I'm trying to decentralize my application follow the function of the user logged in.So, I need to list all the controls (such as: Button, TextBox, ...) in the forms that the user can do action.
Honestly, I can't even envision how you are going to go about taking a list of all the forms and all the control names, and make that relate to user privileges when they log in. It seems that if everything is tied to the form names and control names then it will be hard to manage. Every time you add a control, or change a name then you have to rework your permissions code. I'd love to see how you go about accomplishing this based on form and control names.

I go a much different route: A "Priveleges " class. When a user logs in their Priveleges class is populated. The class contains booleans like "AllowEdit" , "AllowMakeUsers ", "AllowExit" , "ShowTools" , "AllowCustomize " and so on. Then the code of all the other forms just gets the user's Priveleges class to see if they are allowed to do something. If the user tries to open the 'Preferences' but "AllowCustomize " is false, then they get a dialog saying they don't have permissions.

In some places I just use the Priveleges to determine if certain menu options are even visible
EditMenu.Visibl e = AllowEdit;


Anyway, getting back to the way you want to do requiring getting all the form names and control names... I've never played with doing that. I'll play around with the code you provided and see what I can come up with.
Oct 21 '09 #5
nktt3514
3 New Member
Thank for your sharing.
But, I have my reason to choose that way. If you can help me to solving above codes, i'll feel very happy.
All that i need is how to list all Forms and all controls inside each Form.
Thanks!
Oct 21 '09 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

6
2129
by: allyn44 | last post by:
HI--what I am trying to do is 2 things: 1. Open a form in either data entry mode or edit mode depending on what task the user is performing 2. Cancel events tied to fields on the form if I am in edit mode. The reason I want to do this is becasue when entering a new record the form is entered in data entry mode and I have lots of stuff...
8
2732
by: sara | last post by:
I am learning Access and programming. I wanted to have the user select the departments for an ad from the list of all departments. Found code (that I could understand) on this site, and it works. But I have 2 quesitons: 1. How can I REMOVE a selection from the Destination List box - and keep the others there? My first code removes ALL...
8
2551
by: Galina | last post by:
Hello I have 6 dependent list boxes on my ASP page:  Faculty;  Lecturer;  Course;  Course occurrence;  Group;  Week commencing date. When faculty is selected, lists of lecturers and courses are populated. When course is selected, lists of occurrences, groups and
2
1878
by: Wysiwyg | last post by:
I was hoping to get some opinions on the efficiency of various methods of reusing the same dropdown list data. Here is the situation: Multiple panels on maintenance pages with TAB menus across the top showing different panels. A DropDownList with a 50+ value/text entries exists on more than one panel but only one will be displayed at a...
20
1634
by: TM | last post by:
I have a form that I would like to use, with a few small code and control text changes, and was wondering if there was any way that I could somehow save another cop of the form so I can just import it code and all. Thanks -- Tony
3
2616
by: Zorpiedoman | last post by:
Horay! I have just put the finishing touches on a new User Control... The" Jelly Button" I created a setup program which runs fine. I see the .dll nicely in the GAC. How come it does not show up in my Add/Remove componenets list when I try to add it to the toolbar?
9
1649
by: Dimsion | last post by:
Hi, How do i expose all my forms and it controls to other form in the project? I want to be able to add a form and some control on it, this then be available to all other forms. form1 click event: 'this allow me to change the textbox on form2 from form1 Form2.text="" 'this allow me to add item to form2 from form1
4
13348
by: Toze | last post by:
I'm using a assembly to load my apllication (ex: Mobi.exe), and now I need to list all forms in my apllication and list all controls (ex: txtname;btnname) inside of each form.
3
4671
by: bsturg21 | last post by:
Hello, I have a windows form that has a series of linklabels on it, and I need to have each linklabel, when clicked, open a separate windows form that has a single paramter passed into it. The form that has the System.Windows.Forms.LinkLabel controls on it is in a different project and under a different namespace from the file where the...
0
7665
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7583
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7888
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7642
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7950
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5213
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2082
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1200
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.