问题描述
您好,
我在vs2010和vs2013中使用c#语言,我的问题是..我写了一个计时器代码,所以如果我点击一个打开的窗口就像在聊天室中,然后计时器将文本放入其中,但我希望计时器自动选择聊天室窗口将其放入,这样用户只需要按下按钮而不是两者,按钮和聊天室之后带有白色文本栏的窗口在哪里输入文字。
有谁知道我的意思?
也许任何人都知道这个并且可以告诉我我需要写什么,对我来说真的很有帮助。 :)
最好的问候,
Andre
没关系。谢谢你的澄清。如果您需要进一步的帮助,我们需要先描述UI设计,然后再实现。我根本看不出任何困难,但在计时器中处理轮询数据有点棘手。
- 不要使用
System.Windows。 Forms.Timer
出于此目的,更好地使用System.Timers.Timer
; - 在计时器处理程序中,进行轮询。由于线程执行处理程序不在UI线程中,因此使用
Control.BeginInvoke
委派与UI相关的任何内容以响应轮询数据; - 使用
Control.Focus()
获取某些控件的方法,或者更好的方法是将其留给用户。
请查看我过去的答案:
[],
[]。
这里的主要问题是缺乏of ;基于模型.wikipedia.org / wiki / Pull_technology> 拉技术 太有限了,即使聊天也太不够了。但是,我不知道您的服务正在使用什么。在某些背景下,请阅读我以前的回答: []。
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
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 useSystem.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[^].
这篇关于如何自动选择打开的窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!