如何从VB.NET中的非单击Sub调用Click例程 [英] How do I call a Click routine from a non-click Sub in VB.NET

查看:89
本文介绍了如何从VB.NET中的非单击Sub调用Click例程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我试图调用点击例程,例如

 btnVoltsCurrent_Click( sender, System.EventArgs())



我使用另一个具有一些值的点击例程完成了此操作传递给它,我现在试图从没有传递给它的值的Sub()调用。

离开发件人不是声明错误....

HELP!



Glenn

解决方案

你的第一个错误是你的代码在Click中事件处理程序那是错的。你在那里的代码应该是自己的方法。这样,您可以从任何地方调用代码,包括Click事件处理程序(!),您不必担心如何通过向其传递垃圾参数来调用代码。

正如大卫那样正确地指出,正确的方法是从需要从其他非事件驱动方法调用的按钮单击处理程序中取出代码并将其放入单独的方法。



但是,如果你按时间并且需要做一个快速而肮脏的测试以确定它是否有效,你可以(我并不是说这是对的)用虚拟参数调用你的按钮点击处理程序。



 btnVoltsCurrent_Click(没什么没什么





但是如果你不需要发送者或事件arg参数,你只能这样做。


Hi All,

I am trying to call a click routine such as

btnVoltsCurrent_Click(sender, New System.EventArgs())


I have done this using another click routine which has some values passed to it, I am now trying to call from a Sub() that does not have the value passed to it.
Leaving with sender is not declared errors....
HELP!

Glenn

解决方案

Your first mistake is that you have your code in the Click event handler. That's wrong. The code you have in there should be in its own method. That way, you can call the code from anywhere, including the Click event handler(!), and you don't have to worry about how you're going to call the code in there by passing garbage parameters to it.


As David so rightfully pointed out that the correct way to do this is to pull out the code from the button click handler that you need to call from the other non-event driven method and put that into a separate method.

However, if you are pressed for time and need to do a quick and dirty test to see if it works, you could (and I am not saying that this is right) call your button click handler with dummy parameters.

btnVoltsCurrent_Click(Nothing, Nothing)



But you can only do this if you do not need the sender or the event arg parameters.


这篇关于如何从VB.NET中的非单击Sub调用Click例程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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