I have a user control that pops up much like intelisense in visual studio to
display a range of navigable options when a key combo is pressed within a
textbox. I have called the user control within the parent form and
programmatically called it using the following code within the parent form.
MyUserControl control1 = new MyUserControl;
control1.BorderStyle = BorderStyle.FixedSingle;
this.Controls.Add(control1);
control1.Focus();
control1.BringToFront();
control1.Show();
How do I go about making my new popup control resizeable?
the only options I have under BorderStyle is FixedSingle and Fixed3D.
thanks
skoya
What is the base class for your control? It seems not to be UserControl
because it doesn't have BorderStyle property.
However this is not important because control's doesn't support sizable
borders anyways.
The easies way would be to use form instead of control. Modify the form
border (remove the caption and stuff. Set the FormBorderStyle to *Sizable*
then show the form (control) using the following code:
Form2 f2 = new Form2();
f2.TopLevel = false;
f2.Size = new Size(200,200);
this.Controls.Add(f2);
f2.Show();
The key here is setting f2.TopLevel to *false*. When do that the form
becomes normal control rather that top-level window.
The problem here is with the 3D look of the form. This cannot be controlled
and the control's visual appearance doesn't make sense.
Next solution that came up in my mind is to override CreateParams property
and adding resizable border to some normal control. Unfortunately resizable
border comes with 3D look and there is nothing we can do about it.
So the solution is to use thin (non resizable) border and process the
WM_NCHITTEST.
The following is sample control that inherits from panel and can be resized.
I've implemented only resizing by grabbing the bottom border it needs to be
implemented in the same way for the other possible grab regions (corners,
left and right border as well as top border if make sense)
class SizablePanel: Panel
{
private const int WM_NCHITTEST = 0x0084;
private const int HTBOTTOM = 15;
public SizablePanel()
{
this.BorderStyle = BorderStyle.FixedSingle;
}
protected override void WndProc(ref Message m)
{
base.WndProc (ref m);
if(m.Msg == WM_NCHITTEST)
{
Point pos = new Point((int)m.LParam);
pos = this.PointToClient(pos);
if(pos.Y > this.Height - 10)
m.Result = new IntPtr(HTBOTTOM);
}
}
}
What is the base class for your control? It seems not to be UserControl
because it doesn't have BorderStyle property.
However this is not important because control's doesn't support sizable
borders anyways.
The easies way would be to use form instead of control. Modify the form
border (remove the caption and stuff. Set the FormBorderStyle to *Sizable*
then show the form (control) using the following code:
Form2 f2 = new Form2();
f2.TopLevel = false;
f2.Size = new Size(200,200);
this.Controls.Add(f2);
f2.Show();
The key here is setting f2.TopLevel to *false*. When do that the form
becomes normal control rather that top-level window.
The problem here is with the 3D look of the form. This cannot be controlled
and the control's visual appearance doesn't make sense.
Next solution that came up in my mind is to override CreateParams property
and adding resizable border to some normal control. Unfortunately resizable
border comes with 3D look and there is nothing we can do about it.
So the solution is to use thin (non resizable) border and process the
WM_NCHITTEST.
The following is sample control that inherits from panel and can be resized.
I've implemented only resizing by grabbing the bottom border it needs to be
implemented in the same way for the other possible grab regions (corners,
left and right border as well as top border if make sense)
class SizablePanel: Panel
{
private const int WM_NCHITTEST = 0x0084;
private const int HTBOTTOM = 15;
public SizablePanel()
{
this.BorderStyle = BorderStyle.FixedSingle;
}
protected override void WndProc(ref Message m)
{
base.WndProc (ref m);
if(m.Msg == WM_NCHITTEST)
{
Point pos = new Point((int)m.LParam);
pos = this.PointToClient(pos);
if(pos.Y > this.Height - 10)
m.Result = new IntPtr(HTBOTTOM);
}
}
}
HTH
Stoitcho Goutsev (100) [C# MVP]
"sdfsdfds" <sdfs...@sddfs.com> wrote in message
news:%23hYxTWP...@tk2msftngp13.phx.gbl...
Also the code works with UserControl class also not just Panel.
thanks a lot for your help.
private const int WM_NCHITTEST = 0x0084;
private const int HTBOTTOM = 15;
private const int HTBOTTOMRIGHT = 17;
private const int HTRIGHT = 11;
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
if (m.Msg == WM_NCHITTEST)
{
Point pos = new Point((int)m.LParam);
pos = this.PointToClient(pos);
//if (pos.Y > this.Height - 10)
// m.Result = new IntPtr(HTBOTTOM);
if (pos.X > this.Width - 10 && pos.Y > this.Height - 10)
{
m.Result = new IntPtr(HTBOTTOMRIGHT);
return;
}
// if (pos.X > this.Width - 10)
// m.Result = new IntPtr(HTRIGHT);
}
}
"Stoitcho Goutsev (100) [C# MVP]" <1...@100.com> wrote in message
news:epC1sjT8...@TK2MSFTNGP14.phx.gbl...
--
Stoitcho Goutsev (100) [C# MVP]
"sdfsdfds" <sdfs...@sddfs.com> wrote in message
news:u$SKjWb8F...@TK2MSFTNGP11.phx.gbl...