Image Strectch using Graphics.DrawImage()

M

mrabie

hi all,

i am writing my own messagebox control, it's composed of 3 parts
1) Top bar
2) Middle Area (resizable)
3) Buttom bar

the top and bottom bar sizes doesn't change, but the middle area
changes depending on the size of the dialogbox (im my case a form that
i resize). When i draw the middle image it moves 1 pixel to the right
and goes 1 pixel out of the display bounds... i don't know why, here's
what i am doing

protected override void OnPaint(PaintEventArgs e)
{
gxBuffer.DrawImage(topBar, 0, 0);
gxBuffer.DrawImage(middleArea,new Rectangle(0,this.Location
+topBar.Height,this.Width,this.Height),new
Rectangle(0,0,this.middleArea.Width,this.middleArea.Height),
GraphicsUnit.Pixel);
gxBuffer.DrawImage(buttomBar, 0, this.Location.Y -
buttomBar.Height);
e.Graphics.DrawImage(offScreen, 0, 0);
}

although when i place the middleArea image in a picturebox and stretch
it, it works well....
any pointers would be really apreciated

Thanks
 
J

Jin Chang

hi all,

i am writing my own messagebox control, it's composed of 3 parts
1) Top bar
2) Middle Area (resizable)
3) Buttom bar

the top and bottom bar sizes doesn't change, but the middle area
changes depending on the size of the dialogbox (im my case a form that
i resize). When i draw the middle image it moves 1 pixel to the right
and goes 1 pixel out of the display bounds... i don't know why, here's
what i am doing

protected override void OnPaint(PaintEventArgs e)
{
gxBuffer.DrawImage(topBar, 0, 0);
gxBuffer.DrawImage(middleArea,new Rectangle(0,this.Location
+topBar.Height,this.Width,this.Height),new
Rectangle(0,0,this.middleArea.Width,this.middleArea.Height),
GraphicsUnit.Pixel);
gxBuffer.DrawImage(buttomBar, 0, this.Location.Y -
buttomBar.Height);
e.Graphics.DrawImage(offScreen, 0, 0);
}

although when i place the middleArea image in a picturebox and stretch
it, it works well....
any pointers would be really apreciated

Thanks

Not really sure without seeing the rest of your code, but it could be
related to:

this.Location+topBar.Height

because this.Location is a Point. I haven't tested what result is
returned when you do this (perhaps increment both X and Y values?).

- Jin
 
M

mrabie

Not really sure without seeing the rest of your code, but it could be
related to:

this.Location+topBar.Height

because this.Location is a Point.  I haven't tested what result is
returned when you do this (perhaps increment both X and Y values?).

- Jin- Hide quoted text -

- Show quoted text -

Hi,
i tried stretcing it to the whole screen
(Rectangle(0,0,this.Width,this.Height) without using this.Location
+topBar.Height), incremented both X and Y, X alone everything it just
wont draw correctly, here's the rest of the code

public partial class Form2 : Form
{
Bitmap offScreen;
Bitmap topBar;
Bitmap buttomBar;
Bitmap middleBar;
Graphics gxBuffer;
string path;

public Form2()
{
InitializeComponent();
path =
System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase);
topBar = new Bitmap(path + @"\mbTopBar.png");
middleBar = new Bitmap(path + @"\mbMiddle.png");
buttomBar = new Bitmap(path + @"\mbButtom.png");
offScreen = new Bitmap(this.Width, this.Height);
gxBuffer = Graphics.FromImage(offScreen);

}

public Form2(int param_Width, int param_Height)
{
InitializeComponent();
this.Size = new Size(param_Width, param_Height);
path =
System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase);
topBar = new Bitmap(path + @"\mbTopBar.png");
middleBar = new Bitmap(path + @"\mbMiddle.png");
buttomBar = new Bitmap(path + @"\mbButtom.png");
offScreen = new Bitmap(this.Width, this.Height);
gxBuffer = Graphics.FromImage(offScreen);

}


protected override void OnPaint(PaintEventArgs e)
{
gxBuffer.DrawImage(topBar, 0, 0);
gxBuffer.DrawImage(middleArea,new
Rectangle(0,this.Location+topBar.Height,this.Width,this.Height),new
Rectangle(0,0,this.middleArea.Width,this.middleArea.Height),GraphicsUnit.Pixel);
gxBuffer.DrawImage(buttomBar, 0, this.Location.Y -
buttomBar.Height);
e.Graphics.DrawImage(offScreen, 0, 0);
}


}
}

thanks for your help
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Button onPaint event doesn't fire?!?! 1
AlphaBlend in CF 4
region clipping in Win 2k 4
A Little Help?? 2

Top