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!
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?
Thank for your anwser.
Here is my code : - Assembly assembly = Assembly.GetExecutingAssembly();
-
-
List<string> listAllForm = new List<string>();
-
List<string> listAllControl = new List<string>();
-
string control = string.Empty, form = string.Empty;
-
-
foreach (Type assemblyType in assembly.GetTypes())
-
{
-
if (assemblyType.IsSubclassOf(typeof(Form)))
-
{
-
AssemblyName[] name = assembly.GetReferencedAssemblies();
-
-
listAllForm.Add(assemblyType.Name);
-
form += "\r\n" + assemblyType.Name + "\r\n";
-
-
Form frm = (Form)assembly.CreateInstance(assemblyType.BaseType.Name,
-
false, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.InvokeMethod, null, null, CultureInfo.GetCultureInfo("en-us"), null);
-
if (frm != null)
-
{
-
if (frm.Controls.Count > 0)
-
{
-
foreach (Control ctrl in frm.Controls)
-
{
-
listAllControl.Add(ctrl.Name);
-
control += ctrl.Name;
-
control += "\r\n";
-
}
-
}
-
}
-
else
-
{
-
control = "Can't load";
-
}
-
}
-
}
-
-
richTextBox1.Text = control;
-
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!
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. 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.
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!
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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...
|
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
|
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...
|
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
| |
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?
|
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
|
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.
|
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...
|
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...
|
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...
| |
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. ...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |