Grab Handles on textbox

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
 
J

Jeffrey Tan[MSFT]

Hi Bob,

Thanks for your post.

In .Net, we can use ControlPaint.DrawGrabHandle method to draw grab handle.
There is a sample in chapter in book "Integrating Componentswith Visual
Studio .NET". I can find the html content in the link below:
http://66.102.7.104/search?q=cache:pRfXCL3FZ30J:www.edv-buchversand.de/chapt
er/ore-00360.pdf+DrawGrabHandle+ControlPaint&hl=zh-CN

Hope it helps

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
B

Bob Dankert

Thanks, I will continue to play around with this and see if I can get this
to work. If I have any trouble, I will report back.

Bob Dankert
 
J

Jeffrey Tan[MSFT]

Ok, if you need further help, please feel free to tell me, thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

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

Top