zoukankan      html  css  js  c++  java
  • winform:界面加载时自定义选中Button

    应用:实现窗体加载后自定义选中button按钮,并且按回车能响应该按钮的点击事件

    第一种办法:.Focus()

    注:要在窗体加载完毕后才执行的事件中使用才有效

     1 namespace FormTest
     2 {
     3     public partial class Form1 : Form
     4     {
     5         public Form1()
     6         {
     7             InitializeComponent();                                              
     8         }
     9         private void Form1_Shown(object sender, EventArgs e)
    10         {
    11             btnsecond.Focus();
    12         }
    13 
    14         private void btnfirst_Click(object sender, EventArgs e)
    15         {
    16             MessageBox.Show("first button");
    17         }
    18 
    19         private void btnsecond_Click(object sender, EventArgs e)
    20         {
    21             MessageBox.Show("second button");
    22         }
    23 
    24         private void btnthird_Click(object sender, EventArgs e)
    25         {
    26             MessageBox.Show("third button");
    27         }
    28     }
    29 }

    第二种办法:修改Tabindex

    打开窗体设计页面,打开vs工具栏中的视图,点击Tab键顺序选项,更改控件的tab顺序

    执行结果:(操作:执行,按下回车键)可以看到窗体打开时,选中的是second按钮,按回车键是响应的也是second按钮的点击事件

  • 相关阅读:
    关掉firefox(火狐)和palemoon地址栏自动加www.前缀功能【转】
    Maven入门指南(一)
    Linux 常用命令
    maven-编译速度优化
    monkeyscript
    GIT
    maven简介及基础使用
    使用xcrun打包iOS应用
    Mac系统下STF的环境搭建和运行
    npm介绍与cnpm介绍
  • 原文地址:https://www.cnblogs.com/ecake/p/8124078.html
Copyright © 2011-2022 走看看