Click to See Complete Forum and Search --> : Background image resize
madcrow74
July 16th, 2003, 05:27 AM
I've assigned a background image to a MDI form.
When i resize the form, the image retain the same size, but I want it to resize with the form.
i've tried in the Resize event this code:
Graphic g = this.CreateGraphic();
g.DrawImage(img, this.ClientRectangle);
but it doesn't works...
How can I do?
tomcat101
July 16th, 2003, 06:58 AM
Hi!
i've found this in the MSDN a few days ago, maybe it helps:
e.Graphics.DrawImageUnscaled(yourImage, x,y,width, heigth);
the example code looks good but i've not tried this
blue skies
newvisva
July 16th, 2003, 07:54 AM
IF u don't want to code then do the following:
1. Place a picbox on ur MDI randomly (no need to resize it)
2. Picbox property select image NOT background image!
3. Picbox property set the sizemode="StretchImage"
4. Picbox property set dock to the middle box (DockStyle.Fill)
5. Ctrl-F5
Done.
madcrow74
July 16th, 2003, 11:39 AM
I've tried this:
private void Form1_Resize(object sender, System.EventArgs e)
{
this.CreateGraphics().DrawImageUnscaled(sfondo,this.ClientRectangle);
}
but it doesn't work...
The other method, with picturebox, hide every MDIchild form that i have to load after the main form...even if i SendBack the picturebox...
tomcat101
July 17th, 2003, 03:13 AM
Hi,
okay, here's an example with only one problem, it flickers when it's resizing:
add to methods with the property page of your Windows-Form:
"Paint" and "SizeChanged"
private Image myImg;
private Rectangle myRec;
public Form1(){myImg = Image.FromFile("c:\\Blaue Berge.jpg");}
private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e) {
myRec = new Rectangle(0,0,this.Right,this.Bottom);
e.Graphics.DrawImage(myImg, myRec);
}
private void Form1_SizeChanged(object sender, System.EventArgs e)
{ this.Refresh(); }
with this code the image is sized to the borders of the Window-Form, but i guess you'll need a solution to avoid the flickering ( if you have one let me know it )
hope it helps
blue skies
rg
tomcat101
July 17th, 2003, 03:53 AM
yo man,
i've found a solution for the flickering ( thank god for google.com ):
add this to the initialize() of your view:
this.SetStyle(ControlStyles.DoubleBuffer, true);
this.SetStyle(ControlStyles.AllPaintingInWmPaint , true);
this.SetStyle(ControlStyles.UserPaint, true);
it works really nice, i was really surprised!
think i've to change my mind about microsoft ;-)
blue skies
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.