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

Two clicks for a button

759 512MB
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

✓ answered by IronRazer

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.  

1 1531
IronRazer
83 64KB
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
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) ...
0
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...
1
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. ...
7
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...
2
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...
1
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,...
2
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...
2
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...
3
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...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: 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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...

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.