|
Yes and I allways get an TypeLoadException.
The problem is that the Type.GetType method searches the executing assembly in this case an testlibrary.
"An unhandled exception of type 'System.TypeLoadException' occurred in xmltestlibrary.dll
Additional information: Could not load type System.Windows.Forms.TextBox from assembly TestLibrary, Version=1.0.1589.1600, Culture=neutral, PublicKeyToken=null."
|
|
|
|
|
Then you have to force .NET to load the correct assembly:
<br />
String name = System.Reflection.Assembly.CreateQualifiedName("System.Windows.Forms", "TextBox");<br />
<br />
System.Reflection.Assembly a = System.Reflection.Assembly.LoadWithPartialName("System.Windows.Forms");<br />
<br />
Type t = a.GetType("System.Windows.Forms.TextBox", true, false);<br />
|
|
|
|
|
Thx it worked like a charm.
|
|
|
|
|
And after you get the Type like Corrina said, then you can use a number of ways to instantiate it, like Activator.CreateInstance . See the .NET Framework SDK documentation for more ways, like getting the constructor with a certain parameter list and calling that to create a new instance with the parameters you want.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I know that. Then I can use various methods to be able to execute methods.
I can even load an unknown dll and search it find and class and call methods.
So I know about the capabilities.
As I replied to Corrina.
Yes and I allways get an TypeLoadException.
The problem is that the Type.GetType method searches the executing assembly in this case an testlibrary.
"An unhandled exception of type 'System.TypeLoadException' occurred in xmltestlibrary.dll
Additional information: Could not load type System.Windows.Forms.TextBox from assembly TestLibrary, Version=1.0.1589.1600, Culture=neutral, PublicKeyToken=null."
I dont get it. I've looked at examples but they arent very helpfull.
|
|
|
|
|
Notice how it's trying to load a Type that should be in the System.Windows.Forms.dll assembly? You have to specify a correct partial or full Type, like:
Type t = Type.GetType("System.Windows.Forms.TextBox, System.Windows.Forms"); Notice the assembly name in there, too? If you want to get specific, you can also include the version, culture, and publicKeyToken attributes.
There are plenty of examples - even in common .config sections do you specify the fully-qualified Type name and either a partial of full assembly reference. If you don't specify the assembly, then it assumes the Type name is in the currently executing assembly.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
HI!
I want to detect CPU usage and Net speed using PerformanceCounter, but the vaules are always 0.
For net speed here is the code:
private void GetNetSpeed()
{
PerformanceCounterCategory category = new PerformanceCounterCategory("Network Interface");
foreach(string adapter in category.GetInstanceNames())
{
if(adapter == "MS TCP Loopback interface")
continue;
PerformanceCounter netRCounter = new PerformanceCounter("Network Interface","Bytes Received/sec",adapter);
PerformanceCounter netSCounter = new PerformanceCounter("Network Interface","Bytes Sent/sec",adapter);
txtSys.Text += "Recived: " + netRCounter.NextValue().ToString() + " b/s.";
txtSys.Text += "Sent: " + netSCounter.NextValue().ToString() + " b/s.";
}
}
Could anybody tell me way is always 0?
HELLO!
|
|
|
|
|
would like to know how to get hold of excel cells using the Excel namespace?
Is there anyone with ideas, I need to read a lot of data and manipulate it from a spread sheet.
thanks
Dries
|
|
|
|
|
Use the Microsoft PIAs (Primary Interop Assemblies) that can be downloaded from http://msdn.microsoft.com[^] for Office XP or that come on the CD with Office 2003 Professional. Add a reference to Microsoft.Office.Interop.Excel.dll and create a new instance of the ApplicationClass in the Microsoft.Office.Interop.Excel namespace. This creates a new instance of the Excel application (invisible at first - set its Visible property to true to display it).
Then load a new workbook or template using Workbooks.Open . That will give you a Workbook instance. Cast this to a WorkbookClass and use the Sheets property to get the Sheet you want. Use the Item property to get a Worksheet . Cast this to a WorksheetClass and you can now get the Cells property. This is all documented in the Office Programming Reference what to do and where to go from there (like the various ways you can reference cells).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
i have two classes, one serverCommands and one socketServer. once i have created a new instance of the serverCommands class in socketServer, i want to be able to type something like serv (my new instance of serverCommands) .CreateSocket(socketName) and create a socket according to the name specified. is this possible?
if so, how? this could be used with other stuff two as there is some things that would be much quicker to create with a function. should the functions be private, public, static or what? (and what do they mean? )
also is it possible to say something like Console.WriteLine(serv.Version()); and have it getting an output from the function Version and displaying it in the Console? i understand references have something to do with this, and returns...
thanks for help with any of the above,
surgeproof
-------------------------------------------------------
ithium is the best.
'Science without religion is lame, religion without science is blind.' --Albert Einstein
'The pioneers of a warless world are the youth who refuse military service.' --Albert Einstein
|
|
|
|
|
This is all possible if you design your application right. It's your implementation.
As far as the access modifiers, you need to decide if you want any class to be able to call a method or get/set a property or not. You can see the differences between the access modifiers by reading Access Modifiers[^] in the Visual C# product documentation.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
thanks for the link, it helps. would you have a link to teach me about functions/etc. and referencing? i can't seem to find anything useful, so if you do know of a good one please tell.
thanks,
surgeproof
-------------------------------------------------------
ithium is the best.
'Science without religion is lame, religion without science is blind.' --Albert Einstein
'The pioneers of a warless world are the youth who refuse military service.' --Albert Einstein
|
|
|
|
|
Nothing useful? How about reading the .NET Framework SDK[^] for starters, not to mention any number of the countless books out there about the .NET Framework and the languages that target it, like C#? It's how many of us learned.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
thanks. will try
surgeproof
-------------------------------------------------------
ithium is the best.
'Science without religion is lame, religion without science is blind.' --Albert Einstein
'The pioneers of a warless world are the youth who refuse military service.' --Albert Einstein
|
|
|
|
|
Hi to all,
Can somebody tell me some usefull links where I can get help for working with XML files. In my WinForm application I creating xml file and wite some data to it. But when I lauch my program again it rewrites the existing file. How can I do that new nodes would be written to the end of the document? And also I want to read all these nodes, what is the best way to them all, one for one? Thanx.
www.xedom.com
|
|
|
|
|
Everything you need to know is under the System.Xml[^] namespace.
Basically, you want to check if the .xml file exists, if so you want to insert your new data, if not create a new .xml file. Don't create a new file everytime, you'll write over your data.
The bulk of your methods might come from this class, XmlTextWriter[^]
Good luck.
R.Bischoff
.NET, Kommst du mit?
|
|
|
|
|
I'm really confused.
I'm new to forms in c#, but i have used c# and forms before, just not together.
i want to draw a rectangle on the screen so i used this code in a button click event
Pen NewPen = new Pen(Color.Red,10);
Graphics g = this.CreateGraphics();
g.DrawRectangle(NewPen,200,200, 50,50);
this does exactly what i would expect, but it's not very interesting so i added some lines:
Pen NewPen = new Pen(Color.Red,10);
Graphics g = this.CreateGraphics();
int X = this.Width/2;
int Y = this.Height-100;
g.DrawRectangle(NewPen,X,Y, 50,50);
Now i don't get the rectangle, but if i step through the code i can see a flash as it gets drawn and then when the form is displayed it dissappears.
I revert to the original code and now that doesn't work either, but if i paste the code into a new project it works fine.
has anyone seen anything like this before?
I'm really confused, any help would be appreciated
russ
|
|
|
|
|
Perhaps you've turned double-buffered drawing on?
As a general rule, you shouldn't paint anything in response to a command. Instead, you should 'remember' (somehow) what needs to be painted, then paint it when Windows asks you to. Override the OnPaint method to handle this notification and do your painting.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
You have to override OnPaint (in a derivative class) or handle the Paint event (from a different class) and draw your rectangle based on some state variable (perhaps the Button.Click handler sets some variable to true, and your override for OnPaint draws a rectangle if that variable is true. If you don't, then each time the form (or any surface) is invalidated, your rectangle will disappear. So, in your form you'd do something like this:
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Graphics g = e.Graphics;
} Also, if you ever create a Graphics object or a Bitmap or something, dispose of it (i.e., call Dispose ) when you're done to release the native resources used by the class, otherwise you'll see a drop in performance after a while since memory isn't being freed (in some cases, not freed cast enough). Do not do this in the override for OnPaint or a Paint event handler, however - the caller will dispose the Graphics object when finished.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
thanks for the help, i'm putting it into the on_paint method.
i had realised that there was a painting issue going on, the cause of the confusion was the break point forcing a redraw of the form, but it took me a while to work that out.
for some reason i'd thought 2d drawing would take care of redraws etc by itself.
thanks again
russ
|
|
|
|
|
If i have a string like this :
string test = "<session> <appservers/> <parameters> <runtimestatistics>true" + "</runtimestatistics> <dateformat>dmy</dateformat> <sessionyearoffset>1980 " + "</sessionyearoffset> </propathwin32> <runprogram /> </parameters> <packages>"
Is it possible to check whether "runprogram", "parameters", "appservers" are in the string
With Indexof you can only check for one string: IndexOf("runprogram",0)
So i want to check whether several words are in a string
(actually i want to check whether my program can open the xml-file, so if those words are not in the xml-file then my program can't work)
Thx in advance
|
|
|
|
|
You could always load this string into an XmlDocument using the LoadXml method, or use a StringReader and then pass that to an XmlTextReader 's constructor overload.
However, a better way is to use XML in a way it's intended - using schemas. You should define a schema with a namespace and you can always validate if that XML document uses that namespace. If you can't change the schema, then simply use an XmlValidatingReader to read-in the XML document and embed a schema that matches the XML document structure you require. If the XML document doesn't validate against the schema, then don't use it.
Besides, nothing says you can't load the XML document to check what elements are present. If they aren't, don't continue to process the document. The XmlValidatingReader is the best way to go, however.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I'd just add that the string isn't XML, but it is XML-like. Maybe the poster should first investigate the use of XML as a better solution to the problem at hand...
-Jeff
here, bloggy bloggy
|
|
|
|
|
I guess I didn't look that closely, but your right! Of course, it often seems that we aren't provided with full details on this forum to help answer questions. I just "love" it when someone provides no details and asks why something doesn't work!
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I'm not saying you're wrong, just that I think maybe you should point the person to a good starting place for learning how to even use XML properly. They're pretty clearly going for XML, they're just not getting there.
-Jeff
here, bloggy bloggy
|
|
|
|