Click here to Skip to main content
13,257,667 members (73,985 online)
Rate this:
Please Sign up or sign in to vote.
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 1-Jan-13 6:16am
So, what's the problem? Perhaps you need to explain about "other things", otherwise it's hard to analyze your situation.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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!

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.
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.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.171114.1 | Last Updated 1 Jan 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100