can you make a pop up user control resizable like a form

S

sdfsdfds

Hi,

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
 
S

Stoitcho Goutsev \(100\) [C# MVP]

Hi,

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]
 
S

sdfsdfds

Thats superb it turns out that I only need HTRIGHTBOTTOM for now...

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) said:
Hi,

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 said:
Hi,

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
 
S

Stoitcho Goutsev \(100\) [C# MVP]

It is going to work with any control because it exploits windows message
that is common for all windows. I just used a panel because it has this
BorderStyle property. I don't see the UserControl to expose such a property.
Nevertheless, border can be added (theoretically) to any control via
overriding CreateParams property.


--

Stoitcho Goutsev (100) [C# MVP]

sdfsdfds said:
Thats superb it turns out that I only need HTRIGHTBOTTOM for now...

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) said:
Hi,

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 said:
Hi,

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
 

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