Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello Community, (New Guy Here qith vb.net 2010 question)

Im struggling to figure this out.

What im trying to do is draw either a picturebox or image then skip 50 pixels then draw another image or picbox and repeat this process. I need this to happen across the entire window form and stop the the end width pixel of the form.

Possible? I figure it might be some sort of loop or array maybe even both.. but im new to this area of VB.net programming so im hoping for help.

If it means anything what i am trying to do here is something ive been trying to accomplish for years using vb6 and now vb.net and no luck.

Thanks in advance! You have my gratitude eternally you really have no idea seriously!
Posted
Updated 10-Oct-14 12:21pm
v2
Comments
Sergey Alexandrovich Kryukov 10-Oct-14 18:23pm    
Was your previous question removed? Probably it was automatically removed due to some abuse reports: not clear, not a question.
I already told you: forget PictureBox. Explain what do you want to draw and where. What do you have on input? What's the problem? Why all that?
—SA
Member 11133722 10-Oct-14 18:34pm    
I removed and made more simplified i think.

Starting at the window form frame Draw an Image separate by 50pixels then Draw Image then 50pixels then Draw Image then 50pixels then Draw Image, so on and so on until it reaches the window frame width end. I dont want to do this manually because its going to need to be dependent on the window width which may change.

Trying to draw pictures dynamically with 50 pixel spacing between them on my Window.

I hope this may make more sense.
Sergey Alexandrovich Kryukov 10-Oct-14 18:44pm    
Hm. Somehow, I did not spotted the improvement. You really need to be more clear. This is not about language, this is about your logic.
—SA
Sergey Alexandrovich Kryukov 10-Oct-14 18:45pm    
So, are they fixed images? Then use PictureBox, really, and learn some layout. This is easy. How about the window? Fixed size? Do you want a matrix of images or what? What do you want to see if they don't fit in the form? Are the image sized identical or not? Do you want them to freely flow in rows, perhaps? There are so many possible designs behind your vague description...
—SA
Member 11133722 10-Oct-14 18:59pm    
Once again, Sorry.

Images are all the same size. How would i loop images and the loop stop at the window frame. One line matrix maybe?

Ok ill explain what im making or trying to make. I have several png icons that look like christmas light bulbs. I want to make it look like there are bulbs placed along the top of my program form. Make sense? so im trying to place images with spacing thats dynamic because the window size may change and i dont want it to look like its cut off if you do so placing them manually. a good example is here but its on the top of the desktop instead of in the form window / area. http://img.informer.com/screenshots/17/17338_2.jpg

See what i mean?

sorry if i cant explain it better and appreciate your time if its still not enough but thats the best i can do. i am a beginner.

1 solution

You could simply arrange the instance of PictureBox in a loop, the way you want. A matrix would be a nested X-Y loop, and so on.

However, you may want the images to flow as you resize the window, preserving those gaps. Then you can use the class System.Windows.Forms.FlowLayoutPanel:
http://msdn.microsoft.com/en-us/library/system.windows.forms.flowlayoutpanel%28v=vs.110%29.aspx[^].

How to preserve the 5-pixel gaps then? You need to put each PictureBox in a fixed-size panel 5 pixels taller and wider. And then you can use the property Padding on that panel to create some gaps, say, on right and bottom. (Then you may need to make the rightmost panel of different Width and Padding, to unwanted avoid extra gap.) And then drop those bigger panel instances in a flow panel, which will auto-arrange the layout. It's just a matter of trying, to see what would you prefer and evoke further ideas.

You also need to know how to add a control in code. Here is how:
VB
Dim someChildControl As Control = '...
Dim someOtherChildControl As Control = '...
Dim someParentControl As Control = '...

' set some other properties, size, location, DockStyle, whatever applicable...

someParentControl.Controls.Add(someChildControl);
' or, same thing:
someOtherChildControl.Parent = someParentControl;


I also have another, universal idea. Create a prototype of what you want to see using the designer, build/run the project. And then, look at the auto-generated code to see how it was implemented in code. After you understand it, use the technique in your own code.

—SA
 
Share this answer
 
v3
Comments
BillWoodruff 11-Oct-14 10:39am    
+5 See my comment to the OP raising a possible complication.
Sergey Alexandrovich Kryukov 11-Oct-14 20:21pm    
Thank you, Bill.
And I added a comment to your important comment on resizing.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900