Click here to Skip to main content
15,901,035 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
Hi
Please advise if you know the answer.Otherwise, do not respond. Thankful.


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

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


and i use this dll in this Form:


VB
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?
Posted

1 solution

sara.solati68486 wrote:
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…

sara.solati68486 wrote:
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
 
Share this answer
 
v2
Comments
sara.solati68 2-Dec-11 14:22pm    
I first told:
Please advise if you know the answer. Otherwise, do not respond.


But you do not care!

You are not allowed in threads that I have
Get involved and irrelevant words

A Mason fool you. Here is a place for your nonsensical ideas.

Finally:you just ass... .

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900