点击事件不是“应用". [英] Click event is not Apply.

查看:77
本文介绍了点击事件不是“应用".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


请告知您是否知道答案.否则,请勿回复.感激.


我写了一个类,我只使用以下代码:

 导入 System.Windows.Forms
公共  Class1
    继承 Windows.Forms.Control
结束  



我以这种形式使用此dll:


 公共  Form1

     Dim  m_d,m_up,m_click  As  整数


    私人  Form1_Load( ByVal 发​​件人 As 系统.对象 ByVal  e  As  System.EventArgs)句柄  MyBase  .Load
        Class11.BackColor =颜色.蓝色
    结束 


    私有  Class11_Click( ByVal 发​​件人 As 系统.对象 ByVal  e  As  System.EventArgs) Handles  Class11.Click
        m_click = m_click +  1 
         .Text = "  & m_d& " & m_up& " & m_click
    结束 

    私有  Class11_MouseDown( ByVal 发​​件人目标 对象 ByVal  e 句柄 Class11.MouseDown
        m_d = m_d +  1 
         .Text = "  & m_d& " & m_up& " & m_click
    结束 

    私有  Class11_MouseUp( ByVal 发​​件人目标 对象 ByVal  e 句柄 Class11.MouseUp

        m_up = m_up +  1 
         .Text = "  & m_d& " & m_up& " & m_click

    结束 
结束  




如果运行该程序并单击dll Object.您将看到平均Click事件数是实际值的一半!!!

是什么原因导致此问题?

解决方案

sara.solati68486写道:

请咨询如果您知道答案.否则,请不要回应.



亲爱的萨拉!

这很不礼貌!人们回答您的帖子而没有回答您的问题,仅仅是因为您发布了很多无效的问题(包括这个问题).您发布问题时没有进行适当的准备,发布的信息不足,也没有使用调试器调查问题.难怪有人会尝试帮助您解决这些问题并真的帮助您,但是您显然不想听.如果您不想听建议,谁愿意为您提供帮助.

另外,回答问题也不是帮助您的最佳方法.让我们看看您的代码示例.

首先,您没有说明您的点击事件是什么意思.方法Class11_Click不是事件,但命名建议您将其用作某些对象的事件处理程序.您的代码不会显示您在何处添加事件处理程序.最有可能的是,这是在您自动生成的代码中完成的.我没有任何证据证明方法Class11_Click被用于添加到任何事件的调用列表中.唯一的证据就是您所说的将实际价值减半",这表明单击有时会调用您的方法.但这可以是其他方法或其他方法.错误地提出问题的方式使我怀疑一切,包括鼠标故障.您没有解释要做什么,因为……

sara.solati68486写道:

如果您运行该程序并单击dll,则对象为(http://en.wikipedia.org/wiki/Gibberish [ ^ ])!

您需要在所有事件句柄上放置一个断点,并使用调试器查看发生了什么.仅根据您显示的代码,我看不到任何问题.可能在其他地方.

一些问题:重复一些代码,例如分配给Me.Text的行.这是各种错误的邀请.永远不要重复任何代码片段.您可以在没有Designer的情况下创建方法吗? :-)

不要重复自己!请参见 http://en.wikipedia.org/wiki/Do_not_repeat_yourself [不可变的,因此这是一个荒谬的性能问题. (我必须解释为什么吗?)改为使用string.Format,它更易读并且不受此性能问题的影响.另外,您可以梳理格式本身:重复的空格根本对您没有帮助.

最后:您的名字不符合Microsoft的命名约定.实际上,大多数自动生成的名称都会失败,但是由Microsoft Designer生成的事实并不意味着您应该保留它们.您需要为所有内容赋予一个语义名称. VS重构在这里有很大的帮助,因此这样做并不是一件容易的事.至少在发布示例代码之前进行此操作.

—SA


Hi
Please advise if you know the answer.Otherwise, do not respond. Thankful.


I wrote a class.I only use the following code:

Imports System.Windows.Forms
Public Class Class1
    Inherits Windows.Forms.Control
End Class



and i use this dll in this Form:


Public Class Form1

    Dim m_d, m_up, m_click As Integer


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Class11.BackColor = Color.Blue
    End Sub


    Private Sub Class11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Class11.Click
        m_click = m_click + 1
        Me.Text = "       down=" & m_d & "      up=" & m_up & "     Click=" & m_click
    End Sub

    Private Sub Class11_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Class11.MouseDown
        m_d = m_d + 1
        Me.Text = "       down=" & m_d & "      up=" & m_up & "     Click=" & m_click
    End Sub

    Private Sub Class11_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Class11.MouseUp

        m_up = m_up + 1
        Me.Text = "       down=" & m_d & "      up=" & m_up & "     Click=" & m_click

    End Sub
End Class




If you run the program and click on the dll Object.You will see Number of Click event On average,is half the real value!!!

What causes this problem? How can it be solved?

Please advise if you know the answer. Otherwise, do not respond.



Dear Sara!

This is rude! People responded to your post without answering your question simply because you post a lot of invalid questions (including this one). You post your questions without proper preparations, posting not enough information, not investigating the problem using Debugger. No wonder some would try to help you to fix these problems and really help you, but you apparently don''t want to listen. Who would like to help you if you don''t want to listen the advice.

Also, answering the question is not the best way to help you. Let''s look at your code sample.

First of all, you did not indicate what click event do you mean. The method Class11_Click is not an event, but the naming suggests you use it as an event handler of some object. Your code does not show where you add the event handler. Most likely, this is done in your auto-generated code. I do not have any proof that the method Class11_Click was used to add to an invocation list of any event; the only evidence is your words about "half the real value", which suggests the click sometimes calls your method. But it can be some other method or whatever. Inaccurate way of posing your problems makes me suspect everything, including malfunction of your mouse. You did not explain a click on what do you do, because…

If you run the program and click on the dll Object

is gibberish (http://en.wikipedia.org/wiki/Gibberish[^])!

You need to put a breakpoint on all your event handles and see what''s going on using the Debugger. I cannot see a problem based just on the code you show. It could be somewhere else.

Some problems: you repeat some code, such as the line assigning to Me.Text. This is the invitation for all kind of bugs. No fragment of code should be repeated, ever. Can you create methods, without Designer? :-)

Do Not Repeat Yourself! See http://en.wikipedia.org/wiki/Do_not_repeat_yourself[^].

Did you know that you should not use string concatenation ''&'' repeatedly? Strings are immutable, so this is a ridiculous performance problem. (Do I have to explain why?) Use string.Format instead, which is more readable and free from this performance problem. Also, you could comb the format itself: your repeated blank spaces don''t help you at all.

Finally: your names fail to follow Microsoft naming conventions. Actually, most of the auto-generated names fail, but the fact they are generated by Microsoft Designer does not assume you should keep them. You need to give everything a semantic name. VS refactoring is a great help here, so it''s not a labor to do so. At least, do it before posting a sample code.

—SA


这篇关于点击事件不是“应用".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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