P
Peter Row
Hi,
I am trying to draw on top of the main menu area of a form (this is just a
test
at the moment). I'm handling the forms paint event and using the following
code:
private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs
e)
{
try
{
using (Graphics g = Graphics.FromHwnd(mainMenu1.Handle))
{
RectangleF testBox = new RectangleF(g.ClipBounds.Width - 50,
g.ClipBounds.Y, 50, g.ClipBounds.Height);
using (StringFormat sf = new StringFormat())
{
sf.Alignment = StringAlignment.Center;
sf.LineAlignment = StringAlignment.Center;
g.FillRectangle(Brushes.Yellow, testBox);
g.DrawString("TEST", this.Font, Brushes.Black, testBox, sf);
}
}
base.OnPaint(e);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
....however I get an OutOfMemoryException error on the line above that starts
using (Graphics g = Graphics.FromHwnd(...
Anybody have any ideas about how I might achieve this?
All ideas welcome, although I don't want to have to use the Win API if I can
help it.
Regards,
Peter
I am trying to draw on top of the main menu area of a form (this is just a
test
at the moment). I'm handling the forms paint event and using the following
code:
private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs
e)
{
try
{
using (Graphics g = Graphics.FromHwnd(mainMenu1.Handle))
{
RectangleF testBox = new RectangleF(g.ClipBounds.Width - 50,
g.ClipBounds.Y, 50, g.ClipBounds.Height);
using (StringFormat sf = new StringFormat())
{
sf.Alignment = StringAlignment.Center;
sf.LineAlignment = StringAlignment.Center;
g.FillRectangle(Brushes.Yellow, testBox);
g.DrawString("TEST", this.Font, Brushes.Black, testBox, sf);
}
}
base.OnPaint(e);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
....however I get an OutOfMemoryException error on the line above that starts
using (Graphics g = Graphics.FromHwnd(...
Anybody have any ideas about how I might achieve this?
All ideas welcome, although I don't want to have to use the Win API if I can
help it.
Regards,
Peter