PictureBox + Color

OK, here's where I'm at -
I've created a panel (400x400) with 324 PictureBoxes (yes, unfortunately I felt the need to use a 18x18 grid of PictureBoxes).

Each PictureBox has some code which changes the colour when pressed. Below is an example for PictureBox2:


Private Sub PictureBox2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox2.Click

paintme(PictureBox2)

End Sub
 


And the code for painting:


Public Function paintme(ByVal square)

square.BackColor = ColorDialog1.Color

End Function
 


I need some script which changes the color of multiple PictureBoxes when they are selected somehow (dragging ) apon the click of a mouse.

I need to know if this is at all possible - I have another idea to use only 1 PictureBox, and use the CreateGraphics() control to fill the squares of an invisible grid. I just need soe guidelines.

Thank you very much for your time,

Robert Hoath (hoathdesigns@gmail.com)



Answer this question

PictureBox + Color

  • Epilif

    Alright. Firstly I would make a module, and inside type the following:

    Global Bob(20,20) as Integer
    Global MX as Integer
    Global MY as Integer

     

    This defines 400 different 'Bob's. Imagine a grid of integers, 20 by 20. (It's actually 21 by 21 because 0 counts). MX and MY is to keep track of where you're mouse is.

    Now in form1.
    You only need to make one, big, perfect square, picturebox1. And you type the following code under Picture1_Mousemove:

    MX=X
    MY=Y

     

    Make two pictureboxes, picturebox2(0) and picturebox2(1). The brackets (0) and (1) mean they are arrays, just like Bob. You make them by copy and pasting picturebox2 once.

    Here's where it gets 'fun'. Under Picture1_click, you fill in this code:

    Bob(CInt((MX / Picture1.Width) * 20 + 0.5), CInt((MY / Picture1.Height) * 20 + 0.5)) = CInt(Rnd)
    For X = 0 To 19
    For Y = 0 To 19
    a = Picture1.Width / 20
    Picture1.PaintPicture Picture2(Bob(X + 1, Y + 1)).Picture, X * a, Y * a, a, a
    Next
    Next

     


    So, when you click on the picturebox1, it creates a grid of 20 by 20 of picture2(0). When you click on any one, it randomizes between picture2(0) or picture2(1).

    Now, have fun translating that gibberish into vb.net gibberish.

  • chillah

    You sure about that They're almost the same. Try me. What would you do in VB6

    Robert Hoath

  • Stevejh

       I know a bit about picture boxes, and I'm sure I could help. First thing though, it's a bad idea to use that many picture boxes. It slows down visual basic. What you can do instead is use Picture1.PaintPicture or something. I could help you with that, and I would, but I'm not sure what exactly you want to do.
    :/

  • nikonek

    Oh, I'm sorry for getting you riled up, but I use visual basic 6. I've tried using vb.net and it seems to view my code as syntax errors everywhere. What I would have done with visual basic 6 is make an array variable. So lets say:
    Bob(20,20) as Integer
    that would keep track of the colours, and I would paint the colours onto the picturebox. But that wont work on vb.net... Sorry again

  • pcoelho

    Thank you for your interest.

    I want to make a small grid (20x20 is GREAT) which users can paint by clicking squares (or dragging to paint multiple areas). I have no idea how to approach this problem, so i just went for the most straightfoward way i could think of.

    I'm using VB.NET Express Edition BETA 2 in case you need to know.

    Robert Hoath

  • PictureBox + Color