如何在运行时按下按钮验证? [英] How Can I Verify If A Button Was Pressed In Run Time?

查看:107
本文介绍了如何在运行时按下按钮验证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果你能找到或知道任何事情请帮助我,谢谢:)



我有两个按钮打开相同的表格,这个表格有一个gridview,当选择该行将根据所选按钮显示不同文本框中的数据

If you can find or know anything please help me, Thanks :)

I have two buttons that open the same form , this form has a gridview that when selecting the line will display the data in different textbox according the selected button

推荐答案

错误的方法。你试图想象它背后的一些拉技术,与实际情况相比,这将更糟糕,更糟糕,更糟糕。一切都已基于推送技术。请参阅:

http://en.wikipedia.org/wiki/Pull_technology [< a href =http://en.wikipedia.org/wiki/Pull_technologytarget =_ blanktitle =New Window> ^ ],

http://en.wikipedia.org/wiki/Push_technology [ ^ ]。



而不是检查任何东西,你只需处理控件实例调用的事件。即使控件实例引用在事件参数实例中可用,您的句柄也会接收(此引用属于对象类型,通常称为 sender ),很少使用此引用,因为每个控件实例通常都有一个单独的处理程序;并且您可以向每个控件或其他对象的每个事件实例的调用列表添加任意数量的不同处理程序。你是决定这一点的人。



你真的需要学习.NET事件来理解它。请参阅:

https:// msdn .microsoft.com / zh-CN / library / edzehd2t%28v = vs.110%29.aspx [ ^ ],

http://www.tutorialspoint.com/vb.net/vb.net_event_handling.htm [ ^ ]。



此CodeProject可以在第一步也很有帮助,但请记住,它过于简单化,并未涵盖现实生活中可能需要的所有内容:循序渐进:VB.NET中的事件处理 [ ^ ]。br />


我没有在此添加我自己的说明性代码示例。如果我知道 Button 的意思,我很乐意这样做。惊讶吗?这是正确的:即使你可能认为Button是一个有效的类型名称,这是错误的:在.NET FCL中,有几个不同的不相关的Button类型使用这个单词作为一个简单的类型名称,但完整类型名称是不同的,具体取决于UI库。所以,下次请总是指定一个完整的类型名称,至少一次。



我觉得你不需要它。相反,只需学习与事件相关的一般主题,然后只需阅读 Button 类型的MSDN文档页面即可。你需要的事件几乎无处不在,名为点击;在派生类型中,您通常可以覆盖虚拟方法 OnClick ,作为处理事件的明显替代方法。如果你调用 base.OnClick ,仍会使用事件调用的原始机制,如果你不调用它,你可以有效地关闭事件,并且只能依赖于重写方法的代码。



这就是全部。



-SA
Wrong approach. You are trying to imagine some pull technology behind it, which would be much, much worse, unacceptably bad, compared to what it really is. Everything is already based on push technology. Please see:
http://en.wikipedia.org/wiki/Pull_technology[^],
http://en.wikipedia.org/wiki/Push_technology[^].

Instead of "checking" anything, you just handle events invoked by control instances. Even though the control instance reference is available in the event arguments instance your handle receives (this reference is of the object type and is usually called sender), this reference is rarely used, because each control instance is typically given an individual handler; and you can add any number of different handlers to the invocation list of each event instance of each control or other object. You are the one to decide on that.

You really need to learn .NET events to understand it all. Please see:
https://msdn.microsoft.com/en-us/library/edzehd2t%28v=vs.110%29.aspx[^],
http://www.tutorialspoint.com/vb.net/vb.net_event_handling.htm[^].

This CodeProject can also be helpful at first steps, but keep in mind that it is overly simplistic, does not cover all you may need in real life: Step by Step: Event handling in VB.NET[^].

I'm not adding my own illustrative code samples to this. I would gladly do it if I knew what did you mean by Button. Surprised? That's right: even though you may think that "Button" is a valid type name, this is wrong: in .NET FCL, there are several different unrelated "Button" types using this word as a simple type name, but full type names are different, depending on the UI library. So, next time, please always specify a full type name, at least once.

I don't think you need it. Instead, just learn general event-related topics and then simply read the MSDN documentation page on your Button type. The event you need is nearly everywhere is named Click; in derived types, you can usually override a virtual method OnClick, as an apparent alternative to handling events. If you call base.OnClick, the original mechanism of event invocation still will be used, if you don't call it, you effectively turn events off and should rely only on the code of the overridden method.

That's all.

—SA


我建​​议如下:

您可以使用您要拨打的表格中的TAG-Property。

取决于您按下哪个按钮将为变量提供与TAG-Property不同的内容。

在表单内部,您只需要询问为这些属性赋予哪个值并启动不同的设置。

请注意:TAG的类型是对象。在表单中,您必须将其转换为所需的变量类型。



问候语

Ralf
I would suggest the following :
You can use the TAG-Property from the Form you want to call.
depending on which Button you press you will give Variable with a different content to the TAG-Property.
Inside the Form you only need to ask which value is given to These Property and start the different settings.
Please note : the Type of TAG is Object. In the Form you have to cast it into the needed Variable-Type.

Greetings
Ralf


这篇关于如何在运行时按下按钮验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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