Repeat-a-matic Mouse Button Problem

I need a mouse button which does its thing when clicked, and keeps repeating 
its thing when held down.  I know that the code below is not very 
sophisticated but I think that it is adequate for my immediate needs.  The 
problem is that when I depress and hold the mouse button down the button 
does absolutely nothing.  When clicked once it does what it should, i.e. 
deletes the leftmost character.  When clicked one and a half times, i.e. 
clicked once and then immediately depressed and held, it goes into 
repeat-a-matic mode.  But I can't see why it is doing nothing when I depress 
and hold it.

The code is dirt simple.  I'd be very Thanksgiving if you'd look at it and 
see if you can tell me what I am doing wrong.

Thanks,  Bob

(btnLeftDel and TextBox1 are placed on a form using the designer.)
Option Strict On

Option Explicit On

Imports System.Threading

Public Class Form1

Dim LeftButtonDown As Boolean = False

Private Sub btnLeftDel_MouseDown(ByVal sender As Object, ByVal e As 
System.Windows.Forms.MouseEventArgs) Handles btnLeftDel.MouseDown

'remove leftmost character

Dim counter As Integer = 0

LeftButtonDown = True

Do While (TextBox1.Text.Length > 0) And _

(LeftButtonDown)

If counter = 0 Then

TextBox1.Text = TextBox1.Text.Substring(1)

'Application.DoEvents() 'doesn't help

End If

'counter += 1

Thread.Sleep(200)

Application.DoEvents() 'without this a single click always deletes 2 
characters

'If counter = Form1.MouseBtnDownRepeatFactor Then counter = 0

Loop

End Sub



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

LeftButtonDown = False

End Sub

End Class


0
eBob
11/26/2009 8:29:26 PM
dotnet.languages.vb 830 articles. 0 followers. Follow

4 Replies
611 Views

Similar Articles

[PageSpeed] 7

First, get rid of DoEvents. It's nasty. ;)

I've used a Timer instead and it seems to work:

   Private Sub Button1_MouseDown( _
      ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) _
      Handles Button1.MouseDown

      If e.Button = Windows.Forms.MouseButtons.Left Then
         If TextBox1.Text.Length > 0 Then
            Timer1.Start()
         End If
      End If

   End Sub

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

      Dim Text = TextBox1.Text

      If Text.Length < 2 Then
         Timer1.Stop()
      End If

      If Text.Length > 0 Then
         TextBox1.Text = Text.Substring(1)
      End If

   End Sub

   Private Sub Button1_MouseUp( _
      ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) _
      Handles Button1.MouseUp

      If e.Button = Windows.Forms.MouseButtons.Left Then
         Timer1.Stop()
      End If

   End Sub

-- 
Armin

0
Armin
11/26/2009 9:26:08 PM
Thank you Armin.  It's interesting to see a different approach.

But I'm embarassed to admit that this was a false alarm.  Although I go back 
and forth several times a day between a desktop with a mouse and a laptop 
with a touch pad, I was not conscious of the difference between real mice 
and my laptop's touch pad's simulation of a mouse.

On my laptop, to press and hold ANY button requires a double tap and hold, 
whereas using the same laptop with a real mouse requires a single press and 
hold of the mouse button.

When your code worked exactly like mine I thought maybe I should experiment 
more with the touch pad and discovered my mistake.  It's really strange, I 
use my laptop A LOT and just wasn't conscious of what I was doing to cause 
repeat-a-matic action.

By the way, what do you have against DoEvents?

Thanks again,  Bob

"Armin Zingler" <az.nospam@freenet.de> wrote in message 
news:OypL28tbKHA.1596@TK2MSFTNGP06.phx.gbl...
> First, get rid of DoEvents. It's nasty. ;)
>
> I've used a Timer instead and it seems to work:
>
>   Private Sub Button1_MouseDown( _
>      ByVal sender As Object, ByVal e As 
> System.Windows.Forms.MouseEventArgs) _
>      Handles Button1.MouseDown
>
>      If e.Button = Windows.Forms.MouseButtons.Left Then
>         If TextBox1.Text.Length > 0 Then
>            Timer1.Start()
>         End If
>      End If
>
>   End Sub
>
>   Private Sub Timer1_Tick( _
>      ByVal sender As System.Object, ByVal e As System.EventArgs) _
>      Handles Timer1.Tick
>
>      Dim Text = TextBox1.Text
>
>      If Text.Length < 2 Then
>         Timer1.Stop()
>      End If
>
>      If Text.Length > 0 Then
>         TextBox1.Text = Text.Substring(1)
>      End If
>
>   End Sub
>
>   Private Sub Button1_MouseUp( _
>      ByVal sender As Object, ByVal e As 
> System.Windows.Forms.MouseEventArgs) _
>      Handles Button1.MouseUp
>
>      If e.Button = Windows.Forms.MouseButtons.Left Then
>         Timer1.Stop()
>      End If
>
>   End Sub
>
> -- 
> Armin
> 


0
eBob
11/27/2009 1:53:58 AM
eBob.com schrieb:
> Thank you Armin.  It's interesting to see a different approach.
> 
> But I'm embarassed to admit that this was a false alarm.  Although I go back 
> and forth several times a day between a desktop with a mouse and a laptop 
> with a touch pad, I was not conscious of the difference between real mice 
> and my laptop's touch pad's simulation of a mouse.
> 
> On my laptop, to press and hold ANY button requires a double tap and hold, 
> whereas using the same laptop with a real mouse requires a single press and 
> hold of the mouse button.
> 
> When your code worked exactly like mine I thought maybe I should experiment 
> more with the touch pad and discovered my mistake.  It's really strange, I 
> use my laptop A LOT and just wasn't conscious of what I was doing to cause 
> repeat-a-matic action.

Thanks for the feedback.

> By the way, what do you have against DoEvents?

If I want to do two things at a time, I use two threads. If there is already
one thread processing windows messages, why use DoEvents additionally? If messages
are not processed anymore, I look for the cause (that makes DoEvents necessary): The
cause is the loop inside the MouseDown event. If you remove it, the thread
keeps on doing what it is made for: processing messages.

Also, the UI thread should be as responsive as possible and consume as little
CPU power as possible. Your loop does not fulfil this as good as the (already
running) message loop does. It just (unnecessarily) occupies the CPU or,
using Thread.sleep, makes it less responsive. Moreove, any event handler should finish
as quickly as possible. If it's a long running task, it should be done in another
thread started in the event handler. That's not the case in your example, but
in your case it's just not necessary at all. It's like endlessly picking up
and hanging up the phone (because somebody might call) instead of
sitting there doing nothing and wait till it rings. ;)

In addition, DoEvents can cause code reentrance. Often, people are not aware
that everything can happen during DoEvents. For example, the Form can
be closed. Do you check if the Form is still visible after calling DoEvents?
If not, it can lead to exceptions because you assume it is still there.
In every event handler, are you aware that it might have been called during
DoEvents?

(BTW, there is still the bug that a button is clicked again even if you
click somewhere else on the form if the click is processed by calling Doevents.
Try it: put a button on a form. In it's click event, write a loop only
calling Doevents. Start. Click the button to make the loop run.
Then click on the [X] to close the Form. You see what I mean?)


-- 
Armin





0
Armin
11/27/2009 2:57:26 AM
Thanks Armin.  All excellent points.  I totallly agree.

Bob


"Armin Zingler" <az.nospam@freenet.de> wrote in message 
news:%23wJKf2wbKHA.5656@TK2MSFTNGP04.phx.gbl...
> eBob.com schrieb:
>> Thank you Armin.  It's interesting to see a different approach.
>>
>> But I'm embarassed to admit that this was a false alarm.  Although I go 
>> back
>> and forth several times a day between a desktop with a mouse and a laptop
>> with a touch pad, I was not conscious of the difference between real mice
>> and my laptop's touch pad's simulation of a mouse.
>>
>> On my laptop, to press and hold ANY button requires a double tap and 
>> hold,
>> whereas using the same laptop with a real mouse requires a single press 
>> and
>> hold of the mouse button.
>>
>> When your code worked exactly like mine I thought maybe I should 
>> experiment
>> more with the touch pad and discovered my mistake.  It's really strange, 
>> I
>> use my laptop A LOT and just wasn't conscious of what I was doing to 
>> cause
>> repeat-a-matic action.
>
> Thanks for the feedback.
>
>> By the way, what do you have against DoEvents?
>
> If I want to do two things at a time, I use two threads. If there is 
> already
> one thread processing windows messages, why use DoEvents additionally? If 
> messages
> are not processed anymore, I look for the cause (that makes DoEvents 
> necessary): The
> cause is the loop inside the MouseDown event. If you remove it, the thread
> keeps on doing what it is made for: processing messages.
>
> Also, the UI thread should be as responsive as possible and consume as 
> little
> CPU power as possible. Your loop does not fulfil this as good as the 
> (already
> running) message loop does. It just (unnecessarily) occupies the CPU or,
> using Thread.sleep, makes it less responsive. Moreove, any event handler 
> should finish
> as quickly as possible. If it's a long running task, it should be done in 
> another
> thread started in the event handler. That's not the case in your example, 
> but
> in your case it's just not necessary at all. It's like endlessly picking 
> up
> and hanging up the phone (because somebody might call) instead of
> sitting there doing nothing and wait till it rings. ;)
>
> In addition, DoEvents can cause code reentrance. Often, people are not 
> aware
> that everything can happen during DoEvents. For example, the Form can
> be closed. Do you check if the Form is still visible after calling 
> DoEvents?
> If not, it can lead to exceptions because you assume it is still there.
> In every event handler, are you aware that it might have been called 
> during
> DoEvents?
>
> (BTW, there is still the bug that a button is clicked again even if you
> click somewhere else on the form if the click is processed by calling 
> Doevents.
> Try it: put a button on a form. In it's click event, write a loop only
> calling Doevents. Start. Click the button to make the loop run.
> Then click on the [X] to close the Form. You see what I mean?)
>
>
> -- 
> Armin
>
>
>
>
> 


0
eBob
11/27/2009 9:15:38 PM
Reply:

Similar Artilces:

Here is fix for Windows file problems
If you have installed a Windows update and started having problems opening, closing, copying files, see: http://www.microsoft.com/communities/newsgroups/list/en-us/default.aspx?dg=microsoft.public.excel.misc&mid=1fe358b1-c8eb-4217-ad2a-4b9fcf741916 A better solution is offered at http://support.microsoft.com/kb/918165 "Problems in Windows Explorer or the Windows shell after you install security update MS06-015". Patricia Shannon wrote: > If you have installed a Windows update and started having problems opening, > closing, copying files, see: > > http://ww...

Problem with CFTPConnection
Hi I've an application that connects to an FTP Server and uploads a big directory (size over 500 MB). Now what happens is that after sometime the application stops uploading files and stays idle. The FTP server connection timeout value is set to 2 minutes. So the server seeing the connection idle for two seconds, disconnect the session and no more file is uploaded. On debugging I found out that after some time CFTPConnection.PutFile() method hangs on some random file and stays like that for 5 minutes (default send timeout value of CFTPSession). During this time the server connection timeo...

Can I copy radio buttons so that the second set is independent of.
I have a group of four radio buttons that all point to one cell. My goal is to create a second set that looks identical to the first but which points to a second cell. This is for a questionaire that will have many questions with the same four answer values. I want to be able to quickly create 100 button groups that will each update a separate cell for scoring of the questionaire. There are optionbuttons on the Control toolbox toolbar and there are optionbuttons on the Forms toolbar. Each has different behaviors. If I had to use lots, I'd use the Forms version. Here's a pos...

Excel 97 Win XP calc problem?
I have a machine running office 97 and Win XP. I have seen posts stating it runs fine, but I don't know how man people use spreadsheets that require a hard calculation: Excel will not force a calculation. i.e. ctrl-alt-f9 does not cause full workbook calculation as required. Meaning cells do not update and it doesn't calculate unless you clic in the cell to edit and hit enter. neither does the "Calc Now" button. Auto or manual calculation mode has no effect. Anybody else have this problem -- Message posted from http://www.ExcelForum.com Make sure that both the SR1 a...

CRM Outlook Client Configuration Wizard Problem
CRM 4.0 - Microsoft Outlook Client Guys, We've Microsoft CRM 4.0 Server roll up 8 as well as CRM Outlook Client on the same roll up version. Our Internal Web Access works without problems users get to it and they're automatically authenticated. IFD Development is the same way except they're prompt through a login page for their username and password when they're coming from an external network. Ever since we moved to a new facility users are experiencing problems connecting to CRM using their outlook client, I have a test machine where I have the CRM Outlook Client ins...

Problem with Update function of CRecordSet class
Hi All When I use from Update function of CRecordSet class, it apply to table after a few time(for example 1 second) when I need to see it at time. Thanks ...

Problem with macro assigned to custom toolbar button
Problem with macro assigned to custom toolbar button I am having a probelm with macros assigned to a custom button on custom button. I am using excel 2000. 1. I have created a macro called "Jump" in a workbook named "Test1" 2. I then created a custom toolbar and added a custom toolbar button t that toolbar. 3. Through the customize dialog box I assign the Macro "Jump" to th custom button. Everything works fine UNTIL. If I do a SAVE AS for the workbook "Test1" and call it something els like "Test2" and then close "Test2" an...

OL2002 Problem : HELP, SOS, MAYDAY
Hi, I have an IMAP account and OL2002 as client. I have checked for my account ( tools, send/receive settings, define send/receive groups, <my_account>, edit) download item description only. It works only the first time I start OL2002, but it does not work anymore for subsequent automatic/manual send/receive operations. Please could someone really help me ? Thank you in advance, Patrick ...

request to solve my problem #5
hello friends this is vijay,i got a problem while doing my project based on vc++ (i.e)"How to implement Fit Window feature in VC++6.0 in an MDI Application" if any of you got any idea about that please do reply me with the proceedure.i will be waiting for your reply bye with regards vijayprasadreddy ...

Excel. I am having a problem with hidden text
As I type text in some cells, it does not always dispaly if it exceeds the cell length. I wish to keep the cell lenghts for the entire document, but do wish for teh text in that particular row to be displayed. How about if you select that cell, then format|cells|alignment tab|check wrap text And with that row selected format|row|autofit SHR77 wrote: > > As I type text in some cells, it does not always dispaly if it exceeds the > cell length. I wish to keep the cell lenghts for the entire document, but do > wish for teh text in that particular row to be displayed. -- Da...

Outlook 2003
In Outlook 2003, #1 Is there a way to refresh the unread folder so that read messages no longer apear? Right now I have to click closed the unread folder and click it again #2 Is there a way to create a toolbar button that goes directly to a subfolder? Thanks ...

Fulfillment type orders
We have orders at the initial status (just entered) and the options to allow delete documents and void documents are enabled on the Sales Order Type. However, we can't get a void or delete button unless we move the fulfillment order through the confirm process to an "Invoice" to get a Delete? What's up with this? Very annoying. Jana, I know it is subtle and wish there was a better way to display it, but the Void option only applies to Invoice type IDs and not Fulfillment Order type IDs ("Void Invoice Documents" vs. "Delete Documents"). Since both t...

Excel List Sorting Problem (Descending)
Hi there, I'm having trouble sorting my list--my column contains *only* 4-digit numbers but when I click on "descending order", only about the first half of the rows are arranged this way, before it begins again to arrange the rest in descending order. Like this: 5120 5119 5118 4000 3050 5116 4112 etc. Has this problem happened for anybody else? I'd appreciate any help you can offer. Part of your list is text, although it looks like numbers. Format an empty cell as number. Enter the number 1. Copy. Select your "numbers". Edit>Paste Special, check Mul...

I really need help with a formview problem
I have a formview that I place a toolbar onto. In my OnInitialUpdate(), after I create the toolbar, I say GetParentFrame()->RecalcLayout(); ResizeParentToFit(FALSE); ResizeParentToFit(TRUE); The formview is still not sized properly. It looks like the problem is the toolbar on the top of the formview. It is not being taken into account in sizing the formview. The difference at the bottom of the form that is not displayed is the size of the toolbar. Any suggestions? Should work if your toolbar was created (and docked) back in your CMainFrame::OnCreate() method. ----- William Gower ...

Printing problem in booklet format
When I try to print my booklet document, on the screen it looks perfect, but when i go into print preview it only has half of each page on the paper. When i print, it comes out exactly like that. I have Publisher 2003 and run it on XP home. My printer is an Epson stylus Photo RX650. I contacted Epson and they say its a Publisher problem. Any suggestions. Driver? http://tech.epson.com.au/downloads/product.asp?sCategory=Multi_Functional&id=stylusphotorx650&FileType=1&EmailAdd=&MetricIDReturned=624915&platform=winxp Are you selecting booklet in page setup? Do you ...

problem opening up program/file
Hello, All. I am having some trouble opening up Word. It was working okay until I loaded some fonts to FontBook. Okay, now I removed all my fonts but I still get this error message about corrupt fonts I have on my computer. When I open Word, I see the blue starting-up window: Word:Mac 2004. Right underneath the product ID #, I see that it is initiating... when it gets to the point "Optimizing font menu performance" I start getting this error windows popping up one after another. (E.g. The font M TimesSmallText is corrupt and should be removed.) I keep on clicking okay for a whole lot...

Money deluxe 2007 password problem
When I update my bank account transactions I get a message saying that my account was not updated because my password is incorrect. I then go into account info and have to update my password. I save the update, but then it happens again sporadically when I open Money at later times. Is there a way to fix this glitch? ...

printing problems with memorized reports
We have recently been running into printing problems with our memorized reports. We will print preview a report and it will look fine on screen, then we will send to the printer, and the report print extremely small in the corner of the page. However if we go back in and re-print the report then it will print normal size on the page. We are not making any settings changes at all, and when it does this appears to just be at random. We are printing to an HP laserjet 4000 series printer that is on our network. We've used RMS with the same configuration for approx. 5 years now and ...

Reports and sub-reports problems
Dear Sirs,I have a report with 4 sub-reports.How can it be that 2 sub-reports are showing the data triple.Can someone help?ThanksKlaus I just realized. It's not due to being a subreport - it's already showing on the normal report triple data. It was not before and I did not change anything. I hope that someone can help me.Thanks Klaus"Amateur" wrote:> Dear Sirs,> I have a report with 4 sub-reports.> How can it be that 2 sub-reports are showing the data triple.> Can someone help?> Thanks> Klaus...

connection problems
a popup saying internet explorer cannot diaplay webpage and it is a connection problem -- eummer2010 how does your problem/question pertain to windows update? terri wrote: > a popup saying internet explorer cannot diaplay webpage and it is a > connection problem Hello Terry, Would be nice if you could tell us more information, like what OS you're using, Service Pack, what other security software are you running, if any? etc. IE6 ? IE7 ? IE8 ? Repoяt problems and check for solutions automatically <http://windowshelp.microsoft.com/Windows/en-US/Help/...

There is a problem with your printer settings.
There is a problem with your printer settings. Your printer has given Publisher an invalid value, and the printer could not be correctly initialized. Check your printer settings in the Windows control panel." 1. I only have one network printer 2. The network printer is not the default printer 3. I have deleted the printer, rebooted and reinstalled the latest printer drivers. 4. The printer name is less than 8 characters long. ... any idea what the problem is??? -- kirks What version Publisher? Do you have the service packs? http://www.microsoft.com/downloads/search.aspx?displaylan...

Automated starting of app
Hi NG, I don't know if this a problem special to MFC or something else. I work with XP and VC++ 6.0. I wrote a small dialog based app which can collect names of files and/or directories. I can start this app and select the files and directories with the usual common dialogs - works fine. I can also mark the files in the explorer and dragdrop them to the icon of the app. In this case I get the names as argv[n] and can fill the dialog with them while the program is starting. Works fine too. But when I select too many file names to dragdrop them to the icon, while the program starts I get the...

problem with dependency on atl71.dll
Hello, I have problem removing dependency on atl71.dll. I've tried these: defining /D "_ATL_STATIC_REGISTRY" and Properties->Config->General->UseOfATL : Static Link To ATL din't helped, still asking for missing dll when trying register my dll on Win2k. When I supply atl71.dll it's fine, but not sure if this is safe solution. can somebody advise on that? thanks Post this in ATL group instead (or atleast cross-post) --- Ajay ...

Double Click Command Button to run module
I have code like the following in a module and a Call command linked to a command button on Sheet1 which is named Index. Sheet 2 is named Form. When I check the check box and press the command button only the cell range defined is highlighted but does not change to yellow. After going back the the Index sheet and pressing the command button again will the cells then turn yellow. What can I add so the cells will follow the complete code on the first press of the command button. Thanks for the help! Public Sub AddingEquipment() If Worksheets("Index").CheckBox1.Value = Fa...

Business Portal 4.0 Problems
Hi everyone, I was wondering if anyone here who has experience in Business Portal could help me out here. I have Installed Business Portal 4.0 on our SharePoint Services (WSS 3.0) and it seems to be running fine. But when I try to remove a user from the Business Portal list, I get this error: System.Exception: soap:Server Server was unable to process request --> The subscriber type in the subscription is invalid. PublisherAssemblyName: Microsoft.BusinessFramework PublisherClass: Microsoft.BusinessFramework.User PublisherEvent: Deleting SubscriberAssemblyName: Microsoft.Dynamics.R...