Button.performclick()[通俗易懂]

Button.performclick()[通俗易懂] (1)WinForm中,Button按钮有PerformClick()方法,可以模拟用户单击鼠标.即button.PerformClick()生成按钮的事件。相关网站为:http://msdn2.microsoft.com/zh-cn/library/system.windows.forms.button.performclick(VS.80).aspx(2)在一些事件处理程序中,比如Fo

大家好,又见面了,我是你们的朋友全栈君。

 (1)WinForm中,Button按钮有PerformClick()方法,可以模拟用户单击鼠标. 即button.PerformClick()生成按钮的事件。相关网站为:http://msdn2.microsoft.com/zh-cn/library/system.windows.forms.button.performclick(VS.80).aspx

(2)在一些事件处理程序中,比如Form窗体的Click事件 Form_Click(parameter1,parameter2 )、Button按钮的Click事件Button_Click()等等,可以直接调用相应的按钮代码在其相应的事件处理程序中执行。先看下面两例:

事例1:Visual Basic

Private Sub button1_Click(sender As Object, e As EventArgs)
    ‘ If myVar is an even number, click Button2.
    If myVar Mod 2 = 0 Then
        button2.PerformClick()
        ‘ Display the status of Button2’s Click event.
        MessageBox.Show(“button2 was clicked “)
    Else
        ‘ Display the status of Button2’s Click event.
        MessageBox.Show(“button2 was NOT clicked”)
    End If
    ‘ Increment myVar.  
    myVar = myVar + 1
End Sub ‘button1_Click

事例2:
       Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim cust As Customer
        cust.Company = “Bottom-Dollar Markets”
        cust.Manager = “Elizabeth Lincoln”
        cust.Address = “23 Tsawassen Blvd.”
        cust.City = “Tsawassen”
        cust.Country = “Canada”
        cust.CustomerSince = #10/20/1996#
        cust.Balance = 33500
        Customers(0) = cust

        cust = New Customer()
        cust.Company = “Drachenblut Delikatessen”
        cust.Manager = “Sven Ottlieb”
        cust.Address = “Walserweg 21”
        cust.City = “Aachen”
        cust.Country = “Germany”
        cust.CustomerSince = #1/2/1994#
        cust.Balance = 2400
        Customers(1) = cust

        cust = New Customer()
        cust.Company = “Furia Bacalhau e Frutos do Mar”
        cust.Manager = “Lino Rodriguez “
        cust.Address = “Jardim das rosas n. 32”
        cust.City = “Lisboa”
        cust.Country = “Portugal”
        cust.CustomerSince = #12/22/1998#
        cust.Balance = 300
        Customers(2) = cust

        cust = New Customer()
        cust.Company = “Great Lakes Food Market”
        cust.Manager = “Howard Snyder”
        cust.Address = “2732 Baker Blvd.”
        cust.City = “Eugene, OR”
        cust.Country = “USA”
        cust.CustomerSince = #1/3/1998#
        cust.Balance = 6500
        Customers(3) = cust

        cust = New Customer()
        cust.Company = “QUICK-Stop”
        cust.Manager = “Horst Kloss”
        cust.Address = “Taucherstra遝 10”
        cust.City = “Cunewalde”
        cust.Country = “Germany”
        cust.CustomerSince = #1/1/1989#
        cust.Balance = 23400
        Customers(4) = cust

        cust = New Customer()
        cust.Company = “The Cracker Box”
        cust.Manager = “Liu Wong”
        cust.Address = “55 Grizzly Peak Rd.”
        cust.City = “Butte”
        cust.Country = “USA”
        cust.CustomerSince = #1/1/1999#
        cust.Balance = 23400
        Customers(5) = cust

        cust = New Customer()
        cust.Company = “White Clover Markets”
        cust.Manager = “Karl Jablonski”
        cust.Address = “305 – 14th Ave. S.”
        cust.City = “Seattle, WA”
        cust.Country = “USA”
        cust.CustomerSince = #5/11/1994#
        cust.Balance = 12000
        Customers(6) = cust

        cust = New Customer()
        cust.Company = “Wilman Kala”
        cust.Manager = “Matti Karttunen”
        cust.Address = “Keskuskatu 45”
        cust.City = “Helsinki”
        cust.Country = “Finland”
        cust.CustomerSince = #1/3/2000#
        cust.Balance = 2500
        Customers(7) = cust

        bttnNext.PerformClick()       执行bttnNext_Click()的功能
    End Sub

     Private Sub bttnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bttnNext.Click
        If currentIndex = CountCustomers() Then currentIndex = 0   把当前索引的值与Customers数组里的元素数量相比,如果它们相等,就把currentIndex = 0  
        Dim aCustomer As Customer
        aCustomer = GetCustomer(currentIndex)
        ShowCustomer(currentIndex)
        currentIndex = currentIndex + 1
    End Sub                  

    Function GetCustomer(ByVal idx As Integer) As Customer
        Return (Customers(idx))
    End Function            自定义函数,此函数返回当前记录值

    Function CountCustomers() As Integer
        Return (Customers.Length)
    End Function            自定义函数,此函数返回Customers数组里的记录数量

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/150165.html原文链接:https://javaforall.cn

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)


相关推荐

  • LoadRunner简明教程[通俗易懂]

    LoadRunner简明教程[通俗易懂]LoadRunner是什么LoadRunner是一个性能测试工具,它最初是Mercury公司的产品,后背HP收购。LoadRunner常用来做什么l 验证某系统在某环境下是否满足性能需求。l 通过测试,规划如何达到要求的性能指标。l 调整系统环境,进行性能测试,最终使性能达到最优。为什么要使…

  • sql2005置疑数据库修复_sqlserver2008数据库可疑

    sql2005置疑数据库修复_sqlserver2008数据库可疑–修改数据库为紧急模式alterdatabaseP897A20_dbsetemergency–但用户模式alterdatabaseP897A20_dbsetsingle_user–修复数据库日至dbcccheckdb(P897A20_db,repair_allow_data_loss)–恢复多用户模式alterdatabaseP89

  • WebClien使用国外代理服务器访问URL

    WebClien使用国外代理服务器访问URLusing(WebClientwc=newWebClient()){//代理服务器的IP和PortWebProxymyProxy=newWebProxy(CommonBLL.server,Convert.ToInt32(CommonBLL.port))…

  • 利用树莓派可以做什么?

    利用树莓派可以做什么?基于树莓派的运动检测报警系统传感报警的性能要求并不高,Arduino就能很好地完成,当然树莓派就更不用说了。打造一个简单的结合运动传感器和压电蜂鸣器的报警系统能够让你更快地了解树莓派的外部硬件利用方法;另外,在这个简单的项目中,你也能开始学一点Python了!这个项目所需要的部件不多,除了…

  • java flowable_Flowable流程引擎入门[通俗易懂]

    java flowable_Flowable流程引擎入门[通俗易懂]Flowable是一个流行的轻量级的采用Java开发的业务流程引擎。通过Flowable流程引擎,我们可以部署BPMN2.0的流程定义(一般为XML文件),通过流程定义创建流程实例,查询和访问流程相关的实例与数据,等等。Flowable可以灵活地添加到我们的服务、应用、架构中,可以通过引入Flowablejar包,或者直接使用Flowable的RestAPI来进行业务流程引擎的操作。Flowa…

    2022年10月20日
  • js页面跳转无效(js登录成功后跳转页面)

    或者window.open无效,setTimeout(function(){window.location.href=””;},100);就行了

发表回复

您的电子邮箱地址不会被公开。

关注全栈程序员社区公众号