如何自动选择打开的窗口? [英] How to automatic select a opened window?

查看:149
本文介绍了如何自动选择打开的窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我在vs2010和vs2013中使用c#语言,我的问题是..我写了一个计时器代码,所以如果我点击一个打开的窗口就像在聊天室中,然后计时器将文本放入其中,但我希望计时器自动选择聊天室窗口将其放入,这样用户只需要按下按钮而不是两者,按钮和聊天室之后带有白色文本栏的窗口在哪里输入文字。



有谁知道我的意思?



也许任何人都知道这个并且可以告诉我我需要写什么,对我来说真的很有帮助。 :)



最好的问候,

Andre

解决方案

AndréName写道:



好​​的,这是一个Windows窗体。我喜欢C#中的新人,但我已经对它有所了解,我现在并不是说我是专业人士,但我知道有些事情已经开始工作了。你也开始对C#一无所知,所以我现在也是,这就是为什么我不知道它的一切。但我仍然不知道该怎么做..我知道我解释它非常愚蠢,但我不知道如何解释它不同,所以你知道我的意思是尝试这样做。

有问题或意见吗?

没关系。谢谢你的澄清。如果您需要进一步的帮助,我们需要先描述UI设计,然后再实现。我根本看不出任何困难,但在计时器中处理轮询数据有点棘手。

  • 不要使用 System.Windows。 Forms.Timer 出于此目的,更好地使用 System.Timers.Timer ;
  • 在计时器处理程序中,进行轮询。由于线程执行处理程序不在UI线程中,因此使用 Control.BeginInvoke 委派与UI相关的任何内容以响应轮询数据;
  • 使用 Control.Focus()获取某些控件的方法,或者更好的方法是将其留给用户。




请查看我过去的答案:

Control.Invoke()与Control.BeginInvoke() [ ^ ],

Treeview扫描仪和MD5的问题 [ ^ ]。



这里的主要问题是缺乏of server push ;基于 客户端 - 服务器 模型.wikipedia.org / wiki / Pull_technology> 拉技术 太有限了,即使聊天也太不够了。但是,我不知道您的服务正在使用什么。在某些背景下,请阅读我以前的回答:网站帐户的应用'信息中心' [ ^ ]。



-SA


你的问题不明确,进一步解释会有所帮助。例如,您的应用程序是否为每个聊天使用不同的窗口?每个窗口都有自己的发送按钮。在说明问题之前,请尝试并更简洁地解释一下您的应用程序的作用。



但是如果您希望在窗口聚焦时自动选择一个窗口来控制。我认为你应该听窗口的Window Activated事件。你不应该需要一个计时器。



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

void Form1_Activated( object sender,EventArgs e)
{
// 在此处添加文字
}


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

解决方案

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


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.

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

void Form1_Activated(object sender, EventArgs e)
{
    // do the text addition here
}


这篇关于如何自动选择打开的窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆