473,418 Members | 2,052 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,418 software developers and data experts.

odd behaviour double click label v button

Hi,

This is an odd one. I've been struggling to get "double click" to work well
for my controls.

The same event handler works perfectly for buttons, but not for labels.

Can anyone tell me why not?

Below is an working VB.Net example to illustrate what I mean.

regards

Neil.
>>>>>>>>>>>>>>>>>>>


Public Class Form1

Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()

MyBase.New()

'This call is required by the Windows Form Designer.

InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)

If disposing Then

If Not (components Is Nothing) Then

components.Dispose()

End If

End If

MyBase.Dispose(disposing)

End Sub

'Required by the Windows Form Designer

Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer

'It can be modified using the Windows Form Designer.

'Do not modify it using the code editor.

Friend WithEvents Label1 As System.Windows.Forms.Label

Friend WithEvents Button1 As System.Windows.Forms.Button

Friend WithEvents Label2 As System.Windows.Forms.Label

Friend WithEvents Label3 As System.Windows.Forms.Label

Friend WithEvents Timer1 As System.Windows.Forms.Timer

<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

Me.components = New System.ComponentModel.Container

Me.Label1 = New System.Windows.Forms.Label

Me.Button1 = New System.Windows.Forms.Button

Me.Label2 = New System.Windows.Forms.Label

Me.Label3 = New System.Windows.Forms.Label

Me.Timer1 = New System.Windows.Forms.Timer(Me.components)

Me.SuspendLayout()

'

'Label1

'

Me.Label1.BackColor = System.Drawing.Color.FromArgb(CType(255, Byte),
CType(128, Byte), CType(128, Byte))

Me.Label1.Location = New System.Drawing.Point(192, 104)

Me.Label1.Name = "Label1"

Me.Label1.Size = New System.Drawing.Size(80, 23)

Me.Label1.TabIndex = 0

Me.Label1.Text = "Label"

Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter

'

'Button1

'

Me.Button1.BackColor = System.Drawing.Color.FromArgb(CType(255, Byte),
CType(128, Byte), CType(128, Byte))

Me.Button1.Location = New System.Drawing.Point(24, 104)

Me.Button1.Name = "Button1"

Me.Button1.TabIndex = 1

Me.Button1.Text = "Button"

'

'Label2

'

Me.Label2.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!,
System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0,
Byte))

Me.Label2.ForeColor = System.Drawing.SystemColors.ControlText

Me.Label2.Location = New System.Drawing.Point(40, 24)

Me.Label2.Name = "Label2"

Me.Label2.Size = New System.Drawing.Size(216, 48)

Me.Label2.TabIndex = 2

Me.Label2.Text = "Double Click Successful"

Me.Label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter

Me.Label2.Visible = False

'

'Label3

'

Me.Label3.Location = New System.Drawing.Point(40, 152)

Me.Label3.Name = "Label3"

Me.Label3.Size = New System.Drawing.Size(208, 80)

Me.Label3.TabIndex = 3

Me.Label3.Text = "Try double clicking on the button and the label. Both have
the same event handle" & _

"r. However, the label doesn't behave as anticipated and for some reason
requires" & _

" a ""triple click""."

Me.Label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter

'

'Timer1

'

Me.Timer1.Interval = 200

'

'Form1

'

Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)

Me.ClientSize = New System.Drawing.Size(292, 266)

Me.Controls.Add(Me.Label3)

Me.Controls.Add(Me.Label2)

Me.Controls.Add(Me.Button1)

Me.Controls.Add(Me.Label1)

Me.Name = "Form1"

Me.Text = "Form1"

Me.ResumeLayout(False)

End Sub

#End Region

Dim lastclicktime As DateTime

Dim lastclicked As String

Dim waittwoticks As Integer

Private Sub Double_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs)

'the equals checks if the sender is the same as the last clicked control
i.e. "button" or "label"

'also check if two events on the same control have occurred within the
allowed time period.

If Equals(lastclicked, sender.text) And
Now.Subtract(lastclicktime).TotalMilliseconds <
Windows.Forms.SystemInformation.DoubleClickTime Then

'if they have then show the "double click" label

Label2.Visible = True

Else : Label2.Visible = False

End If

lastclicked = sender.text

lastclicktime = Now

End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

AddHandler Label1.Click, AddressOf Me.Double_Click

AddHandler Button1.Click, AddressOf Me.Double_Click

Timer1.Start()

End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick

If Label2.Visible = True Then

If waittwoticks = 3 Then

Label2.Visible = False

Else : waittwoticks += 1

End If

Else : waittwoticks = 0

End If

End Sub

End Class
Nov 21 '05 #1
3 2385
Neil,

The double click work for almost every control different. There is a special
page on MSDN for that, I have not a link direct to it, and because in this
case I don't know the search string can you maybe look for it yourself.

Cor
Nov 21 '05 #2
Here is the link:

http://tinyurl.com/3hvox

But I wonder why the OP is not just subscribing to the DoubleClick
event of the label?

Chris

Nov 21 '05 #3
Chris Dunaway wrote:
Here is the link:

http://tinyurl.com/3hvox

But I wonder why the OP is not just subscribing to the DoubleClick
event of the label?

Chris


thanks Cor and Chris.

That table does pose more questions than answers.

My understanding was that there was no such thing as a "doubleclick" event
for either a label or a button, hence the need to check programatically for
the elapsed time between two consecutive clicks.
Now we find the CLR interprets the exact same code differently depending on
the nature of the sender?

IMHO that is an example of managed code removing the rights of the
programmer.

I would love to know the reasoning behind this.
Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Vlad | last post by:
Does anybody experience problems with .Net IDE? I have a lot of them. This is just a part: 1. Double click on any control displays HourGlass cursor for a second, then returns to Default. Only the...
0
by: ygy | last post by:
Hi,I want to make a control.It is made of a label(show the data) ,a image(as button) and a trackbar(change the label value).When i click the image,the trackbar show under the label.My control is...
3
by: Wang | last post by:
Here is the code for a webcontrol, quite simple: ------------------------------------------------------------------------------------------------------------- <%@ Control Language="c#"...
1
by: fd123456 | last post by:
The TextBoxes in ASP have a weird behaviour when it comes to handling carriage returns. You can try this : Create a Webform. On it, place a textbox, set it's TextMode property to MultiLine....
2
by: dunderhead | last post by:
Hello, I am having a problem with function and class syntax. I have one class (MakePanel1) that creates a button and label. The button-click event of the button is linked to a function...
4
by: peter | last post by:
I've come across a weird difference between the behaviour of the Tkinter checkbox in Windows and Linux. The issue became apparent in some code I wrote to display an image in a fixed size canvas...
3
by: J055 | last post by:
Hi I have a PlaceHolder control inside a FormView EditItemTemplate: <asp:PlaceHolder ID="phResponseText" runat="server"> <tr> <td> <asp:Label ID="lblResponseText"...
2
by: Radu | last post by:
Hi. I have a page with the following html: __________________________________________________________ <h1>Dynamic Controls Test</h1> <hr /> <asp:TextBox ID="txtProduct1" Text="txtProduct 1"...
1
by: daonho | last post by:
I tried to use javascript to trigger up the button click function when user press enter key from the textbox. This function work fine with a single button click such has login page. However, if the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.