|
Basically what I have is a an IM program. I set up a delegate function that monitors messages from a server, and upon a given message coming in, it launches a new message window. I created my own component that extends the PictureBox class which holds info about the user in the list, and one of the components is a pointer to the Message form. If it is null then a new one is created, otherwise it appends the chat messages to the richtextbox. Now my problem is, when the message comes through, I create a new Message form if the pointer is null, set the pointer to the new message, and call message.Show(). This seems to cause the Message form to hang and it doesnt display any of the controls. However if I do ShowDialog() it all works perfectly except only one message gets displayed until the user closes the window, obviously. Any thoughts? I'm thinking it has something to do from where I'm calling it. Here are some snippets of code:
The GraphicComponents.ImageComponent is my extended PictureBox class with the window property that points to an instance of the Message class, or null, of which Window gets or sets.
private static void ProcessTextMessage(string msg)
{
String[] data = msg.Split(':');
String from = data[0];
String message = data[1];
Message msgWindow;
Debug.WriteLine("Message received from: "+from+" MSG {"+message+"}");
foreach(GraphicComponents.ImageComponent member in users)
{
if(member.UserName.Equals(from))
{
if(member.Window != null)
{
msgWindow = member.Window;
msgWindow.AppendData(from,message);
}
else
{
//The Show method is in the constructor, did have it
//here but still did not work
member.Window = new Message(from);
msgWindow.AppendData(from,message);
}
break;
}
}
}
Any thoughts? Thanks.
|
|
|
|
|
I bet the thread on which you're calling Show doesn't have a message pump. Is it a thread that you created on your own or a threadpool thread?
For Show to work, the thread that calls it must be running a message pump (Application.Run(...) ). ShowDialog creates its own message pump, so that's why it worked for you.
As a solution, you can either start a message pump on the thread that calls Show or you can marshal the call to an UI thread using BeginInvoke .
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
The basic rundown of execution is as follows:
Majo is the main class of which Application runs
A new instance of the Web project is instantiated and called
The delegate functions are set up in Majo as well as Web
The functions then receive messages sent from the server and this is where I am calling the Show() for a new Message form
I have a setupHandlers() method in Majo that instantiates the methods for receiving the messages:
ClientServer.messageEvent += new Web.ClientServer.MsgHandler(ProcessTextMessage);
ClientServer.connectEvent += new Web.ClientServer.MsgHandler(ProcessConnectMessage);
ClientServer.statusEvent += new Web.ClientServer.MsgHandler(ProcessStatusMessage);
Then with the code above, the ProcessTextMessage is called with the user that sent the message as well as the message itself and this is where I'm creating a new Message form that is more or less an IM window. If I were to implement one of the above solutions, how would I go about doing so? I have not worked with BeginInvoke before but I have a feeling that this could be the problem. I Just find it odd that when it creates the Message window, you can see the outline of the controls but they don't get drawn. Thanks for the reply.
|
|
|
|
|
I think not calling BeginInvoke is the problem. To know why, you have to understand how Windows messages work. Basically, any action that you do on the UI, like clicking on a button, gets translated to a message and is posted to the application's message queue. Every Winforms application is provided with a thread on startup, whose only job is to process messages in the message queue, also called message pumping. Without processing messages, none of the UI commands will go to their handlers, in fact, the window itself won't get rendered properly. Your event handler runs on a thread pool thread, which doesn't have a message pump and that's why you get a half drawn window.
In .NET, Application.Run(...) in the Main method of any Winforms application does the message pumping.
Do you have a reference to the main form (or one of the controls in that form) inside ProcessTextMessage? If so, you can just do
private delegate void ProcessTextMessageDelegate(string text);
private void ProcessTextMessage(string text)
{
if (control.InvokeRequired)
{
control.BeginInvoke(new ProcessTextMessageDelegate(ProcessTextMessage), new object[] {text});
return;
}
form.Show();
}
control is either the Form object or some control that is in the form. The above piece of code results in another call to ProcessTextMessage, but this time on the UI thread (which means there is a message pump).
In the second call, InvokeRequired will be false, so it won't go inside the if block.
If you want to know more about BeginInvoke/InvokeRequired, you can take a look here[^]
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Can anyone Suggest how I can display Multiple Line text in ListView Cell.
|
|
|
|
|
Hi all, I know this is a known question but so far I have not found anything that will help me.
Is there a way to format the background color or the text color of a an entire row (or a cell would be better) based on the contents of a cell?
Think of this with an example, if I want to register students passing scores and 7 is the minimum passing score, I want to show all the students with score les than 7 in red, and all others in blue.
Thanks to all.
Best regards,
Jose Guay
|
|
|
|
|
Have a look at DataGrid.Item.
For instance, you could loop through the DataGridItem collection of your DataGrid and change its backGround property based on the cell's contents
Hope this helps
Regards,
Polis
Can you practice what you teach?
|
|
|
|
|
Thanks for the tip Polis, but DataGridItem is for ASP.NET and I'm using WinForms.
If you can point me into another direction I'd really appreciate.
Best Regards,
Jose Guay
|
|
|
|
|
Oh I am sorry Jose.
It seems that for a reason I got the impression that u were dealing with ASP.NET. Anyways, even better. Have a look here[^] for your answer. In fact, have a look at the remaining part of that website. I am pretty sure that any other questions you might have regarding the DataGrid control have already been answered in there. It's an excellent resource.
Hope this helps.
Regards,
Polis
Can you practice what you teach?
|
|
|
|
|
Can any one help me out how to write the code for addin in C# which creates a button on command bar and on click of that button entire document data shuld be saved to database.(not only word but this should work for every office application ppt,xls,doc..it shuld be generic to office applications)
text selection shuld be hidden from user how?
how to add customdocument property of an office application thru C#? this can be done i VB.NET but it has some issues with C# plz help me out
|
|
|
|
|
hi everyone i need to know how can i transfer the instant voice comes from the mic through the network to another client in chat Application any help with this ?
is there any one can help me with that option ?
Miss With The Best And Die Like The Rest
|
|
|
|
|
I'm writing a desktop security application which uses findwindow and showwindow API's to hide the desktop. The problem I have is if the user double clicks on the background the start menu appears. This also occurs if you set the policy value NoDesktop.
<br />
Hive: HKEY_CURRENT_USER<br />
Key: Software\Microsoft\Windows\CurrentVersion\Policies\Explorer<br />
Name: NoDesktop<br />
Type: REG_DWORD<br />
Value: 1<br />
Can anyone tell me how to stop the start menu from appearing?
Thanks in advance!
I reject your reality and substitute my own!
- Adam Savage, Mythbuster
- George W Bush
life is like a roll of toilet paper. The closer it gets to the end, the faster it goes.
|
|
|
|
|
I have a property grid which shows a set of properties of a Label the user selects. I can move the label around and resize. When the user changes one of the properties the PropertyValueChanged event handler is fired, and it sets a flag to true (I use this flag to check if the programs has to save the work on exit). However, when I resize or move the labels with the mouse the values of Location and Size in a property grid don't change, and the handler isn't fired.
The question - how to make the property grid show these changes?
|
|
|
|
|
You could try invalidating the PropertyGrid after the Label has been moved or resized. This might force the PropertyGrid to pick up the new values.
"I think I speak on behalf of everyone here when I say huh?" - Buffy
|
|
|
|
|
ok background. I've added buttons to a "navigation" user control...added this control to my form. How do I capture the controls Onclick events?
|
|
|
|
|
The control should capture the onclick events by itself. Where are you putting the control? Is it on a webform or winform? When I create a user control in a winform and click the buttons it responds as it should. What are you trying to do exactly?
-------------------------------------
Do not do what has already been done.
|
|
|
|
|
"Where are you putting the control?"
I drag and drop the control from "MyUserControls" on the toolbox to 'form1' or whatever.
"Is it on a webform or winform?"
It's a winform.
"What are you trying to do exactly?"
All I'm trying to do is make 'form1' respond to a click of a button on the control I added to the form.
So for instance....when you click the "personnel" button a label's text on 'form1' changes.
I'm trying to get a handle on where you put things.
Thank you!
|
|
|
|
|
If the button was in a user control so you must handle it's click event in the code of the user control itself.
|
|
|
|
|
Ok here's the statement I was missing....
the event handler I needed to add in the form was not just to the control, but to the control within the control.......I know it's a headache. Here's the statement
this.left_navigation1.linkLabel1.Click += new EventHandler(linkLabel1_Click);
Thats all I was missing....
Thanks all for you response!
|
|
|
|
|
The button exposes a Click event that you can subscribe to. From within the event handler for click, you can set the label's text to whatever you want. The code will look like
public class MainForm : Form
{
private Button button = new Button("Hai");
private Label label = new Label();
private void InitializeComponent()
{
button.Click += new ClickHandler(MainForm_buttonClick);
}
private void MainForm_ButtonClick(object sender, EventArgs e)
{
label.Text = "Bye";
}
}
Note that you don't need to write all the event wireup code, VS.NET does it for you. You only need to write code to set the label's text.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Hello. I'd like to write a CAB extracting/packing application, and am looking for MSZIP/LZX implementations (no matter what programming language it/they is/are in) or format specifications.
Thank you, and regards,
Stan
|
|
|
|
|
Good day all.
I have a two column ListView. I am having problems getting my ListView to display text in the 2nd column after the first row. The first row works fine for both columns 1 and 2. When I write data the second time. Row 2 column 1 writes the data but column 2 does not.
I am trying to use Listview.Items[0].Add( "xxxx" ); to update the 2nd column.
Thank you in advacne for your assistance.
|
|
|
|
|
try ListView.Items[n].SubItems.Add("xxxx")
|
|
|
|
|
Hi,
I am new in devloping applications for communication between devices.
How can i do serial port communication on .NET platform using C#(.NET Framework 1.1).
Please, let me know some good articles/books to learn "how to communicate to devices".
Thanks for some help.
Subrahmanyam.
|
|
|
|
|
There are a number of articles here on CodeProject, use the search article above with the word "Serial".
Here's one to get you started: http://www.codeproject.com/dotnet/DotNetComPorts.asp[^]
Gary
Marc Clifton: "In other words, VB is like a bad parent. It can really screw up your childhood."
|
|
|
|