Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VS2008C#
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 5:16am
Comments
Sergey Alexandrovich Kryukov at 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

Rate this: bad
good
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!
 
—SA
  Permalink  
v2
Comments
Coffee Monster at 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 at 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)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 422
1 sanket saxena 355
2 Abhinav S 258
3 OriginalGriff 250
4 CPallini 205
0 Sergey Alexandrovich Kryukov 8,704
1 OriginalGriff 5,000
2 Peter Leow 3,839
3 Maciej Los 3,535
4 Er. Puneet Goel 3,107


Advertise | Privacy | Mobile
Web04 | 2.8.140415.2 | Last Updated 1 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid