Panel with a Raised BorderStyle

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.
 
Joined
Apr 21, 2010
Messages
1
Reaction score
0
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.
 
Joined
Sep 23, 2010
Messages
1
Reaction score
0
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.
 

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