Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
Hello,

I work with the c# language in vs2010 and vs2013, my problem is.. I wrote a timer code so if I click in a opened window like in a chatroom then the timer put the text in it, but I want that the timer automatically selects the chatroom window to put it in, so that the user just need to hit the button and not the both, the button and after the chatroom window with the white text bar where to type the text in.

Does anyone know what I mean?

Maybe anyone knows about this and could tell me what I need to write in, would be really helpfull for me. :)

Best Regards,
Andre
Posted
Comments
BillWoodruff 29-Sep-14 9:34am    
Unclear. What is the chatroom application: is that your application/code ? Is this WinForms. Describe the structure of your application.

If you are using some kind of Windows "hook" to locate other application's open windows, tell us about that.
hjghjghjjgj 29-Sep-14 9:46am    
Ok I thought it's unclear. :p Alright, I mean it's a chatroom in the internet, they use Java for it and the chatroom is a opened window form with a white textbar at the bottom. I write the code in here.. as solution.

So if I press the button on my windows form then I want that the text automatically detect and select the chatroom java windows form with the white textbar, how do I do that?
Yemi Dicy 29-Sep-14 9:54am    
Do you have a link to the chatroom ?
hjghjghjjgj 29-Sep-14 9:55am    
Yes, www.Knuddels.com

André Name wrote:

Ok, it's a Windows Form. I'm like new in C# but I know a bit about it already, I don't say that I am a pro in it now, but I know how some things to get to work already. You also started with no knowledge with C#, so me too now, that's why I can't know everything about it. But I still don't know how to do it.. I know that I explain it very stupid, but I don't know how to explain it different so that you know how I mean to try to do it.
Have a Question or Comment?
It's all right and kind of irrelevant. Thank you for the clarification. If you want further help, we would need to describe the UI design first, and then the implementation. I cannot see any difficulty at all, but the processing of polled data in a timer is a bit tricky.
  • Don't use System.Windows.Forms.Timer for such purposes, better use System.Timers.Timer;
  • In timer handler, do the polling. As the thread executing handler won't be in UI thread, use Control.BeginInvoke to delegate anything related to UI in respond to polled data;
  • Use Control.Focus() method to get to some control, or, even better, leave it to the user.


Please see my past answers:
Control.Invoke() vs. Control.BeginInvoke()[^],
Problem with Treeview Scanner And MD5[^].

Major problem here is the lack of server push here; pure client-server model based on pull technology is way too limited and way too insufficient even for the chat. However, I don't know what your service is using. For some background, please read my past answer: Application 'dashboard' for website accounts[^].

—SA
 
Share this answer
 
v3
Comments
hjghjghjjgj 29-Sep-14 13:11pm    
Alright that seems helpfull for me now, I will take a look on it tomorrow, because it's late in here now. But I think this could help me a lot and if I solve my problem with this then I share it in here and let you know how I did it with your answers.

Thanks anyway!
Sergey Alexandrovich Kryukov 29-Sep-14 13:25pm    
No problem. I feel you will need some follow-up questions, but you rather may want to ask them as you go. They will be welcome anyway.
—SA
You question is not clear, further explanation would help. For example, does your application make use of different windows for each chat ? Does each window have it's own "Send" button. Try and explain more concisely what your application does first before stating the problem.

however if you want a window to be come control to be automatically selected when a window is focused. i think you should listen to the Window Activated event of the window. You shouldn't need a timer for that.

C#
public Form1()
{
    this.Activated += new EventHandler(Form1_Activated);
}

void Form1_Activated(object sender, EventArgs e)
{
    // do the text addition here
}
 
Share this answer
 
Comments
hjghjghjjgj 29-Sep-14 9:49am    
I don't think that is that what I need, that only opens another windows form of my own doesn't it? Take a look on my timer solution, I pasted it in here, maybe then you know what I mean and take a look on my answer under BillWoodRuff, there I wrote what I exactly want to try to get to work. :(

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900