putting an event procedure subroutine into a different event procedure
-
In .net, I am reading in a text file, line by line. Each line represents the file path for a picture I'd like to show. What I am trying to do is change the picture each time a user clicks the button. For example, lets say I've got something like this: Private Sub Form2_Load If Button1.Click = 1 Then PictureBox1.Visible = True PictureBox1.Image = System.Drawing.Image.FromFile _ (string1(y)) End If I know I can't do button1.click like this, but is there another way? Basically, I want the if condition to check if the button has been clicked or not. Thanks for any help or direction, Mike
-
In .net, I am reading in a text file, line by line. Each line represents the file path for a picture I'd like to show. What I am trying to do is change the picture each time a user clicks the button. For example, lets say I've got something like this: Private Sub Form2_Load If Button1.Click = 1 Then PictureBox1.Visible = True PictureBox1.Image = System.Drawing.Image.FromFile _ (string1(y)) End If I know I can't do button1.click like this, but is there another way? Basically, I want the if condition to check if the button has been clicked or not. Thanks for any help or direction, Mike
There is no "if" condition to check to see if the button was clicked. You simply put the code in the Click event handler of the button. Go to the form designer window and double-click on the button you want to add the code to. The code editor will come up with a blank event handler function for that button. All you need to do is add the code:
PictureBox1.Visible = True
PictureBox1.Image = System.Drawing.Image.FromFile _
(string1(y))You'll also need some code in here to increment the value of
y
and check to see that it doesn't exceed the bounds of the arraystring1()
. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome -
There is no "if" condition to check to see if the button was clicked. You simply put the code in the Click event handler of the button. Go to the form designer window and double-click on the button you want to add the code to. The code editor will come up with a blank event handler function for that button. All you need to do is add the code:
PictureBox1.Visible = True
PictureBox1.Image = System.Drawing.Image.FromFile _
(string1(y))You'll also need some code in here to increment the value of
y
and check to see that it doesn't exceed the bounds of the arraystring1()
. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming GnomeThanks for the feedback Dave. However, my application is a little bit different. In the main program, I am using streamreader to read in a text file line by line. Each line is a file path to a jpeg picture. In my loop of reading the file, I dont want the streamreader to read the next line until the user presses the button. Somehow I think I need to monitor if the button has been clicked or not within the streamreader loop. Maybe there's an easier way, I dunno..... -Mike
-
Thanks for the feedback Dave. However, my application is a little bit different. In the main program, I am using streamreader to read in a text file line by line. Each line is a file path to a jpeg picture. In my loop of reading the file, I dont want the streamreader to read the next line until the user presses the button. Somehow I think I need to monitor if the button has been clicked or not within the streamreader loop. Maybe there's an easier way, I dunno..... -Mike
You're actually trying to do it the hard way. You can monitor for the click, but you can't do it reliably. Your loop can execute multiple iterations if the user holds the button down for even 1 second. Since, from your first post, your reading the filepaths into a String array, just read them all in. You really shouldn't be holding open resources like your trying to do. It's very bad practice. Once you have all the filepaths in the array, you can setup a counter that points to the first index in the String array and you call a function to load and display the image it's pointing to. When the user clicks the button, you increment the counter, check to majke sure it hasn't overflowed, then call the function to load and display the image. Actually, it'd be easier to write a class to encompass this functionality. But that's an entirely different discussion... RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome