Click here to Skip to main content
15,883,802 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Help a newbie out! I'm just a hobby programmer, so bear with me.

I have a table of docked pictureboxes where I'm trying to scale the photos inside them relative to the size of the pictureboxes. So, for instance, if I maximize the window the photos will also resize. I know picturebox has properties for automatic scaling, but I'm doing other things here that would make that counterproductive. So I need to find a way to code it. Fun fun!

The problem is that I can't get the size of the pictureboxes. I think this is probably because they're docked to fill the table cell. So, I need to find another way to access their dimensions if one exists.

Also, to make things even harder on myself, I've placed this function in another class file. What I've passed to the function is the picturebox handle. I know this gives me access to it's properties, but I have a suspicion that I'll have to somehow access the parent cell's properties. Then again, those auto-size, too.. smh

Thanks, guys!
Posted
Comments
Sergey Alexandrovich Kryukov 1-Jan-13 13:37pm    
So, what's the problem? Perhaps you need to explain about "other things", otherwise it's hard to analyze your situation.
—SA

1 solution

Please see my comment to the question: you omitted some details which makes your situation look uncertain.

I have a general advice for you, based just on the following rule of thumb: if you are starting to have trouble with PictureBox, its the time to get rid of it.

This is because this class is not really needed. You can always render any image in any control by yourself, using GDI. The only purpose of the class PictureBox is to create a highly simplified way of showing a static image in your application. This is just a middleman between a parent control and the image with scaling, it does not do anything useful if you try to do a bit more.

At the same time, immediate rendering of image on the control is very easy. And it will be dramatically easier in the situations where the PictureBox start giving you even the minimal trouble. You can render the image in the cell using a table control (whatever it is, DataGridView or anything), or insert any other control, a custom control derived from System.Windows.Forms.Control or Panel and render the image on it.

I explain it all and explain what to do in my past answers:
How do I clear a panel from old drawing[^],
draw a rectangle in C#[^],
Append a picture within picturebox[^].

See also these past answers:
Drawing Lines between mdi child forms[^],
capture the drawing on a panel[^],
What kind of playful method is Paint? (DataGridViewImageCell.Paint(...))[^].

Happy New Year!

—SA
 
Share this answer
 
v2
Comments
Coffee Monster 1-Jan-13 15:38pm    
Perfect. Thank you. I had a feeling that I was just heading in the wrong direction. The "other things" would be basic manipulation like zoom and pan. Now I see that the picturebox was just getting in my way.
Sergey Alexandrovich Kryukov 1-Jan-13 16:05pm    
I suspected "other things" are something like that. It completely justifies my point. Trash PictureBox right away, it will make only a hassle. You have, basically, three options. One I described, others are based on WPF, where zoom and pan are already implemented...

You are very welcome.
Good luck, call again.
—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