473,832 Members | 2,194 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.

InitializeCompo nent()

'Add any initialization after the InitializeCompo nent() 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.Disp ose()

End If

End If

MyBase.Dispose( disposing)

End Sub

'Required by the Windows Form Designer

Private components As System.Componen tModel.IContain er

'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.Diagnos tics.DebuggerSt epThrough()> Private Sub InitializeCompo nent()

Me.components = New System.Componen tModel.Containe r

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.SuspendLayou t()

'

'Label1

'

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

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

Me.Label1.Name = "Label1"

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

Me.Label1.TabIn dex = 0

Me.Label1.Text = "Label"

Me.Label1.TextA lign = System.Drawing. ContentAlignmen t.MiddleCenter

'

'Button1

'

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

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

Me.Button1.Name = "Button1"

Me.Button1.TabI ndex = 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.Po int, CType(0,
Byte))

Me.Label2.ForeC olor = System.Drawing. SystemColors.Co ntrolText

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

Me.Label2.Name = "Label2"

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

Me.Label2.TabIn dex = 2

Me.Label2.Text = "Double Click Successful"

Me.Label2.TextA lign = System.Drawing. ContentAlignmen t.MiddleCenter

Me.Label2.Visib le = False

'

'Label3

'

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

Me.Label3.Name = "Label3"

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

Me.Label3.TabIn dex = 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.TextA lign = System.Drawing. ContentAlignmen t.MiddleCenter

'

'Timer1

'

Me.Timer1.Inter val = 200

'

'Form1

'

Me.AutoScaleBas eSize = 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(By Val sender As System.Object, ByVal e As
System.EventArg s)

'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(lastclic ked, sender.text) And
Now.Subtract(la stclicktime).To talMilliseconds <
Windows.Forms.S ystemInformatio n.DoubleClickTi me 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(ByVa l sender As System.Object, ByVal e As
System.EventArg s) 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(ByV al sender As System.Object, ByVal e As
System.EventArg s) 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 2426
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 "doubleclic k" 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
1229
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 second double click opens Code Window 2. In many cases (but not always) underlines error in code window and doesn't remove that underline after the error fixed. Underline disappears after compile 3. In many cases after previous problem occurred...
0
1305
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 like the numericUpDown,and i add a image button ,click the button,show the trackbar.I can use the trackbar to change the value of the label.I use the code to confirm the location of the trackbar: (The TrackFormCtrl is a form class which contains...
3
2521
by: Wang | last post by:
Here is the code for a webcontrol, quite simple: ------------------------------------------------------------------------------------------------------------- <%@ Control Language="c#" AutoEventWireup="false" Codebehind="WebUserControl1.ascx.cs" Inherits="WebApplication23.WebUserControl1" TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%> <STYLE> ..ModuleContent P { FONT-SIZE: x-small; FONT-FAMILY: Arial, Verdana, Helvetica }...
1
2291
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. Place a button. Double-click on the button and in it's event handler, just type : TextBox1.Text = TextBox1.Text ;
2
4288
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 (daclick1) that changes the text of the label. This works well. I have another class (MakePanel2) that creates a second button. I want this second button to call the button-click function of the first button. My incorrect call MakePanel1.daclick1()...
4
3053
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 widget. If a checkbox was set then the image should be shrunk as necessary to fit the canvas while if cleared it should appear full size with scrollbars if necessary. The code worked fine under Linux (where it was developed). But under Windows,...
3
3644
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" runat="server"></asp:Label></td> <td> <asp:TextBox ID="tbResponseText" runat="server" Text='<%#
2
1820
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" runat="server"></ asp:TextBox> <asp:Button ID="cmdAddRow" Text="+" AccessKey="+" runat="server" /> <asp:Button ID="cmdSubtractRow" Text="-" AccessKey="+" runat="server" / <asp:PlaceHolder runat="server" id="placeTextBoxes" />
1
7031
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 page has multiple button such login page with a search function somewhere around, then it's not respond properly. I have attached a brief example of two text boxes and two button. When ever a key is press on textbox one, I want to trigger...
0
9642
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10781
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10541
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10212
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9320
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7753
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6951
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5789
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4421
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.