zoukankan      html  css  js  c++  java
  • c# winform 设置winform进入窗口后在文本框里的默认焦点

    http://www.cnblogs.com/JuneZhang/archive/2011/04/19/2020585.html

    进入窗口后默认聚焦到某个文本框,两种方法:

    ①设置tabindex

    把该文本框属性里的tabIndex设为0,焦点就默认在这个文本框里了。

    ②Winform的Activated事件

    在Form的Activated事件中添加textBox1.Focus(), 即可获得焦点。

    private void Form1_Activated(object sender, EventArgs e)
    {
        textBox1.Focus();
    }

    TextBox是可以获得焦点的. 有几个前提:

    1. TextBox所属的窗体(Form)在可操作(Active)状态. 即用户选中了Form.
    2. TextBox的Enable属性,Visiable属性为True.

    刚开始时原以为在Form的Load事件中添加textBox1.Focus(),测试失败

    private void Form1_Load(object sender, EventArgs e)
    {
        textBox1.Focus();
    }

    因为在窗体加载时调用Focus()函数时, TextBox还未能成功的被显示到界面上。所以导致了失败。

  • 相关阅读:
    10. Regular Expression Matching
    9. Palindrome Number
    8. String to Integer (atoi)
    7. Reverse Integer
    6. ZigZag Conversion
    《设计模式
    《设计模式
    《设计模式
    《linux 计划任务》- cron
    《设计模式
  • 原文地址:https://www.cnblogs.com/kennyliu/p/3925661.html
Copyright © 2011-2022 走看看