|
With the help of Yesterday`s discussion[^] and this[^] I worked am getting all the type in system.Windows.Forms
Code:
<font>AssemblyName name = new AssemblyName("System.Windows.Forms");
name.CultureInfo = new System.Globalization.CultureInfo("");
name.SetPublicKeyToken(new byte[] {0xb7, 0x7a, 0x5c, 0x56, 0x19, 0x34, 0xe0, 0x89});
name.Version = new Version(2, 0, 0, 0);
Assembly a = Assembly.Load(name);
Type[] types = a.GetTypes();
foreach (Type t in types)
{
if (t.Namespace == "System.Windows.Forms")
listBox1.Items.Add(t.ToString());
}
MessageBox.Show(listBox1.Items.Count.ToString());
</font>
I didnt Understand the meaning of
<br />
name.SetPublicKeyToken(new byte[] {0xb7,0x7a, 0x5c, 0x56, 0x19, 0x34, 0xe0, 0x89});<br />
Can you Explain This
Thanks & Regards
Amar Chaudhary
It is Good to be Important but!
it is more Important to be Good
|
|
|
|
|
When signing assemblies a private and public key are generated by the company distributing the assembly. The company keeps the private key in a secure location. The public key is sent along with the assembly. When the company signs an assembly with the private key, third party users can then use the public key to verify that the assembly has not changed. Basicaly it allows users to detect if someone has tampered with the assembly.
Now, assemblies have four pieces of information to describe their full name. They are Name, Version, Culture, and PublicKeyToken. The PublicKeyToken is the public key which is used to validate that the assembly has not changed.
Now, it is possible to change the assembly and simply sign it will a different private key and update the PublicKeyToken appropriately. But in this case, you application is typically tied to the assembly using the full name (which include the correct public key). So in this case your application won't open the assembly because the public key is not correct.
So, long story short. If you excluded the public key then the assembly would still load, but then someone could drop in a "hacked" version of the assembly and your application would happily load it.
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
Thanks and regards
Amar Chaudhary
It is Good to be Important but!
it is more Important to be Good
|
|
|
|
|
I have one more problem
How can I distinguish controls in any namespace / dll
Thanks & Regards
Amar Chaudhary
It is Good to be Important but!
it is more Important to be Good
|
|
|
|
|
You're going to have to explain what you mean by this. What do you mean by "distiguish"?? And in "any namespace"?? What are you trying to do??
|
|
|
|
|
I am creating an article for code project
which is a theme applier for windows forms
we have an xml file with details of theme (Some what like the Concept of CSS)
this will contain 4 projects
1>Control Resizer : it will resize most of the controls at run time (completed)
2>Auto Control Resizer: this will resize all the controls on run time when the form is resized or the screen resolution is changed (completed)
3>UI Applier : this will read the theme from the xml and apply it to the respective forms (Almost completed )
4>UI Maker : this will make that XML file.-> I want to implement the idea that user can select any control at run time (for example a button) he can select that control even if it is custom control, then the control will be shown on the screen, with its property grid. he can modify control at run time and see the effects of the modification on the run time. (partially completed)
now the problem is that I need to get a list of all such controls so that user can select the control and that control can be created at run time.
Thanks and Regards
Amar Chaudhary
It is Good to be Important but!
it is more Important to be Good
|
|
|
|
|
I'm assuming you want the types from a given assembly that derive from System.Windows.Forms.Control. If so, then once you have the assembly loaded you can run the following code:
foreach (Type type in assembly.GetTypes()) {
if (type.IsSubclassOf(typeof(Control))) {
}
}
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
Great
the list is pretty much clear But there are still some extra entries
Like
System.Windows.Forms.Application+MarshalingControl
System.Windows.Forms.Application+ParkingWindow
System.Windows.Forms.AxHost
System.Windows.Forms.UpDownBase
System.Windows.Forms.UpDownBase+UpDownEdit
System.Windows.Forms.UpDownBase+UpDownButtons
System.Windows.Forms.DomainUpDown
System.Windows.Forms.PropertyGrid+SnappableControl
System.Windows.Forms.SendKeys+SKWindow
System.Windows.Forms.StatusStrip+RightToLeftLayoutGrip
System.Windows.Forms.ToolStripComboBox+ToolStripComboBoxControl
System.Windows.Forms.ToolStripOverflow
System.Windows.Forms.ToolStripPanel+FeedbackRectangle+FeedbackDropDown
System.Windows.Forms.ToolStripScrollButton+StickyLabel
System.Windows.Forms.ToolStripTextBox+ToolStripTextBoxControl
System.Windows.Forms.PrintControllerWithStatusDialog+StatusDialog
Thanks & Regards
Amar Chaudhary
It is Good to be Important but!
it is more Important to be Good
|
|
|
|
|
It really depends on what you are looking for, but I'm assuming you want only public and non-abstract controls, which would look like:
foreach (Type type in assembly.GetTypes()) {
if (type.IsSubclassOf(typeof(Control)) &&
type.IsPublic &&
!type.IsAbstract) {
}
}
I would recomment using Reflector[^] to help further filter the list. The Type class has lots of properties that can be used.
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
Thanks
if you want to see what I am doing you can see this[^]
Thanks and Regards
Amar Chaudhary
It is Good to be Important but!
it is more Important to be Good
|
|
|
|
|
I want to search for an line in a .txt file, if there are text then go.
i tryade this:
string[] lines = System.IO.File.ReadAllLines(".txt");
if (lines[0] == "#")
{
but it doesn´t work. Do you have some suggest?
Tnx!!;););)
|
|
|
|
|
Try a foreach-loop and match the indexed string against your searchpattern.
For instance:
string searchPattern = "#";
foreach(string line in lines)
{
if(line.Equals(searchPattern))
{
}
else
{
}
}
You could also use String.Contains(searchPattern) .
-Larantz-
|
|
|
|
|
Are you simply searching for lines that begin with "#"?
If so, then code is:
foreach (String line in lines) {
if (line.StartsWith("#")) {
}
}
Basically, you are missing the loop that iterates over each line read..
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
ok.. but i have to give out line nr can i do like this?
foreach (String line in lines)
{
if (line[20].StartsWith("#"))
{
or d oi have to change the hole code?
|
|
|
|
|
To get the line number, you would need to either keep a counter, like so:
Int32 lineNumber = 0;
foreach (String line in lines) {
lineNumber++;
}
or you could switch to the for[^] loop (instead of a foreach[^] loop), like so:
for (Int32 i = 0; i < lines.Length; i++) {
String line = lines[i];
Int32 lineNumber = i + 1;
}
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
ok..
So if line[20] exists in the .txt file, so let the code to run.
Int32 lineNumber = 20;
foreach (String line in lines)
{
If (lineNumber++;)
{
////my code?
}
}
Or i´m i wrong ??
Do you understand what i´m trying to do? I have a directory search and the user can add more paths, and it saves in a .txt file... !!
Tnx Man!!
|
|
|
|
|
Sorry, I don't understand what you are trying to do. Are you looking for the 20th line?
I doubt the code you provided above is correct, though. The line number variable tells you the line number for the current line in the loop. So the loop gets the first line into the line variable. At this point lineNumber will be 1 because it's the first line. You can then perform an operation on that line. Then the loop will then get the next line into the line variable. At this point lineNumber will be 2 because it's the second line.
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
OK.. i don´t know if the if() code is the right thing to do here.. my .txt file look like this
#
C:\Documents and Settings\scanner\Skrivbord\Ny mapp
// it can be more, if the user adds more, like this:
//#
//C:\Documents and Settings\scanner\Skrivbord\Ny mapp2
My code moves folders and count files in them.. i just need mayby a if code to check if its text in line[3] (for this example] and if its true then go on and count files and move foldern in that path.
Or do you have another suggest?
Tnx my friend!!!
-- modified at 9:39 Thursday 6th September, 2007
|
|
|
|
|
So the format of the file is a # on a line, followed by the path on the next line? In your example above, the lines added by the user are preceeded by //, is this correct? Please try to explain the format a little more clearly.
After I understand the format, I can explain how to pull out the paths.
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
It´s build like this
#
name(example1)
C:\Documents and Settings\scanner\Skrivbord\Ny mapp(example1, path)
C:\Documents and Settings\scanner\Skrivbord\Ny mapp2(example1, destination folder)
price(example1)
name(example1)
#
name(example2, don´t have to be added)
C:\Documents and Settings\scanner\Skrivbord\Ny mapp(example2, path)
C:\Documents and Settings\scanner\Skrivbord\Ny mapp2(example2, destination folder)
price(example2)
name(example2)
That´s how the .txt file is build, but it can mayby be up to 10-15 examples, its the user hwo decide that.
// where just an example in the previous code...
more clearly now my friend..?
Tnx!!
|
|
|
|
|
Based on the example above, the code below will properly parse it out. I included comments so that you can understand what it's doing and learn from it. But, if you have an questions then let me know.
Int32 index = 0;
while (lines.Length >= index + 6) {
if ("#" != lines[index].Trim()) {
index++;
continue;
}
String name1 = lines[index + 1];
String path1 = lines[index + 2];
String path2 = lines[index + 3];
String price = lines[index + 4];
String name2 = lines[index + 5];
index += 6;
}
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
Thanks man!! You are the best!
One more question, if i add a item to a listview, then i only want to save THAT item to a .txt file not the hole listview items in it.
i use this right now:
using (StreamReader adressFil = new StreamReader("dataapplikationer.txt"))
{
string rad;
while ((rad = adressFil.ReadLine()) != null)
{
ListViewItem nyAdress = new ListViewItem(adressFil.ReadLine());
nyAdress.SubItems.Add(adressFil.ReadLine());
nyAdress.SubItems.Add(adressFil.ReadLine());
this.listView1.Items.Add(nyAdress);
this.listView1.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
}
}
i only want to save that item i just added with a button_click? what do i need to change?? And how do i delete ONE items from .txt file?
i´m finished pretty soon...;P
Kisses
|
|
|
|
|
The easiest and recommended way is to simply write everything to the file when saving. Technically, you could add and remove items from the file but this can be tricky.
Basically, you will read everything into the ListView. Allow the user to add or remove items as they see fit. Then to save, you simply write everything (which is everything in the ListView) to the file. Since you are overwriting the file, only items that are in the ListView will exist in the file after saving. This means items deleted by the user were removed and items added were inserted.
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
ok... i can go round it by have two listviews one fore save and next to show...
But heres a difficult question??
I have a button called split it means that i have listview1 that looks like this
for example:
(listview1)
columheader1, columheader2, columheader3, columheader4, columheader5
Online, k441211 DateTime.now , ad , whatever
if i click on this listview.item i want to copy the hole item with all the subitems in it EXCEPT subitem[1] it´s gonna look and check .txt file and count +1 if that is taken +1 if that is taken +1......
Little to hard to explain.. ;)
|
|
|
|
|
Sorry, I don't understand what you are trying to accomplish.
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|