dcsimg
Results 1 to 9 of 9

Thread: Control Array Like solution

  1. #1

    Thread Starter
    Member intellilogic's Avatar
    Join Date
    Oct 2010
    Location
    Tyson's Corner, VA
    Posts
    39

    Control Array Like solution

    First, I am not really a programmer, I am just trying to slap together this project. But I have 6 pictureboxes that I want to do "the same thing". So when I click it, it saves the image, I press a button, they all load their pictures... except the save the image 'image1' 'image2', etc... when they load the image, same sorta thing. Anyway I can tighten up this code?


  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    104,175

    Re: Control Array Like solution

    I don't see any code to tighten up. If you're saying that you want to repeat a group of controls then you should create a UserControl. You add one to your project and design it just as you would a form. Once you build, the UC is added to the Toolbox and you use it like any other control. If you want to be able to loop through them in code, create an array in code as you would any other.

  3. #3

    Thread Starter
    Member intellilogic's Avatar
    Join Date
    Oct 2010
    Location
    Tyson's Corner, VA
    Posts
    39

    Re: Control Array Like solution

    Code:
        Private Sub picCrop1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picCrop1.Click
            CropandClear(picCrop1)
        End Sub
    
        Private Sub picCrop2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picCrop2.Click
            CropandClear(picCrop2)
        End Sub
    
        Private Sub picCrop3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picCrop3.Click
            CropandClear(picCrop3)
        End Sub
    
        Private Sub picCrop4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picCrop4.Click
            CropandClear(picCrop4)
        End Sub
    
        Private Sub picCrop5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picCrop5.Click
            CropandClear(picCrop5)
        End Sub
    
        Private Sub picCrop6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picCrop6.Click
            CropandClear(picCrop6)
        End Sub
    and then I will have :
    Code:
            picCrop1.WaitOnLoad = False
            picCrop1.LoadAsync("http://www.photo.com/content_1.jpg")
    and one per pic box 1-6

  4. #4
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    104,175

    Re: Control Array Like solution

    You're assuming that we know things that we don't. You list six event handlers and then you say:
    and then I will have
    but what does that mean? The code you posted isn't a method so it must be in a method but what method? Also, it only refers to one PictureBox so does that mean you have similar code five more times? We only know what you tell us so you have to tell us everything that's relevant. Provide a FULL and CLEAR description of EXACTLY what you want and what you have.

    That said, one thing you can definitely do is combine those six event handlers into one. You put all six PictureBoxes in the Handles clause and then you pass the 'sender' to CropAndClear. In an event handler, 'sender' is always the object that raised the event.

  5. #5

    Thread Starter
    Member intellilogic's Avatar
    Join Date
    Oct 2010
    Location
    Tyson's Corner, VA
    Posts
    39

    Re: Control Array Like solution

    Quote Originally Posted by intellilogic View Post
    and one per pic box 1-6
    How can I do that?

  6. #6
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    104,175

    Re: Control Array Like solution

    I don't understand what you're asking.
    Provide a FULL and CLEAR description of EXACTLY what you want and what you have.

  7. #7

    Thread Starter
    Member intellilogic's Avatar
    Join Date
    Oct 2010
    Location
    Tyson's Corner, VA
    Posts
    39

    Re: Control Array Like solution

    I'm not sure how to describe what I want of if it's even possible. I just envision making all 6 things 1 portion of code. Like I said, I'm not a VB coder here.
    Code:
        Private Sub picCrop{}_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picCrop{}.Click
            CropandClear(picCrop{})
        End Sub
    Code:
            picCrop{}.WaitOnLoad = False
            picCrop{}.LoadAsync("http://www.photo.com/content_{}.jpg")

  8. #8

    Thread Starter
    Member intellilogic's Avatar
    Join Date
    Oct 2010
    Location
    Tyson's Corner, VA
    Posts
    39

    Re: Control Array Like solution

    So here's what I have, there must be a better way, maybe a loop or something?
    Code:
        Public Sub LoadPics()
            Dim RWI As String = "RapidWebInventory"
    
            picCrop1.WaitOnLoad = False
            picCrop2.WaitOnLoad = False
            picCrop3.WaitOnLoad = False
            picCrop4.WaitOnLoad = False
            picCrop5.WaitOnLoad = False
            picCrop6.WaitOnLoad = False
            picCrop1.LoadAsync("http://" + "haydenliquidations.com" + "/" + RWI + "/list_images/" + lblSku.Text + "/" + lblSku.Text + "_" + "1" + ".png")
            picCrop2.LoadAsync("http://" + "haydenliquidations.com" + "/" + RWI + "/list_images/" + lblSku.Text + "/" + lblSku.Text + "_" + "2" + ".png")
            picCrop3.LoadAsync("http://" + "haydenliquidations.com" + "/" + RWI + "/list_images/" + lblSku.Text + "/" + lblSku.Text + "_" + "3" + ".png")
            picCrop4.LoadAsync("http://" + "haydenliquidations.com" + "/" + RWI + "/list_images/" + lblSku.Text + "/" + lblSku.Text + "_" + "4" + ".png")
            picCrop5.LoadAsync("http://" + "haydenliquidations.com" + "/" + RWI + "/list_images/" + lblSku.Text + "/" + lblSku.Text + "_" + "5" + ".png")
            picCrop6.LoadAsync("http://" + "haydenliquidations.com" + "/" + RWI + "/list_images/" + lblSku.Text + "/" + lblSku.Text + "_" + "6" + ".png")
        End Sub

  9. #9
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    104,175

    Re: Control Array Like solution

    You would take out the common part and put that into a method, then just pass the required data into that method, calling it once for each PictureBox. The method should look like this:
    Code:
        Public Sub LoadPic(ByVal picCrop As PictureBox, ByVal imageNumber As Integer)
            picCrop.WaitOnLoad = False
            picCrop.LoadAsync(String.Format("http://haydenliquidations.com/RapidWebInventory/list_images/{0}/{0}_{1}.png", lblSku.Text, imageNumber))
        End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width