私人子Form1_OnFocus [英] Private Sub Form1_OnFocus

查看:91
本文介绍了私人子Form1_OnFocus的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!

我像一个任务栏.我只有一个问题:我希望程序执行以下操作:

Hi!

I''m making like a taskbar. I have just one problem: I want the program to do:

ShowInTaskbar = False

当它获得焦点时.

这行代码有效:

when it gets focus.

This line of code works:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load



我的问题是:是否可以编写这样的内容? :



And my question is: is it possible to write something like this? :

Private Sub Form1_OnFocus



我无法使其正常工作.

感谢您的帮助.



I can''t make it work.

Thanks for help.

推荐答案

因此,您可以从几个地方开始.首先,您可以转到此处:表单事件(System.Windows.Forms) [^ ]并浏览事件.只需为Focus查找,就会发现一个名为"GotFocus"的事件.

您可以做的另一件事是进入调试器,查看可用的事件.我会假设您正在使用Visual Studio,因为那是更常见的情况.在VS中的某个位置,您会找到属性"窗口.它看起来像这样: http://yfrog.com/f3propertie [ ^ ].

您会注意到闪电朝向顶部.如果单击该按钮,它将显示所有可以挂接到的事件.现在,这不会向您显示所有事件,但会向您显示很多事件.

但是,在这种情况下,GotFocus不是其中之一.因此,要挂钩它,您可以使用两种方法. Visual Studio的VB版本很不错,因为它仍然为您提供了代码编辑器中的下拉菜单以及所有可以挂接的事件.因此,进入表单的代码并查看左上方的下拉菜单.从中选择((Form1事件)")(或任何表单名称).然后,在右侧的下拉列表中,选择GotFocus事件.这将设置事件处理程序并添加代码.

不过,在以后的工作中,我将更深入地研究事件编程,并查看实现该事件的其他方法.而且,认真地说,如果您想了解某个控件,msdn始终是开始的地方.
So, there are a couple of places that you could start. First, you could go here: Form Events (System.Windows.Forms)[^] and look through the events. Just do a find for Focus and you''ll find an event called "GotFocus".

The other thing that you can do is go into your debugger and see what events are available. I''ll assume you''re using Visual Studio since that''s the more common. Somewhere in VS you will find the Properties Window. It looks like this: http://yfrog.com/f3propertie[^].

You''ll notice the lightning bold towards the top. If you click on that, it will show you all of the events that are available to hook in to. Now this will not show you all of the events but it shows you quite a few.

In this case, though, GotFocus is not one of them. So, to hook it, you can do it two ways. The VB version of Visual Studio is nice because it still provides you with drop-downs in the code editor with all of the events that you can hook. So, go into your code for the form and look at the top left drop-down. From it, select "(Form1 Events)" (or whatever your form name is). Then in the right drop-down, select the GotFocus event. This will set up the event handler and add the code.

For future work, though, I would look into Event programming more in depth and see the other ways you can do it. And, seriously, msdn is always the place to start if you want to know something about a control.


我的建议是尝试一下,看看".您拥有使用代码进行实验所需的所有工具,包括调试器.
My suggestion is "try it, and see". You have all the tools you need to experiemnt with your code, including a debugger.


这篇关于私人子Form1_OnFocus的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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