473,394 Members | 1,699 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,394 software developers and data experts.

help me with my buttons.

I have a button that when clicked once it loads a picture in an image box. i want it to do that but when it is clicked twice i want it to goto a form 3. Can anyone right some code for this problem.
Feb 11 '07 #1
16 1296
try declaring a global variable ctr
then per click increment ctr then if ctr = 2
form3.show or the likes
Feb 11 '07 #2
that would work but i want people to be able to viw the image more than once. is it posible to do something like use something like the dbl click.
Feb 11 '07 #3
Killer42
8,435 Expert 8TB
that would work but i want people to be able to viw the image more than once. is it posible to do something like use something like the dbl click.
The command button doesn't have a double-click event, but you might try simulating it. For example, when it is clicked, you could set a flag and start a timer. When the timer event fires (after half a second, for example) you can check whether the button was clicked again within that time. Also, in the click event, if the flag is already set, don't do anything except increment the "number of times clicked" counter.
Feb 12 '07 #4
could someone write the code for that i wouldn't know where to start with that one.
Feb 12 '07 #5
Killer42
8,435 Expert 8TB
could someone write the code for that i wouldn't know where to start with that one.
If I can find the time, I'll have a shot at it when I get home (in a couple of hours).

However, if you think about it for a while you can probably work it out. It's not really a terribly complicated concept, just awkward to describe.
Feb 12 '07 #6
i don't know how to use the check function let alone the check function with a timer.
Feb 12 '07 #7
Killer42
8,435 Expert 8TB
i don't know how to use the check function let alone the check function with a timer.
Well, I'm leaving work now. If someone else doesn't beat me to it, I'll give it a shot when I get home.
Feb 12 '07 #8
alrighty then. drive safe
Feb 12 '07 #9
Killer42
8,435 Expert 8TB
alrighty then. drive safe
Hi again.

I'm home, and I've thrown together the first two options that came to mind, to produce the equivalent of a double-click on a command button. To use them, just create a new project, add a form, and place a timer and a command button on the form. Then go to the code window for that form, erase absolutely everything and paste in the following.

This is the one which I described earlier...
Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2. DefLng A-Z
  3.  
  4. Dim Click_Count As Long
  5.  
  6. Private Sub Command1_Click()
  7.   Click_Count = Click_Count + 1
  8.   If Timer1.Enabled Then Exit Sub
  9.   Timer1.Enabled = True
  10. End Sub
  11.  
  12. Private Sub Timer1_Timer()
  13.   If Click_Count > 1 Then
  14.     MsgBox "Hey, you clicked " & Format(Click_Count) & " times."
  15.   End If
  16.   Click_Count = 0
  17.   Timer1.Enabled = False
  18. End Sub
This one works, but it's not very responsive, and doesn't really feel like a double-click. While writing it, I thought of a better way, which would respond immediately like a "real" double-click. Try this alternative...
Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2. DefLng A-Z
  3.  
  4. Dim Click_Count As Long
  5.  
  6. Private Sub Command1_Click()
  7.   If Click_Count Then
  8.     ' Consider this a double-click, and go do something.
  9.     MsgBox "Hey, you double-clicked the button!"
  10.     Click_Count = 0
  11.   Else
  12.     Click_Count = Click_Count + 1
  13.     Timer1.Enabled = True
  14.   End If
  15.  
  16. End Sub
  17.  
  18. Private Sub Timer1_Timer()
  19.   Click_Count = 0
  20.   Timer1.Enabled = False
  21. End Sub
Feb 12 '07 #10
thanks that will help alot. i wont be able to try it until wednesday because that is when i goto my dad's house.
Feb 12 '07 #11
Killer42
8,435 Expert 8TB
Oops! While I believe both those methods provide a double-click equivalent, I think I failed to handle the single-click. Here are modified versions of both which should work.

Note that the Interval property of the timer will affect the "double-click speed" - adjust it to suit yourself. I found 250 was a good setting.

Method 1
Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2. DefLng A-Z
  3.  
  4. Dim Click_Count As Long
  5.  
  6. Private Sub Command1_Click()
  7.   Click_Count = Click_Count + 1
  8.   If Timer1.Enabled Then Exit Sub
  9.   Timer1.Enabled = True
  10. End Sub
  11.  
  12. Private Sub Timer1_Timer()
  13.   If Click_Count > 1 Then
  14.     ' Do your double-click processing here.
  15.     Debug.Print "Double-click"
  16.   Else
  17.     ' Do your single-click processing here.
  18.     Debug.Print "Click"
  19.   End If
  20.   Click_Count = 0
  21.   Timer1.Enabled = False
  22. End Sub
Method 2
Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2. DefLng A-Z
  3.  
  4. Dim Click_Count As Long
  5.  
  6. Private Sub Command1_Click()
  7.   If Click_Count Then
  8.     ' Do your double-click processing here.
  9.     Debug.Print "Double-click"
  10.     Click_Count = 0
  11.   Else
  12.     Click_Count = Click_Count + 1
  13.     Timer1.Enabled = True
  14.   End If
  15.  
  16. End Sub
  17.  
  18. Private Sub Timer1_Timer()
  19.   Timer1.Enabled = False
  20.   If Click_Count = 1 Then
  21.     ' Do your single-click processing here.
  22.     Debug.Print "Click"
  23.   End If
  24.   Click_Count = 0
  25. End Sub
Feb 12 '07 #12
but i cant create a new project it needs to go in the middle of a 1/2 complete project. if you can wait till wednesday i can show you the code i have on the form already and you could right around it. till then i wont know if this code will work.:(
Feb 12 '07 #13
Killer42
8,435 Expert 8TB
but i cant create a new project it needs to go in the middle of a 1/2 complete project. if you can wait till wednesday i can show you the code i have on the form already and you could right around it. till then i wont know if this code will work.:(
The ideal way to do this would be to create a new project and use it to try out these ideas. Once you understand what's going on, you can include it into your real code much more easily.
Feb 12 '07 #14
ok i will do that.
Feb 12 '07 #15
got it to work with my program. thanks so much
Feb 15 '07 #16
Killer42
8,435 Expert 8TB
got it to work with my program. thanks so much
Glad we could help. :)
Feb 15 '07 #17

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Eric | last post by:
I have the following function which creates buttons on Excel commandbar. The problem i can't get the buttons to hook up to events. For example, if i create four buttons only the fourth one fires...
2
by: Steve K | last post by:
While reading "Eric Myer on CSS" I decided it was time to replace the buttons on my page (which were graphics) with some CSS "buttons" but I hit some snags. The first set of buttons I replaced...
7
by: Trvl Orm | last post by:
I am working with 2 frames, Left and Right and the main code is in the left frame, which has been attached. Can someone please help me with this code. I am new to JavaScript and can't figure it...
4
by: Gequina | last post by:
Something goes wrong in my script. I'm all new to it so i don't know much yet. I have a set of buttons. And when you click on either of them, the background image will change. Only it's not...
2
by: MyNameIsnt | last post by:
Can anyone tell me why, when I click on the buttons it register 2 characters on the display? if you use the right mousebutton it works ok, but the buttons dont flash?? it works fine without the...
1
by: momo | last post by:
Hello all, I need some help with radio buttons. This is what I have. I have 15 groups of radio buttons and each group contains three radio buttons which non of them are selected. I need a way...
10
by: Bharat | last post by:
Hi Folks, Suppose I have two link button on a page (say lnkBtn1 and lnkBtn2). On the click event of the lnkbtn1 I have to add a dynamically created control. And On the click event of the lnkBtn2 I...
5
by: Edwinah63 | last post by:
Hi everyone, i was wondering if anyone else had observed this and if there is any workaround or patch. i have some screens (an mdi child forms) with the buttons &Add, &Edit, &Save and E&xit,...
3
by: Learner | last post by:
Hello, I have two buttons on one of my VehicleDetails.aspx page. Obiviously these two buttons takes the user to two different pages. Now my client is interested in having a linkbutton instead of...
10
by: aboolamoola | last post by:
hi, I recently started programing about a month ago. my teacher ask me to make a game. A connect 4 game. I try to make, but failed. I need help. here is my code: import java.awt.*; import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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
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...

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.