Picturebox autosize error

LeeC

New member
Joined
Jan 24, 2006
Messages
4
Programming Experience
10+
Hi all,
Does anyone know a way round this problem perhaps?

I have a picturebox with a 3D border. When you set this type of picturebox to autosize, it doesn't take into account the border and actually resizes the whole control to the size of the image, rather than the internal displayable area. This means that you lose 4 pixels with a 3D border and 2 pixels with a fixed single border. I can draw a surrounding box but I would have thought that the control would have autosized correctly. Any help is much appreciated, thanks.

Lee C
 

Don Delegate

Well-known member
Joined
Jan 4, 2006
Messages
140
Location
Belgium
Programming Experience
10+
Is this .NET 1.1 or 1.0 ?
I cannot reproduce this behaviour with .NET 2.0
VB.NET:
[COLOR=blue]Private[/COLOR] [COLOR=blue]Sub[/COLOR] testImage()
[COLOR=black][FONT=Courier New]   PictureBox1.SizeMode = PictureBoxSizeMode.AutoSize
    PictureBox1.Image = [COLOR=blue]My[/COLOR].Resources.award
    [COLOR=blue]Dim[/COLOR] sb [COLOR=blue]As[/COLOR] [COLOR=blue]New[/COLOR] System.Text.StringBuilder
    sb.AppendLine(PictureBox1.Image.GetBounds(GraphicsUnit.Pixel).ToString)
    sb.AppendLine(PictureBox1.Bounds.ToString)
    sb.AppendLine(PictureBox1.DisplayRectangle.ToString)
    PictureBox1.BorderStyle = BorderStyle.FixedSingle
    sb.AppendLine(PictureBox1.Bounds.ToString)
    sb.AppendLine(PictureBox1.DisplayRectangle.ToString)
    PictureBox1.BorderStyle = BorderStyle.Fixed3D
    sb.AppendLine(PictureBox1.Bounds.ToString)
    sb.AppendLine(PictureBox1.DisplayRectangle.ToString)
    MessageBox.Show(sb.ToString)
    [COLOR=blue]End[/COLOR] [COLOR=blue]Sub[/COLOR]
[/FONT][/COLOR]

gives +4 for both width and height for BorderStyle.Fixed3D and +2 for BorderStyle.FixedSingle
 

LeeC

New member
Joined
Jan 24, 2006
Messages
4
Programming Experience
10+
Don Delegate said:
Is this .NET 1.1 or 1.0 ?
It's 1.1 in VS 2003.

I don't quite understand your reply, are you saying that the size of your control increases if you change the border styles? Mine appears to keep the same outer dimensions but subtracts the width away from the inner space.

Easiest way to see the problem is to get an image that is simply a dark square with a bright outline. Assign it to the picturebox control and watch the line disappear as you change the borderstyle.
 

Don Delegate

Well-known member
Joined
Jan 4, 2006
Messages
140
Location
Belgium
Programming Experience
10+
LeeC said:
... are you saying that the size of your control increases if you change the border styles?
Exactly.
I fired up VS2003 and ran a quick test and indeed in .NET 1.1 the size of the PictureBox stays the same (and the DisplayRectangle shrinks). Whilst in .NET 2.0 the DisplayRectangle stays the same and the PictureBox grows (or shrinks) as needed.

So it seems it was a bug in .NET Winforms 1.1, corrected in .NET Winforms 2.0.
 

LeeC

New member
Joined
Jan 24, 2006
Messages
4
Programming Experience
10+
Thanks for that Don, at least I know what I need to do now.

So annoying that we try and write bug free code and are hindered by tools written by someone who didn't write bug free code.

I have found moving from VB6 to .NET bad enough, I was kind of convinced I was doing something stupid. At least I wasn't... well not that time anyway ;)

Thanks again
Lee C
 
Top Bottom