Results 1 to 6 of 6

Thread: how use several Listboxes or controls for only one action (loop?)

  1. #1

    Thread Starter
    New Member archy-one's Avatar
    Join Date
    Mar 2019
    Posts
    4

    how use several Listboxes or controls for only one action (loop?)

    Hello everyone,

    first of all I want to apologize for my approximate english.
    Well, I expose my problem, I code a small application with VS2015 that will allow me, finally the day or it will work to change pixels of icons automatically using the X & Y coordinates and ARGB values contained in 3 different ListBoxes.

    Here is the overview:
    Name:  Capture.PNG
Views: 277
Size:  59.0 KB

    When i use manually for one pixel change, all works like a charm.. I can choose coordinates with 2 NumericUpDown and color with 4 others with no problem.

    code of button ("change color pix"):

    Code:
    Dim bm As New Bitmap(PictureBox2.Width, PictureBox2.Height)
            PictureBox2.DrawToBitmap(bm, PictureBox2.ClientRectangle)
            bm.SetPixel(NumericUpDown1.Value, NumericUpDown2.Value, Color.FromArgb(NumericUpDown3.Value, NumericUpDown4.Value, NumericUpDown5.Value, NumericUpDown6.Value))
            PictureBox2.Image = bm
            PictureBox1.Image = PictureBox2.Image
    Now my main problem is to use with a list of coordinates and color which are stored in 3 listboxes (all are good color or coordinates) for automation for several pixels.
    I tried several things but none works.Here is the least buggy code but it apparently takes into account the coordinates but uses only the last item of my first ListBox (ARGB)

    Code:
    For h = 0 To ListBox1.Items.Count - 1
                NumericUpDown6.Value = ListBox1.Items(h)
                For i = 0 To ListBoxXF.Items.Count - 1
                    NumericUpDown1.Value = ListBoxXF.Items(i)
                    For ia = 0 To ListBoxYF.Items.Count - 1
                        NumericUpDown2.Value = ListBoxYF.Items(ia)
    
                        Button4.PerformClick()
    
                    Next
                Next
            Next
    Friends (true) coders, sorry for the burns caused to your eyes

    I need use in a loop the 3 différents listbox at the same index (items 1 of each listbox then 2, 3 ....) but seem i haven't the skill to perform that and i have no idea of where is the problem and what to look for.

    Thanks in advance !! I'm ok for every idea of change like no listbox or anything
    Last edited by archy-one; Mar 7th, 2019 at 04:40 PM.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,335

    Re: how use several Listboxes or controls for only one action (loop?)

    The very first thing you should do is rename all your controls so that each name actually describes the control and its purpose. Accepting all the default names like that makes them nearly meaningless. It makes it harder for us to work out what's going on and it makes it harder for you if you put this project down and come back to it later. It also makes it far more likely that you will make a mistake by using the wrong control.

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,335

    Re: how use several Listboxes or controls for only one action (loop?)

    If you want the items from each ListBox at the same index each time then you only need one loop. One For loop gives you a loop counter that you use as an index into all three ListBoxes, e.g.
    vb.net Code:
    1. For i = 0 To ListBox1.Items.Count
    2.     Dim a = ListBox1.Items(i)
    3.     Dim b = ListBox2.Items(i)
    4.     Dim c = ListBox3.Items(i)
    5.  
    6.     'Use a, b, c here.
    7. Next
    Note that this assumes that the ListBoxes all have the same number of items or, at least, the one you specify in the For statement has the fewest items. Your screenshot indicates that the second condition is met, although your description seems to suggest that the first condition should be met, so I'm a little confused about that.

    Also, I would recommend against the way you're doing it now, i.e. setting the NumericUpDown controls and calling PerformClick. I would suggest that you write a method that has parameters for all the variables and then you call that method as required. That would mean that your first code snippet would be replaced with a single call to that method and you'd pass values from the NumericUpDown controls and you would call the same method in the loop and pass values from the ListBox controls.

  4. #4

    Thread Starter
    New Member archy-one's Avatar
    Join Date
    Mar 2019
    Posts
    4

    Re: how use several Listboxes or controls for only one action (loop?)

    Totally agree with you ... I'm lost
    This is my big fault, I start by testing bits of code after I add functions, controls and after one hour is uncontrollable ... but it's too late !

    In this case I will try to explain a little more precisely my problem.

    Code:
    'here is the icon i opened before for pixel édition (color)
            Dim bm As New Bitmap(PictureBox2.Width, PictureBox2.Height)
            PictureBox2.DrawToBitmap(bm, PictureBox2.ClientRectangle)
    
            'here is to modify the color of icon (picturebox2) at specified coordinates
            'the original code is : bm.SetPixel(0, 0, Color.FromArgb(255, 0, 0, 0)) / i need to do that for each pixel in my 3 listboxes from the beginning to the end
            bm.SetPixel(NumericUpDown1.Value, NumericUpDown2.Value, Color.FromArgb(NumericUpDown3.Value, NumericUpDown4.Value, NumericUpDown5.Value, NumericUpDown6.Value))
    
            'apply
            PictureBox2.Image = bm
            'just to see the correction because original icon (picture2) is too small, i set sizemode to zoom on pictureBox1
            PictureBox1.Image = PictureBox2.Image
    hoping to have been clearer ..

  5. #5

    Thread Starter
    New Member archy-one's Avatar
    Join Date
    Mar 2019
    Posts
    4

    Re: how use several Listboxes or controls for only one action (loop?)

    oups..double

  6. #6

    Thread Starter
    New Member archy-one's Avatar
    Join Date
    Mar 2019
    Posts
    4

    Resolved Re: how use several Listboxes or controls for only one action (loop?)

    THANKS .... Now it's working
    when I see the simplicity of the thing ... I am ashamed to have spent several days without finding and it's now logic for me. Once again thank you !

    simple but effective here is my code - Resolved for now

    Code:
    For i = 0 To ListBox1.Items.Count - 1
                Dim a = ListBox1.Items(i)
                Dim b = ListBoxXF.Items(i)
                Dim c = ListBoxYF.Items(i)
    
                'Use a, b, c here.
    
                Dim bm As New Bitmap(PictureBox2.Width, PictureBox2.Height)
                PictureBox2.DrawToBitmap(bm, PictureBox2.ClientRectangle)
                'here i don't need NumericUpDown3.Value,NumericUpDown4.Value, NumericUpDown5.Value for the moment and i use only the end of ARGB color (other listbox not see in screenshot)
                bm.SetPixel(b, c, Color.FromArgb(NumericUpDown3.Value, NumericUpDown4.Value, NumericUpDown5.Value, a))
                PictureBox2.Image = bm
                PictureBox1.Image = PictureBox2.Image
    
            Next

Posting Permissions

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



Click Here to Expand Forum to Full Width