Windows Develop Bookmark and Share   
 index > Windows Forms Designer > Why BackgroundImageLayout::center don't act like PictureBoxSizeMode::CenterImage
 

Why BackgroundImageLayout::center don't act like PictureBoxSizeMode::CenterImage

Hi,

I got a problem with the BackgroundImageLayout in the pictureBox.

I toogle the BackgroundImageLayout from Zoom to Center to see more closer picture when using high res image using :

(code in C++)
pictureBox1->BackgroundImageLayout:Tongue Tiedet(System::Windows::Forms::ImageLayout::Center);
or
pictureBox1->BackgroundImageLayout:Tongue Tiedet(System::Windows::Forms::ImageLayout::Zoom);

Now, when i put the image in pictureBox1->Image, the layout control are control with pictureBox1->SizeMode, and everything was working fine (togeling from center to zoom), but since i am placing my image in the background someting strange append.

When the picture is in the background, if the picture size is smaller then the pictureBox, no problem appen.
When the picture is in the background, if the picture size is Bigger then the pictureBox, the layout react to the "Center" option from the "BackgroundImageLayout" exactly as is was set to "None".

So does some one have a solution to make BackgroundImageLayout::center act like PictureBoxSizeMode::CenterImage ?

Ho, and yes, i really need to use the BackgroundImage because i use the BackgroundImage and the Image of the pictureBox at the same time!

Thanks
V.L.



exemple (C++):

private: System::Void button1_Click(System:Surprisebject^ sender, System::EventArgs^ e) {
using namespace System:Big Smilerawing;
openFileDialog1->ShowDialog();
Image^ image = Image::FromFile(openFileDialog1->FileName);
pictureBox1->BackgroundImage = image;
//pictureBox1->Image = image;
}

private: System::Void button2_Click(System:Surprisebject^ sender, System::EventArgs^ e) {
pictureBox1->SizeMode:Tongue Tiedet(System::Windows::Forms:Stick out tongueictureBoxSizeMode::CenterImage);
pictureBox1->BackgroundImageLayout:Tongue Tiedet(System::Windows::Forms::ImageLayout::Center);
}

private: System::Void button3_Click(System:Surprisebject^ sender, System::EventArgs^ e) {
pictureBox1->SizeMode:Tongue Tiedet(System::Windows::Forms:Stick out tongueictureBoxSizeMode::Zoom);
pictureBox1->BackgroundImageLayout:Tongue Tiedet(System::Windows::Forms::ImageLayout::Zoom);
}
Van Lothar  Tuesday, November 13, 2007 9:57 PM

I have a workaround for you, just paint the background when the BackgroundImageLayout is set to Center,

Code Block

myPictureBox : PictureBox

{

protected override void OnPaintBackground(PaintEventArgs pevent)

{

base.OnPaintBackground(pevent);

if (this.BackgroundImage != null)

{

if (this.BackgroundImageLayout == ImageLayout.Center)

{

pevent.Graphics.DrawImage(this.BackgroundImage,

(this.Width - this.BackgroundImage.Width) / 2,

(this.Height - this.BackgroundImage.Height) / 2);

}

}

}

protected override void OnBackgroundImageLayoutChanged(EventArgs e)

{

base.OnBackgroundImageLayoutChanged(e);

if (this.BackgroundImageLayout == ImageLayout.Center)

{

this.Invalidate();

}

}

}

I have a workaround for you, just paint the background when the BackgroundImageLayout is set to Center,

Code Block

myPictureBox : PictureBox

{

protected override void OnPaintBackground(PaintEventArgs pevent)

{

base.OnPaintBackground(pevent);

if (this.BackgroundImage != null)

{

if (this.BackgroundImageLayout == ImageLayout.Center)

{

pevent.Graphics.DrawImage(this.BackgroundImage,

(this.Width - this.BackgroundImage.Width) / 2,

(this.Height - this.BackgroundImage.Height) / 2);

}

}

}

protected override void OnBackgroundImageLayoutChanged(EventArgs e)

{

base.OnBackgroundImageLayoutChanged(e);

if (this.BackgroundImageLayout == ImageLayout.Center)

{

this.Invalidate();

}

}

}

You can use google to search for other answers

Custom Search

More Threads

• Microsoft Visual studio has encountered a problem and needs to close
• Visual Studio / Windows Form Designer crashes when trying to edit a toolstrip item
• Tracking text entry position
• difference between PointToScreen and PointToClient
• displaying zero with single digit int
• Barcord Scan
• VS 2008 error HRESULT 0x80042929
• Restricting color change of windows title bar in my application.
• Relating Combos on Windows Forms
• Protected control not select-able (single click) at design time on an inherited form