Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. putting an event procedure subroutine into a different event procedure

putting an event procedure subroutine into a different event procedure

Scheduled Pinned Locked Moved Visual Basic
csharpgraphicshelptutorialquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mpiotro
    wrote on last edited by
    #1

    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

    D 1 Reply Last reply
    0
    • M mpiotro

      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

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      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 array string1(). RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

      M 1 Reply Last reply
      0
      • D Dave Kreskowiak

        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 array string1(). RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

        M Offline
        M Offline
        mpiotro
        wrote on last edited by
        #3

        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

        D 1 Reply Last reply
        0
        • M mpiotro

          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

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups