473,749 Members | 2,356 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Two clicks for a button

759 Contributor
Hello !
I try to switch from VB6 to VB.NET.
For now I use 2008 Express Edition.

Look at this code, please:
Expand|Select|Wrap|Line Numbers
  1. Public Class frmMovieBuild
  2.     Dim StopMovie As Boolean
  3.  
  4.     Private Sub cmdPlayMovie_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdPlayMovie.Click
  5.         StopMovie = False
  6.         Dim i As Long, jpg As String
  7.         i = 0
  8.         Do While i <= lstMainMovie.Items.Count - 1
  9.                 System.Windows.Forms.Application.DoEvents()
  10.             jpg = lstMainMovie.Items.Item(i).ToString
  11.                 System.Windows.Forms.Application.DoEvents()
  12.             pic_MoviePreview.Image = Image.FromFile(jpg)
  13.                 System.Windows.Forms.Application.DoEvents()
  14.             If StopMovie Then
  15.                 MsgBox("Stopped by user")
  16.                 Exit Do
  17.             End If
  18.             i = i + StepFrames.Value 'Here I use a slider control
  19.         Loop
  20.     End Sub
  21.  
  22.     Private Sub cmdStopMovie_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdStopMovie.Click
  23.         StopMovie = True
  24.     End Sub
  25.  
  26. End Class
  27.  
When I run the form, first I click the cmdPlayMovie button.
Then I try to exit by clicking the cmdStopMovie button (in order to set the StopMovie variable to TRUE).
And here is the problem:
At the first click, nothing happen. The cmdStopMovie button seems to take the focus.
Then, at the second click, the "Stopped by user" message appear.

For my project is strongly necessary to stop the movie at a certain frame.
That means that cmdStopMovie button must react at the first click.

Is there a bug or there are some settings to do ?

Hope I have explained well my problem.

More one question (If necessary I'll start a new thread for this).
The WHILE clause seems to have no effect in Do-Loop cycle. So this cycle run for ever (except if I click the cmdStopMovie button).
Can someone understand (and explain) WHY ?

Thank you !
Nov 11 '12 #1
1 1549
IronRazer
83 New Member
I have run into the problem you where having in an old program of mine and here is the fix i used for it. I changed a little of the code but it should work fine.

First add a timer. Then use this code :
Expand|Select|Wrap|Line Numbers
  1.     Private Sub cmdPlayMovie_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdPlayMovie.Click
  2.         Timer1.Start()
  3.     End Sub
  4.  
  5.     Private Sub cmdStopMovie_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdStopMovie.Click
  6.         StopMovie = True
  7.     End Sub
  8.  
  9.     Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
  10.         Timer1.Stop()
  11.         StopMovie = False
  12.         Dim i As Long
  13.         i = 0
  14.         While (i <= frames And Not StopMovie)
  15.             System.Windows.Forms.Application.DoEvents()
  16.             jpg = lstMainMovie.Items.Item(i).ToString
  17.             System.Windows.Forms.Application.DoEvents()
  18.             pic_MoviePreview.Image = Image.FromFile(jpg)
  19.             System.Windows.Forms.Application.DoEvents()
  20.             i += StepFrames 'Here I use a slider control
  21.         End While
  22.         If StopMovie Then
  23.             MsgBox("Stopped by user")
  24.         End If
  25.     End Sub
  26.  
Jan 19 '13 #2

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

Similar topics

6
5116
by: MLH | last post by:
How can I hit www.someplace.com from an Access form? I'd like to... 1) open user's default browser (if not already open) 2) type in a URL 3) press enter (or click Go - or - whatever it takes) I'd like it all to happen when user clicks button on form.
0
914
by: | last post by:
hi I have got .aspx page on the page i have pasted .ascx. On the .ascx i have pasted two more .ascx. I called the method " Page_Load " with statement " if (!IsPostBack) ", problem is when .aspx page is load it will display some content but when user select items via combo box, fills name and address and clicks the button the rest of selected content from .aspx page will disappear Plz how can i solve this problem
1
1768
by: John Hughes | last post by:
Im adding a button at runtime to a datagrid but the DataGrid1.ItemCommand event does not fire. I also have a button that I added at design time and this button does fire the event ItemCommand. Any ideas? My Code : private void InitializeComponent()
7
41826
by: code100579 | last post by:
Hi there, sorry if this is a really simple question. I need to write code for: If a button is pushed and then one variety of other buttons is pushed then certain options on the program will become "greyed out". Ie they can no longer be selected. I assume i need to create an event from the first button being pushed and then do if statements depending which button is pushed next
2
2942
by: jburkle | last post by:
The following is the onclick method called when the "Renew" button is clicked by the user in my Windows application: ..... Private Sub cmdRenew_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdRenew.Click Try If x Is Nothing Then
1
4345
by: Chris Ashley | last post by:
I have an ImageButton which I would like to have the following behaviour: (1) User clicks button, button is disabled. (2) Page validators fire (3) If page fails client side validation, reenable button. Otherwise submit.
2
3298
by: polocar | last post by:
Hi, suppose that you have a C# form with two buttons, that are the classical "btnOk" and "btnCancel" (besides them, of course in the form there can be many other controls). When the user clicks on btnOk, the program makes some confirm operations and closes the form. When the user clicks on btnCancel, the program makes some cancel operations and closes the form. My problem is that, when the user clicks on the "X" button of the form...
2
5453
by: ImageAnalyst | last post by:
Does anyone know how to get rid of excess mouse clicks? I have a button that does some code which takes some time to execute. As soon as the user clicks the button, I disable the button in the button handler and enable it again when I exit the handler. However, if the user clicks a bunch of times, say 10, during the time it's disabled and executing for the first time, it will start to process the second mouse click the moment the button...
3
5116
by: kimiraikkonen | last post by:
Hi experts, I just want to ask a simple procedure of my simple form. My form has a input textbox and a button. I want this if you can help me: Application user types a command prompt command like "dir" into "textbox", then after clicking "button", command prompt(cmd) should run with the prompt that user has written already into "textbox" .
0
8996
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9566
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...
0
9388
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9254
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...
1
6800
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
6078
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
4608
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3319
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
2
2791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.