all groups > dotnet windows forms > august 2007 >
You're in the

dotnet windows forms

group:

How to manually invoke PictureBox.Resize?


How to manually invoke PictureBox.Resize? nvx
8/30/2007 6:12:31 AM
dotnet windows forms:
Hello,
I experience a strange problem with PictureBox I draw onto. My
application has a fill-docked TabControl on its form and there is
PictureBox on one of the TabPages. If I resize the form (hence the
PictureBox should resize too) WITHOUT switching to the TabPage
containing the PictureBox before drawing onto it, the PictureBox does
not change its dimensions and the Bitmap of the size of PictureBox I
create before drawing has wrong dimensions as well. After switching to
the TabPage containing the PictureBox the image drawn before just
stretches/shrinks depending on whether I have enlarged or made the
form smaller.

An example:
1. At this point the PictureBox is 800x600 pixels and is placed on a
TabPage which is not selected.
2. We resize the form (maximize it) and the PictureBox should now be
approx. 1000x720 pixels.
3. Now we draw something onto the PictureBox: we take its dimensions,
which are according to PB's properties STILL 800x600 (!!!), create a
Bitmap and draw what we want. After that we flush the bitmap onto the
graphics using graphics.DrawImageUnscaled(...). IT IS CLEAR THAT THE
IMAGE WE HAVE DRAWN HAS WRONG DIMENSIONS, BUT HOW TO ENSURE THE
PICTUREBOX CHANGES ITS DIMENSIONS EVEN IF IT IS NOT VISIBLE?
4. After selecting the TabPage with PictureBox the image is
stretched...


Well, is there a way to "invoke" the Resize of PictureBox / to force
it to correct its dimensions according to dimensions of its parent
control and current dock style?

Thanks a lot for any help...

Best regards
nvx
Re: How to manually invoke PictureBox.Resize? ClayB
8/30/2007 10:10:48 AM
Here is something you might be able to use to work around the problem.
Before trying to access the size of the picturebox, explicitly set its
tabpage to be the size of the selectedtab.

//tabPage2 holds the pictureBox
tabPage2.Size = tabControl1.SelectedTab.Size;
Size size = pictureBox1.Size;

============================
Clay Burch
Syncfusion, Inc.
Re: How to manually invoke PictureBox.Resize? nvx
8/30/2007 10:46:57 AM
Dear ClayB,
thank you very much for the advice, it works great! :)

Have a nice day...

Best regards
nvx



[quoted text, click to view]

Re: How to manually invoke PictureBox.Resize? Bob Powell [MVP]
8/30/2007 11:54:29 PM
Why and how do you "Draw something" onto a picture box??

You should probably read the GDI+ FAQ including the article about the #1
most asked question, how and where to obtain your Graphics object and
what event driven systems are all about.
--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.





[quoted text, click to view]
AddThis Social Bookmark Button