|
The project i am currently working on is receiving data through a TCPClient from a server. The server is sending messages to the clients. I have this part working.
When the server sends an initalization message, the client form received this message on a seperate thread. I then use Invoke to pass this message to the thread of the client form.
<br />
public delegate void InvokeData(DataMessageClass d);<br />
<br />
private void Client_DataReceived(object sender, DataMessageEventArgs e)<br />
{<br />
this.Invoke(new InvokeData(this.Data), new object[] { e.DataMessage });<br />
}<br />
<br />
private void Data(DataMessageClass dataMessage)<br />
{<br />
switch(dataMessage.MessageType)<br />
{<br />
case INIT:<br />
{<br />
break;<br />
}<br />
}<br />
What i would like to do is open the child form using ShowDialog ( to prevent the user from hiding it and interacting with the parent until its close ), but receive the additional messages on this child form instead of the parent form. When the message is a COMPLETE message, the child form will close and the parent will again listen for the INIT message to start the process over again.
I know that ShowDialog is blocking as it will block all additional messages comming in from the server until the child form is closed.
I have tried to assign the event on the child form however the messages are not received on the child until the for is close.
I have been able to make this work with the parent reveiving all the message and then passing them on to the child form. In order to make it work this way, i have had to use Show() which allows the user to hide the form behind the parent form.
I am at a loss as to what to try next.
|
|
|
|
|
You don't need to use ShowDialog(). Create the child form with something like this:
ChildForm child = new ChildForm();
child.owner = this;
child.Show();
From the help files:
When a form is owned by another form, it is minimized and closed with the owner form. For example, if Form2 is owned by form Form1, if Form1 is closed or minimized, Form2 is also closed or minimized. Owned forms are also never displayed behind their owner form.
Hope that helps.
Cliff.
|
|
|
|
|
Cliff,
I had stumbled on to this solution just as you replyed. Thanks, this as somewhat the effect i am after.
However, this still allows interaction to the parent form while the child form is visible and does not have focus (ie. i can access menu items). Is there anyway to prevent the user from access items on the parent form?
With ShowDialog(), if you were to try and bring the parent form into focus, the parent never get focus and the user can not interact with it. I suspect that this may be because ShowDialog() is blocking the parent form. Is there a way to duplicate this behavior with Show()?
Jason
|
|
|
|
|
Handle the event of focus of your parent form and then check if the child form is still alive. If so then cancel the current event and focus child else call base function for default focus behaviour.
Regards
Khalid
|
|
|
|
|
Jason V wrote: However, this still allows interaction to the parent form while the child form is visible and does not have focus (ie. i can access menu items). Is there anyway to prevent the user from access items on the parent form?
I suppose you could disable the parent form.
Alternatively, you could receive the data in a separate thread that passes it on via a delegate. When you create the child form, you change the delegate to the child, setting it back in Form.Closed.
Cliff.
|
|
|
|
|
Hi,
I upgraded my C# Windows form application project to Visual Studio 2005 and now my Deployment project no longer works correctly. From the administrator account I can install my windows application w/ no errors and I can run the program from the desktop shortcut w/ no errors. However, when one of the normal users logs on and trys to start my application by double-clicking the desktop shortcut, the following error occurs:
An installation package for the product AMCAT cannot be found. Try the installation again using a valid copy of the installation package "SetupAndInstallAMCAT.msi".
Note: AMCAT is the name of my Windows application.
Any help would be greatly appreciated!
Thanks,
Terri
|
|
|
|
|
I am a begginer in C# programming. I am trying to run a simple program made on C# but unable to see the output using messagebox control. i run the code and on form load, it should display a message "Sucessful". Everytime I run the program, it displays an error message "Form1.cs(82): The type or namespace name 'textbox1' could not be found (are you missing a using directive or an assembly reference?)".
Please help me in interstanding the error message and debugging it.
Thanks in advance.
Regards,
Mini
|
|
|
|
|
That error is telling you that you're trying to use Textbox incorrectly. Have you consulted the MSDN yet? (http://www.msdn.com) ...Whenever you run into a problem like that, the first place you're going to want to look is the MSDN. ...Now to answer your question, look up at your "using" statements at the top of your .cs file . If "using System.Windows.Forms" is not there, then you need to add it. (That's what it meant when it said
Form1.cs(82): The type or namespace name 'textbox1' could not be found (are you missing a using directive or an assembly reference?)
if that doesn't work, then you might want to consult the MSDN and look up "Textbox" with a C# language filter. It will bring up all the information that you would need to learn how Textboxes are used in C#
|
|
|
|
|
Very Very Thanks for your help Alaric.
|
|
|
|
|
You can get help for the errors directly in VS. Just select the error in the error list and press F1.
In your case I guess you've simply made a typo: Is the TextBox object you want to access really called "textbox1"? C# is case sensitive, so textbox1 is different from textBox1 ...
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
I didn't mention VS because he made no mention of using VS. He could be writing it in Notepad
|
|
|
|
|
i want to create a project.In form, add a url and get content of the page from that url
|
|
|
|
|
hoatien wrote: i want to create a project.In form, add a url and get content of the page from that url
I want to have cheeseburger and fries for lunch. Nice talking to you.
You might want to read the post at the "TOP" of the forum: How to get an answer to your question
|
|
|
|
|
Use WebBrowser control.
Regards
Khalid
|
|
|
|
|
Hello -
I am working with a datagrid in a Windows application that has a bool column with checkboxes. For certain rows, I want to add functionality to make the checkbox disappear depending on the value of another column.
First things first, i cannot make a selective cell invisible for the life of me. Can someone point me in the right direction? I have seen some posts about this for ASP.NET but nothing for windows forms.
Thanks,
Eric
|
|
|
|
|
there is no such direct function or property to disable or to make a cell invisible.you have to handle this task programmatically.chek your condition on grid click event or at valuechange event
sameer
|
|
|
|
|
Thanks for the reply Sameer.
I know there is not direct function or property and that this would have to be handled programmatically...however, I am even having problems doing this through any event or Paint/Edit override. If you have an example of how to do it, please forward on.
|
|
|
|
|
Hi,
I've developed a .net 2.0 application and am now testing it on different computers. This usually works fine, but on some of the newest computers (core 2 duo laptops from Dell) the program just seems to randomly pop-up an error message saying that my "application has encountered an error and needs to be closed". It doesn't say what kind of error was encountered, and when I drag away the window I can continue to use my program just fine. Any suggestions?
Thanks in advance!
|
|
|
|
|
Just a guess, but I would suspect that your program is multithreaded, and you have a bug accessing some shared structure (e.g. enumerating a collection). Your prorgam keeps running because only a background thread has faulted. There should be a Dr. Watson dump somewhere that might yield some clues...
The flaw shows up on core duos because you have two processors, so simultaneous access by different processors to the same data can happen...
|
|
|
|
|
Yep, it is multithreaded, and the program shows this error when I start using just about all of the thread pool threads available (30+). So this might well be the problem. I've seen the Dr Watson dump but can't find any usefull info in it, could you point me where to look? I can post the dump if you want. Do you think I might be allright if I declare all variables I use as "volatile"?
Thanks for the help so far!
|
|
|
|
|
declareing the variables as volatile will just insure the compiler doesn't optimize their use in loops in a way that might cause strange problems, but it is a good idea for shared variuables (paricularly things like a boolean used to stop one thread from another thread). It won't however prenent things likje one tread incrementing a variable will another thread is doing the same thing (causing, for instance, code to attempt to access beyond the end of an array or collection). For that you nead to use locks to force one thread at a time access. Any collections or arrays that are shared across threads should be protected by locking before making changes, collections should be the synchronized variation and be accessed by locking code.
This article[^] has some good explanations, tips and links to further resources.
|
|
|
|
|
Thanks very very much, I've been trying to figure this out all day. I thought volatile implied putting a lock statement on each variable, that's where I went wrong. Locking the variables manually seems to have solved the issue, thanks again.
|
|
|
|
|
are you using COM in your application.If Yes then check for their Version.it might create some Version problem.
sameer
|
|
|
|
|
No, I'm not using COM, but thanks for the help anyway!
|
|
|
|
|
Hi all,
In other languages we can use the term "parent" for referencing a member of a parent class. C# doesn't have it. In the following code, I post an example of this question.
using System;
namespace NS
{
public class A
{
public static void Main() {
B b = new B();
C c = new C();
c.mc();
}
}
public class B
{
public void mb() {
Console.WriteLine("I'm in class B");
Console.Read();
}
}
public class C
{
public void mc() {
}
}
}
Any idea to do it?
Let the life to be fluent in you. SER
|
|
|
|