B
Bob Dankert
I am trying to create a control which inherits a textbox and has granhandles
on the top and bottom of the control allowing the user to resize the control
vertically on the form. I have no problem handling the mouse events and
resizing the control, however I am haivng problems drawing grab handles on
the control. I have tried using ControlPaint.DrawGrabHandle but they will
frequently disappear and I can not get the grab handle to appear in the
middle of the border; only above the border using the form's graphics or
below the border using the controls graphics (which gets erased by the
control as soon as text is types). I have tried drawing the rectangle
manually, using the form graphics to draw the half of the rectangle falling
outside of the controls bounds and the controls graphics to draw the part of
the rectangle within the control. This works to a point, however while
moving the mouse around the screen parts of the grab handles will get
erased. The source for the textbox is as follows (this is trying to draw
just the top box - once I get this working, I can easily draw the bottom):
class textBox : TextBox
{
private bool drawRect = false;
protected override void OnGotFocus(EventArgs e)
{
Trace.WriteLine("Go Focus " + this.Name);
this.drawRect = true;
this.drawGrabHandles();
base.OnGotFocus(e);
}
protected override void OnLostFocus(EventArgs e)
{
Trace.WriteLine("Lost Focus " + this.Name);
this.drawRect = false;
this.clearGrabHandles();
base.OnLostFocus(e);
}
private void drawGrabHandles()
{
int edge = (Width / 2) - 3;
Rectangle txtRect = new Rectangle(Point.Empty, this.DisplayRectangle.Size);
Graphics txtGraphics = this.CreateGraphics();
Graphics formGraphics = this.Parent.CreateGraphics();
txtGraphics.FillRectangle(Brushes.White, txtRect.X + edge, -1, 6, 3);
txtGraphics.DrawRectangle(Pens.Black, txtRect.X + edge, -1, 6, 3);
formGraphics.FillRectangle(Brushes.White, this.Bounds.X + edge,
this.Bounds.Y - 3, 6, 3);
formGraphics.DrawRectangle(Pens.Black, this.Bounds.X + edge, this.Bounds.Y -
3, 6, 3);
txtGraphics.Dispose();
formGraphics.Dispose();
}
private void clearGrabHandles()
{
this.Parent.Invalidate();
this.Invalidate();
}
protected override void WndProc(ref Message m)
{
if (m.Msg == 0x0085 || m.Msg == 0x000F) // WM_NCPAINT or WM_PAINT
{
if (this.drawRect == true)
this.drawGrabHandles();
else
this.clearGrabHandles();
}
base.WndProc(ref m);
}
}
Thanks for any help,
Bob Dankert
on the top and bottom of the control allowing the user to resize the control
vertically on the form. I have no problem handling the mouse events and
resizing the control, however I am haivng problems drawing grab handles on
the control. I have tried using ControlPaint.DrawGrabHandle but they will
frequently disappear and I can not get the grab handle to appear in the
middle of the border; only above the border using the form's graphics or
below the border using the controls graphics (which gets erased by the
control as soon as text is types). I have tried drawing the rectangle
manually, using the form graphics to draw the half of the rectangle falling
outside of the controls bounds and the controls graphics to draw the part of
the rectangle within the control. This works to a point, however while
moving the mouse around the screen parts of the grab handles will get
erased. The source for the textbox is as follows (this is trying to draw
just the top box - once I get this working, I can easily draw the bottom):
class textBox : TextBox
{
private bool drawRect = false;
protected override void OnGotFocus(EventArgs e)
{
Trace.WriteLine("Go Focus " + this.Name);
this.drawRect = true;
this.drawGrabHandles();
base.OnGotFocus(e);
}
protected override void OnLostFocus(EventArgs e)
{
Trace.WriteLine("Lost Focus " + this.Name);
this.drawRect = false;
this.clearGrabHandles();
base.OnLostFocus(e);
}
private void drawGrabHandles()
{
int edge = (Width / 2) - 3;
Rectangle txtRect = new Rectangle(Point.Empty, this.DisplayRectangle.Size);
Graphics txtGraphics = this.CreateGraphics();
Graphics formGraphics = this.Parent.CreateGraphics();
txtGraphics.FillRectangle(Brushes.White, txtRect.X + edge, -1, 6, 3);
txtGraphics.DrawRectangle(Pens.Black, txtRect.X + edge, -1, 6, 3);
formGraphics.FillRectangle(Brushes.White, this.Bounds.X + edge,
this.Bounds.Y - 3, 6, 3);
formGraphics.DrawRectangle(Pens.Black, this.Bounds.X + edge, this.Bounds.Y -
3, 6, 3);
txtGraphics.Dispose();
formGraphics.Dispose();
}
private void clearGrabHandles()
{
this.Parent.Invalidate();
this.Invalidate();
}
protected override void WndProc(ref Message m)
{
if (m.Msg == 0x0085 || m.Msg == 0x000F) // WM_NCPAINT or WM_PAINT
{
if (this.drawRect == true)
this.drawGrabHandles();
else
this.clearGrabHandles();
}
base.WndProc(ref m);
}
}
Thanks for any help,
Bob Dankert