|
There's nothing different about an MDI Form being painted. There is no seperate event for painting either.
Is your control on the MDI Parent form? Did you know that there is a MDIClient control on the Parent form? Is you control in the Controls collection of the MDIParent or the MDIClient? If it's the MDIParent, your control is probably being painted over by the MDIClient area control.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Is there a way to import regirtry files within C#?
this way i could update some settings myself, and then in C# just open up the registry to the necessary folder and import the files. This would save alot of messing around and i would be able to use the peice of code again.
Any ideas?
|
|
|
|
|
This is an example of a file exported from regedit:
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.ppt]
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.ppt\OpenWithProgids]
"PowerPoint.Show.8"=hex(0):
this is just for the file extension .ppt
Is there any way that i can use this?
|
|
|
|
|
I am not sure how this is done. I have been doing some searching and reading and I can't seem to get this to work. I am really bad with terminology, but if someone could point me in the right direction I would bw greatful...
Thanks,
Eric Garcia
|
|
|
|
|
Ok, just pass the textbox instance to the other class's constructor or a method in that class. For instance,
class ClassWithTextBox
{
private TextBox myTextBox = new TextBox();
ClassWithoutTextBox classWithout = new ClassWithoutTextBox();
classWithout.ChangeTextboxColor(myTextBox);
}
class ClassWithoutTextBox
{
void ChangeTextboxColor(TextBox textBoxToModify)
{
textBoxToModify.BackColor = Color.Red;
}
}
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Hallelujah! It's Ken Jennings!
Judah Himango
|
|
|
|
|
Here is a better explination...
private void FollowLink(object parameters)
{
CMTag_Spider.SpiderForm spiderform;
//Other code here
spiderform.txtOuput.AppendText("/tLink:" + link.AbsolutePath);
//Other code here
}
compiler:
Use of unassigned local variable 'spiderform'(CS0165)
The situation I have is that I am using a c# webspider class and calling it from a form I named SpiderForm. Because of the way the Spider was coded I am not sure that I want to make too many changed to it.
I thought there was a way to declare a form and then set that to the active form and then as long as the textbox was public I could access it.
What I am not sure about is how to assign the spiderform variable...
Thanks for the help,
|
|
|
|
|
Assign it by taking an instance of the class that actually contains the spiderform object, then accessing that variable (provided it's public). Another option is to make the variable static and public, then you don't need an instance of the class to access it.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Hallelujah! It's Ken Jennings!
Judah Himango
|
|
|
|
|
I have a program I am writing for my own personl use that takes an XML file and interprets it into a treeview, then if a secion is clicked it shows the information between the tags in a textbox. The problem im having is with this peice of code.
XmlTextReader document = initializeXmlReader();
while((document.Name != e.Node.Tag.ToString()) && (document.GetAttribute("Name")!= e.Node.Text))
{
document.Read();
}
All the tree nodes are made up of the elemets attributes, this code works partially to go through the document and find if the right attribute, but sometimes it returns null, and does not display the next catagory's text.
Here is some sample XML.
<?xml version="1.0" encoding="utf-8" ?>
<Main Name="Desktop Sidebar Help">
<![CDATA[ TEST TEST TEST ]]>
<Key_Cat Name="Overview">
<Sub_Topic Name="Context Menu">TestTestTest</Sub_Topic>
<Sub_Topic Name="Options"></Sub_Topic>
</Key_Cat>
<Key_Cat Name="Basic Panels">
<Sub_Cat Name="Communication">
<Key_Topic Name="Mail Checker Panel">
</Key_Topic>
<Key_Topic Name="Messenger Panel">
</Key_Topic>
<Key_Topic Name="Miranda IM">
</Key_Topic>
</Sub_Cat>
<Sub_Cat Name="Groups Panels">
<Key_Topic Name="Stack Group">
</Key_Topic>
<Key_Topic Name="Tile Group">
</Key_Topic>
</Sub_Cat>
<Sub_Cat Name="Media"></Sub_Cat>
<Sub_Cat Name="News"></Sub_Cat>
<Sub_Cat Name="Outlook Panels"></Sub_Cat>
<Sub_Cat Name="System"></Sub_Cat>
</Key_Cat>
<Key_Cat Name="3rd Party Panels">
<Sub_Cat Name="Media"></Sub_Cat>
<Sub_Cat Name="Media"></Sub_Cat>
<Sub_Cat Name="Media"></Sub_Cat>
<Sub_Cat Name="Media"></Sub_Cat>
</Key_Cat>
<Key_Cat Name="Skin Development">
<Sub_Cat Name="Media"></Sub_Cat>
<Sub_Cat Name="Media"></Sub_Cat>
<Sub_Cat Name="Media"></Sub_Cat>
</Key_Cat>
<Key_Cat Name="Plugin Development">
<Sub_Cat Name="DS SDK Documentation Forum - About"></Sub_Cat>
<Sub_Cat Name="Creating/Adding a Panel">
<Key_Topic Name="Creating an Empty Panel"></Key_Topic>
<Key_Topic Name="Adding Your Panel to Desktop Sidebar">trdtfgrgbergbergbergber</Key_Topic>
</Sub_Cat>
<Sub_Cat Name="Creating a Panel Installation File "></Sub_Cat>
<Sub_Cat Name="Publishing Your Panel"></Sub_Cat>
<Sub_Cat Name="Using Components"></Sub_Cat>
<Sub_Cat Name="Reference"></Sub_Cat>
<Sub_Cat Name="FAQ"></Sub_Cat>
</Key_Cat>
<Key_Cat Name="FAQ">
<Sub_Cat Name="Media"></Sub_Cat>
<Sub_Cat Name="Media"></Sub_Cat>
<Sub_Cat Name="Media"></Sub_Cat>
</Key_Cat>
<Key_Cat Name="Universal Help Engine">
<Sub_Cat Name="Media"></Sub_Cat>
<Sub_Cat Name="Media"></Sub_Cat>
<Sub_Cat Name="Media"></Sub_Cat>
<Sub_Cat Name="Media"></Sub_Cat>
</Key_Cat>
<Key_Cat Name="About Universal Help Engine">
<Sub_Cat Name="Media"></Sub_Cat>
<Sub_Cat Name="Media"></Sub_Cat>
<Sub_Cat Name="Media"></Sub_Cat>
<Sub_Cat Name="Media">TESTTESTTEST</Sub_Cat>
</Key_Cat>
<Location ID="http://"><Location>
</Main>
I've been testing it by just clicking the first few treenodes that have a different attribute. But most of the time only one or two will work before it is just stays on the same thing for anything else I click. This is really bothering me. I edited out the text that was inbetween the tags, for length problems in this posting.
Sample of what its doing.
Tree
Desktop Sidebar
--OverView
---Context
---Options
--BasicPanels
---Communication
----Mail Checker Panel
----Messanger Panel
----Miranda IM
and so on
When I click mail checker panel for instance, it will show up right. But then if I click messanger Panel, it will show up with Main Check Panels text instead of Messanger Panels Text, upon debugging I noticed that getattribute is returnning null sometimes, I beleive this is the problem. The text between the tags will, contain HTML which is parsed by the textbox/web browser i've incorpertaited.
Any help would be much apperiated. Also if more code is needed I can post it.
|
|
|
|
|
In general when I know exactly the keywords(about 300) I want to find should I use something like:
1)Regex(@"if|do|for|while|int|Int32|Int64...(about 300)") or
2)Regex(@"[_A-Za-z]+[A-Za-z]\w*] and follows searching in a hashtable?
|
|
|
|
|
Option 2 would be preferable, speed and maintainability are the biggest benefits.
Option 1 is simply out of the question. That's just a nightmare waiting to bite you.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
|
I have been banging my head against the wall on this for a couple of hours now.
I work with SQL usually and have that down to an artform, but i am working on a project that requires me to insert info into an access db, and i am trying like hell just to get a simple statement to work, but i cant find a hting in msdn or on the internet. Any suggestions?
______________________
Yes, I am the highly suggestable type.
|
|
|
|
|
What's the statement your trying to get working?
Keep in mind that Jet doesn't support named parameters, but it does support parameters. You just have to supply them in the exact same order that they appear in your SQL statement. Also, Jet doesn't support the full range of SQL syntax that SQL Server does.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
here is the code I am attempting to use:
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + DS + ";";<br />
string comma = "INSERT INTO comments (page,who,comment,email) VALUES (" + page + "," + name + "," + comments + "," + mail + ")";<br />
OleDbConnection con = new OleDbConnection(strConn);<br />
OleDbDataAdapter da = new OleDbDataAdapter(comma,con);<br />
OleDbCommand cmd;<br />
cmd = new OleDbCommand(comma, con);<br />
<br />
con.Open();<br />
cmd.ExecuteNonQuery();<br />
con.Close();
______________________
Yes, I am the highly suggestable type.
|
|
|
|
|
Looking at your code I can't see why it doesnt work.
I do have a couple of suggestions that might help.
1. The OleDbDataAdapter is not required to execute a simple command it is only required when performing operations on datsets.
2. I would use parameters instead of hard coding the values into your command string, problems will occur if you have special characters in the varaiables such as quota marks. To do this the code will look something like below. (NOTE: You need to set the appropriate varaibale types for each parameter, I have guessed at what they might be)
3. I would recommend enclosing field names in square brackets as some words are reserved, see below.
string comma = "INSERT INTO comments([page],[who],[comment],[email]) VALUES (paramPage, paramName, paramComment, paramMail);"
OleDbConnection con = new OleDbConnection(strConn);
OleDbCommand cmd = new OleDbCommand(comma, con);
cmd.Parameters.Add("paramPage", OleDbType.Integer).Value = page;
cmd.Parameters.Add("paramName", OleDbType.VarWChar).Value = name;
cmd.Parameters.Add("paramComment", OleDbType.VarWChar).Value = comments;
cmd.Parameters.Add("paramMail", OleDbType.VarWChar).Value = mail;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
|
|
|
|
|
use single quotes :
VALUES ('" + page + "','" + name + "','" + comments + "','" + mail + "')";
|
|
|
|
|
Hi,
the following is an excerpt of a program, showing the part that starts another application:
<br />
System.Diagnostics.Process process = new System.Diagnostics.Process();<br />
process.StartInfo.Arguments = args;<br />
process.StartInfo.FileName = filepath;<br />
process.Start();
Filepath directs to a program called webLCR. Later I want to check whether this application has been closed. I’m using process.HasExited . The problem is, that HasExited returns true even if the process is still running. In deed it does after the process has been started. When using another application (I tested MS Word XP) instead of webLCR and everything works fine (false when running, true when closed). Is this a known problem? Any other possibilities to check if the program is still running or not?
My System:
Windows XP Serviepack 2
Visual Studio .net 2002
Thanks
|
|
|
|
|
The question becomes what is "webLCR"? The name would suggest a web application of some kind, maybe a Java app? Is your filepath pointing to an .EXE file?
This is not a bug. The problem can show up if you're monitoring an application that launches another application that you actually see. The first application can then quit, leaving the UI application that you see running. This would result in the behavior that your seeing. If you try and monitor the installation of an .MSI, this behavior is what you'd see.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
webLCR is a web least cost router. The filepath is pointing to an .exe file. But of course it may be that webLCR.exe launches another application and quits itself at startup. If I look at what webLCR does this seems to be quite probable. Thanks for the reply. I'm trying to get a handle on that other process now, so that I can check, whether it has exited or not. Any other (better) suggestions?
|
|
|
|
|
It works, thanks for the reply again.
|
|
|
|
|
Greetings,
This is my first post to the forum. I am a relatively new programmer and hope that my questions aren't too simple or obvious for someone at my level. I think I am getting the hang of it but am wrestling with Invoking back to the Main Thread. I have some fundamental questions that would help me understand the basics. I trust someone here will have the right answers.
From what I understand so far each Form runs in its own thread and each of its controls run on their own threads. I wish that we were in person so that you could stop me right here if I'm wrong but I will continue with my questions based on that premise which leads me to my first question.
1. When the Application.Run() method (in the main entry point for the application.) runs the Form passed to it, is there now 2 threads running? The App thread and the Form's thread? Or does the Form's thread become the MAIN THREAD?
Either way there is a Main Thread. So, when other threads are run from the main thread they need to Invoke() or BeginInvoke() back to the main thread, as they need to change variables in the app's main thread or else the change only seems to occur in the context of the thread making the changes. Now, if this is true then my next question is this:
2. Is it normal to have a large amount of EventHandlers in the main thread (main form?) for the other threads to invoke back to?
Let's say I have 40 classes that need to call back to the main thread with invoke. Is it normal to pass the main thread object into their constructor so that they can reference the main object? Something like this:
Form2 frm2 = new Form2(this);
This is how I have been doing it and it just seems messy. I mean, it just doesn't seem like I'm doing this right. If this is normal (or good coding practice) then my next question is this... and it is real basic so please don't laugh! lol
3. When you pass an object into another (or a method I would presume) does that object get copied into a new area in memory?
I know that there is a ref keyword that only sends a reference to the same memory. If this is the case why don't I see the ref keyword all over the place? It seems like it is rarely used. Even in places where it seems like it should have been used it isn't. Is there a reason for this? With that in mind my next question is this:
4. If passing my main-thread-form into each of my 40 class's constructor (as shown above) does that mean that I now have 41 main-thread-form-objects in memory? If so, wouldn't it be better to:
Form2 frm2 = new Form2(ref this);
...and use the reference to invoke off of?
I know these are fundamental concepts and I have been trying to get answers to this but none of the books I have give me the straight-dope on the practical usage. And I ask the book a question and it just sits there!
5. If passing the main-thread-form into every other class that needs to talk with it isn't the right way to do this then what is?
Let's say I have 500 classes that need to either change vars in the main class or invoke back to the main-thread-form. It seems ridicules to be passing it into the constructor like this. Especially if each one has a separate copy of the main-object.
6. Is the answer some kind of static object which contains the instance of the object? Thus avoiding all the copying and passing?
I haven't done that yet as it doesn't make sense either.
If passing the main-thread-form around like this is, indeed, the way to construct an app I would be totally cool with that and continue on my way. But it doesn't seem right and I hope you can point me in the right direction.
EB
|
|
|
|
|
From what I understand so far each Form runs in its own thread and each of its controls run on their own threads. I wish that we were in person so that you could stop me right here if I'm wrong but I will continue with my questions based on that premise which leads me to my first question.
Forms don't have threads, applications do. All controls have Window procedures which receive messages from the OS. You need (atleast) a thread to act as a message pump, to receive the messages and process them. You can create as many threads as you want. When you call Application.Run from a particular thread, that thread becomes the message pump for that form.
1. When the Application.Run() method (in the main entry point for the application.) runs the Form passed to it, is there now 2 threads running? The App thread and the Form's thread? Or does the Form's thread become the MAIN THREAD?
Application.Run starts a message loop on the current thread. So if you call Application.Run from Main(), the main thread is used as the message pumping thread. You can see that for yourself, Application.Run() blocks and doesn't return (until the app closes).
Either way there is a Main Thread. So, when other threads are run from the main thread they need to Invoke() or BeginInvoke() back to the main thread, as they need to change variables in the app's main thread or else the change only seems to occur in the context of the thread making the changes.
No, Invoke() and BeginInvoke() are needed if you are modifying the UI from a different thread. One of the basic laws of Windows is that you can modify the UI only from the thread that created it. Invoke() and BeginInvoke() are used to execute code on the thread that created the UI. It has nothing to do with normal variables. Each thread has its own stack, so local variables are not shared across threads, maybe your problem is because of this?
2. Is it normal to have a large amount of EventHandlers in the main thread (main form?) for the other threads to invoke back to?...
That's ok as long as it makes sense in that context. Again, you are passing a Form object, not a thread object.
3. When you pass an object into another (or a method I would presume) does that object get copied into a new area in memory?
I know that there is a ref keyword that only sends a reference to the same memory...
No. If it is a reference type (the Form object is), only the reference gets passed around, the whole object is not copied. It's like passing a pointer in C/C++. The ref keyword is used to achieve the effect of passing a pointer to a pointer in C/C++ (when you need to change the reference itself).
4. If passing my main-thread-form into each of my 40 class's constructor (as shown above) does that mean that I now have 41 main-thread-form-objects in memory? If so, wouldn't it be better to:
Form2 frm2 = new Form2(ref this);
...and use the reference to invoke off of?
Well, there will be only object in memory and 41 references to it. And the code you wrote won't compile, you can't pass "this" by ref as that would mean that you would be able to change "this" itself.
5. If passing the main-thread-form into every other class that needs to talk with it isn't the right way to do this then what is?
What do you do inside those 500 classes? If all they do is subscribe to events from the mainform, you can pass the mainform as part of the EventArgs.
6. Is the answer some kind of static object which contains the instance of the object?
A static object would solve the passing around of the main form.
Regards
Senthil
My Blog
|
|
|
|
|
Thanks for your reply it is much appreciated and man was it fast! It is taking me more time to digest than it took you to write that's for sure.
It looks like I have been miss-lead about some things. Your reply has already cleared up many of them but, alas, it has raised some other questions that I hope you will be so kind to help me with.
Forms don't have threads, applications do. All controls have Window procedures which receive messages from the OS. You need (atleast) a thread to act as a message pump, to receive the messages and process them. You can create as many threads as you want. When you call Application.Run from a particular thread, that thread becomes the message pump for that form.
This was a big one that cleared up a whole bunch of confusion (as you can imagine). So, just to make sure I get you right… If I (in VS.NET) create a: File->New->Project->C#->Windows Application I only have one thread. No matter how many new forms I make, I still only have one thread (the Main Thread) and all the controls on them are just passing messages to the (hidden) Windows Message Pump. The pump then sends those events, etc. to the respective handlers in the form's code.
No, Invoke() and BeginInvoke() are needed if you are modifying the UI from a different thread. One of the basic laws of Windows is that you can modify the UI only from the thread that created it. Invoke() and BeginInvoke() are used to execute code on the thread that created the UI. It has nothing to do with normal variables. Each thread has its own stack, so local variables are not shared across threads, maybe your problem is because of this?
This really helped too. Here is a question that would help even more with this. When an Asynchronous Callback "calls back" it calls back to the thread that starts it right? Even if the class that starts it was "newed" from a different form than the form being "newed" in the Application.Run? Man I hope that makes sense… I wish I new enough to ask the questions correctly. Maybe if I ask it like this… I new the first form of the app with Application.Run then that form news another form. In that second form I press a button that starts an AsyncCallback (from a socket). When that callback calls back it calls back to the (one and only) main thread. Or is it in a new thread?
No. If it is a reference type (the Form object is), only the reference gets passed around, the whole object is not copied. It's like passing a pointer in C/C++. The ref keyword is used to achieve the effect of passing a pointer to a pointer in C/C++ (when you need to change the reference itself).
Ok, I get this... thanks for clearing that up for me.
If all they do is subscribe to events from the mainform, you can pass the mainform as part of the EventArgs.
Aha... that will come in handy! Thanks again!
A static object would solve the passing around of the main form.
It is very cool to hear you say that and I have a hunch that it's because I don't fully understand proper application design. (I am learning as much as I can about this now.) My current method has been to create a main class (not Main()) with a bunch of sub-classes that it uses. My main class acts as sort of a hub and uses the other classes to perform the details of its "high-level" work. This method has served me well and I thought I was cooking along pretty good... until I ran into threads and these AsyncCallbacks.
I was using this "main-class" with "sub-classes" method so that they could access the main class's properties. They could also access other sub-class's properties through the main class reference that they now had local because I passed my main class into their constructor and set a private MyMainClass property in them. Is this reasonable? Or are you laughing right now at my stupidity? Lol Here is some psudo code to see what I've been doing so you can set me straight.
<br />
public class MyMainClass {<br />
public SubClass1 sc1;<br />
public SubClass2 sc2;<br />
<br />
public MyMainClass() {<br />
sc1 = new SubClass1(this);<br />
sc2 = new SubClass2(this);<br />
}<br />
}<br />
<br />
public class SubClass1 {<br />
private MyMainClass _mmc;<br />
public somevar<br />
<br />
public SubClass1(MyMainClass mmc) {<br />
_mmc = mmc;<br />
}<br />
}<br />
<br />
public class SubClass2 {<br />
private MyMainClass _mmc;<br />
<br />
public SubClass2(MyMainClass mmc) {<br />
_mmc = mmc;<br />
If (_mmc.sc1.somevar == something) {<br />
Do something important;<br />
}<br />
}<br />
}<br />
As my apps got bigger I found it really ugly to be passing my main class into each of my sub-classes. So I had the bright idea (maybe not so bright) of putting a "using" include at the top of each of my sub-classes that looked like this:
using mc = MyNamespace.MyMainClass;
Now I could just access the main class without passing it through the constructor. But, as I'm learning, it looks to me like that is only pointing the MyMainClass on the stack not the heap. I'm so damned confused. I hope this isn't as stupid as I feel it could be. Is this a bad way to go about it? How would you tackle this? Or should I just scrap this thinking altogether?
I am reading and learning as much as I possibly can but I don't know anyone who I can ask questions. I am very eager and grateful for your help.
Reguards,
EB
|
|
|
|
|
Maybe if I ask it like this… I new the first form of the app with Application.Run then that form news another form. In that second form I press a button that starts an AsyncCallback (from a socket). When that callback calls back it calls back to the (one and only) main thread. Or is it in a new thread?
I guess you got mixed up in terminologies, a callback can occur *on* a thread, it can't call a thread. You are confusing objects with threads, they are independent. For eg
<br />
class A<br />
{<br />
public void SomeFunc()<br />
{<br />
}<br />
}<br />
Now, class A can be instantiated by the main thread and can be accessed from a different thread. Calling a method on the object from a different thread does not mean it is "called on" the main thread.
As for AsyncCallbacks, they are implemented using threads in the ThreadPool, so, to answer your question, no, async call backs don't occur on the main thread, they occur on a thread pool thread.
As for the second part, did you look into inheritance? It is a language feature specifically for the situation where you want a class to do a few operations and other classes to enhance/modify the operations of the original class. In your case, it would be something like
<br />
class MyClass<br />
{<br />
}<br />
<br />
class Subclass1 : MyClass<br />
{<br />
}<br />
In the code above, Subclass1 contains all the data in MyClass, plus additional data that you've defined. If the above lines don't make any sense to you, I suggest you read a good "Object Oriented Programming" (OOP) book.
using mc = MyNamespace.MyMainClass;
This is only a shorthand for accessing MyMainClass, instead of typing using MyNameSpace at the top. It doesn't make any difference to the problem you're trying to solve. And you can access only static functions from mc.
Regards
Senthil
My Blog
|
|
|
|
|
Thanks for your time, knowledge, and patience Senthil. You’ve cleared up some confusion for me and I can enjoy my programming experience much better now!
EB
|
|
|
|
|