Panel with a Raised BorderStyle

  • Thread starter Thread starter Steph.
  • Start date Start date
S

Steph.

Hi,

I was looking for a way to get a Panel with a Raised border style ...
I found the simplest way to do it, so I share it with you :


public class StpPanel:Panel
{
const int WS_EX_DLGMODALFRAME = 0x00000001;

// Provide window style constants to enable control border
protected override CreateParams CreateParams
{
get
{
// Take the default params from the base class
CreateParams p = base.CreateParams;
// Add the extended "3d sunken border" style
p.ExStyle = p.ExStyle | WS_EX_DLGMODALFRAME;
return p;
}//EndGet
}//EndProc CreateParams
}//EndClass StpPanel

A+

Steph.
 
Hello Steph,

I added your code and built application without any errors but I don't know how it use in code. Could you write where I should add this code or another information how it use?

Kind regards
Mariusz



Steph. said:
Hi,

I was looking for a way to get a Panel with a Raised border style ...
I found the simplest way to do it, so I share it with you :


public class StpPanel:Panel
{
const int WS_EX_DLGMODALFRAME = 0x00000001;

// Provide window style constants to enable control border
protected override CreateParams CreateParams
{
get
{
// Take the default params from the base class
CreateParams p = base.CreateParams;
// Add the extended "3d sunken border" style
p.ExStyle = p.ExStyle | WS_EX_DLGMODALFRAME;
return p;
}//EndGet
}//EndProc CreateParams
}//EndClass StpPanel

A+

Steph.
 
Hi!

To use this class, create new UserControl and name it something like RaisedPanel.
When the control is generated, change it's base type to Panel and paste Stephs code. Your control's code should look like this

public partial class RaisedPanel : Panel
{
const int WS_EX_DLGMODALFRAME = 0x00000001;

protected override CreateParams CreateParams
{
get
{
CreateParams p = base.CreateParams;
p.ExStyle = p.ExStyle | WS_EX_DLGMODALFRAME;
return p;
}
}

public RaisedPanel()
{
InitializeComponent();
}
}


Try to build it. It will throw an error on the following line:
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;

Delete whole line.

Build it again, go to your form and you should see your new RaisedPanel control in your toolbox, ready to be placed on the form.
 
Back
Top