J
Joe Keller
Hello,
I've got some code that draws a rectangle around the object passed into a
method call and this works great on a form. However, when I try to call
CreateGraphics() to get a drawing context for a tab page, the call fails.
This code works on a form:
private void DrawFocus(Control sender, Boolean on)
{
Color penColor;
Pen penDraw;
if (on == true)
penColor = Color.Red;
else
penColor = Color.White;
penDraw = new Pen(penColor);
Rectangle rt = sender.Bounds;
rt.Inflate(3,2);
// Note call to CreateGraphics() Here Works Fine
Graphics gr = this.CreateGraphics();
gr.DrawRectangle(penDraw,rt);
gr.Dispose();
penDraw.Dispose();
}
But this call fails on a tab page:
private void DrawFocus(Control sender, Boolean on)
{
Color penColor;
Pen penDraw;
if (on == true)
penColor = Color.Red;
else
penColor = Color.White;
penDraw = new Pen(penColor);
Rectangle rt = sender.Bounds;
rt.Inflate(3,2);
// Code fails Here
Graphics gr = this.tabControl1.TabPages[0].CreateGraphics();
gr.DrawRectangle(penDraw,rt);
gr.Dispose();
penDraw.Dispose();
}
Can I draw on a tab page control? Am I just not getting the correct drawing
context?
Thanks!
Joe
I've got some code that draws a rectangle around the object passed into a
method call and this works great on a form. However, when I try to call
CreateGraphics() to get a drawing context for a tab page, the call fails.
This code works on a form:
private void DrawFocus(Control sender, Boolean on)
{
Color penColor;
Pen penDraw;
if (on == true)
penColor = Color.Red;
else
penColor = Color.White;
penDraw = new Pen(penColor);
Rectangle rt = sender.Bounds;
rt.Inflate(3,2);
// Note call to CreateGraphics() Here Works Fine
Graphics gr = this.CreateGraphics();
gr.DrawRectangle(penDraw,rt);
gr.Dispose();
penDraw.Dispose();
}
But this call fails on a tab page:
private void DrawFocus(Control sender, Boolean on)
{
Color penColor;
Pen penDraw;
if (on == true)
penColor = Color.Red;
else
penColor = Color.White;
penDraw = new Pen(penColor);
Rectangle rt = sender.Bounds;
rt.Inflate(3,2);
// Code fails Here
Graphics gr = this.tabControl1.TabPages[0].CreateGraphics();
gr.DrawRectangle(penDraw,rt);
gr.Dispose();
penDraw.Dispose();
}
Can I draw on a tab page control? Am I just not getting the correct drawing
context?
Thanks!
Joe