SetFocus 百科内容来自于: 百度百科

Flash SetFocus 方法

[pre]public static setFocus(newFocus:
  Object) : Boolean
使 newFocus 参数指定的可选择(可编辑)文本字段、按钮或影片剪辑获得焦点。如果传递 null 或 undefined,则删除当前焦点。

可用性

ActionScript 1.0、Flash Player 5 , 按钮和影片剪辑的实例名称仅在 Flash Player 6 及更高版本中有效。

参数

newFocus:Object― 一个对象(例如,某个按钮、影片剪辑或文本字段实例),或者是一个字符串,该字符串指定某个按钮、影片剪辑或文本字段实例的路径。如果您传递指定路径的字符串,请将该路径置于引号内 (" ")。可以使用点或斜杠记号指定路径。如果要使用 ActionScript 2.0,则必须使用点符号表示。可以使用相对路径或绝对路径。

返回

Boolean― 一个布尔值;如果获得焦点成功,则为 true;如果失败,则为 false。

示例

在下面的示例中,当文本字段在浏览器窗口中运行时,它将在 username_txt 文本字段上获得焦点。如果用户未填写某个必需文本字段(username_txt 和 password_txt),则光标将自动将焦点定位在缺少数据的文本字段中。例如,如果用户未在 username_txt 文本字段中键入任何内容,则在单击姨峤挥按钮时,将出现一条错误消息,而且光标在 username_txt 文本字段中获得焦点。
[pre]this.createTextField("status_txt", this.getNextHighestDepth(), 100, 70, 100, 22);this.createTextField("username_txt", this.getNextHighestDepth(), 100, 100, 100, 22);this.createTextField("password_txt", this.getNextHighestDepth(), 100, 130, 100, 22);this.createEmptyMovieClip("submit_mc", this.getNextHighestDepth());submit_mc.createTextField("submit_txt", this.getNextHighestDepth(), 100, 160, 100, 22);submit_mc.submit_txt.autoSize = "center";submit_mc.submit_txt.text = "Submit";submit_mc.submit_txt.border = true;submit_mc.onRelease = checkForm;username_txt.border = true;password_txt.border = true;username_txt.type = "input";password_txt.type = "input";password_txt.password = true;Selection.setFocus("username_txt");//function checkForm():Boolean {if (username_txt.text.length == 0) {status_txt.text = "fill in username";Selection.setFocus("username_txt");return false;}if (password_txt.text.length == 0) {status_txt.text = "fill in password";Selection.setFocus("password_txt");return false;}status_txt.text = "success!";Selection.setFocus(null);return true;}
此示例中使用的 MovieClip.getNextHighestDepth() 方法要求 Flash Player 7 或更高版本。如果您的 SWF 文件包括第 2 版的组件,请使用第 2 版组件的 DepthManager 类代替 MovieClip.getNextHighestDepth() 方法。

VB SetFocus方法

将焦点移至指定的控件或窗体。

语法

object .SetFocus
object 所在处代表对象表达式,其值是“应用于”列表中的一个对象。

说明

对象必须是 Form 对象、 MDIForm 对象或者能够接收焦点的控件。调用 SetFocus 方法以后,任何的用户输入将指向指定的窗体或控件。
焦点只能移到可视的窗体或控件。因为在窗体的 Load 事件完成前窗体或窗体上的控件是不可视的,所以如果不是在 Form_Load 事件过程完成之前首先使用 Show 方法显示窗体的话,是不能使用 SetFocus 方法将焦点移至正在自己的 Load 事件中加载的窗体的。
也不能把焦点移到 Enabled 属性被设置为 False 的窗体或控件。如果已在设计时将 Enabled 属性设置为 False,必须在使用 SetFocus 方法使其接收焦点前将 Enabled 属性设置为 True

可使用SetFocus的部分控件

1.MDI窗体。
2.窗体
3.ADODATA 控件
4.Animation 控件
5.CheckBox 控件
6.ComboBox 控件
7.CommandButton 控件
8.所有数据(Data)控件
9.DateTimePicker 控件
10.DirListBox 控件
11.DriveListBox 控件
12.FileListBox 控件
13.HScrollBar 、VScrollbar 控件
14.FlatScrollbar 控件
15.ListBox 和 ListView 控件
16.TextBox 控件
17.Imagecombo 控件
18.Masked Edit 控件
19.OLE 容器控件
20.MSFlexGrid 和 MSHFlexGrid 控件(别把两个控件混一起了)
21.OptionButton 控件
22.PictureBox 控件
23. 属性页对象(Property Page )
24.RichTextBox 控件
25.Silder 控件
26. 用户自定义控件对象 (UserControl )
27.ActiveX 文档 (UserDocument)
28.TabStrip 控件
29.TreeView 控件
30.updown 控件
31.Window 对象
$firstVoiceSent
- 来自原声例句
小调查
请问您想要如何调整此模块?

感谢您的反馈,我们会尽快进行适当修改!
进来说说原因吧 确定
小调查
请问您想要如何调整此模块?

感谢您的反馈,我们会尽快进行适当修改!
进来说说原因吧 确定