how to make a form that doesn't have the standard windows look C#
I hope this makes sense...
It doesn't only apply to c#, but that is what we are doing this in, so I tagged it with that
I am trying to figure out how to make a windows form not look like a windows form. I would like to repl开发者_如何转开发ace it with a graphic that has its own close button and its own non-square look. I am sorry if I am making no sense, I have no idea how to explain this.
Thank you if you understand what the heck I am talking about.
The official way of doing this is to handle the WM_NCPAINT message that Windows sends to your window when it wants you to draw the non-client area of the form (title bar, close button, borders, etc.) It can be quite a hassle but it may not be necessary. Scott has suggested a way to get a borderless WPF Window and the Windows Forms approach is similar. Refer to the FormBorderStyle property.
In order to support dragging the window around as if the title bar were being dragged, you'll want to send a WM_NCLBUTTONDOWN message to the window passing the HT_CAPTION constant as the wParam.
For example, handle the MouseDown event on the control that you want to be "draggable".
if (e.Button == MouseButtons.Left) {
SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
}
This requires the following P/Invoke declarations.
const int WM_NCLBUTTONDOWN = 0xA1;
const int HT_CAPTION = 0x2;
[DllImportAttribute("user32.dll")]
static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
Finally, to achieve a non-rectangular window, you'll want to have a look at the Region property. You can assign a non-rectangular region to the form and it will be clipped to this region.
You can do this with WPF.
- Create a WPF Window
- Window.WindowStyle="WindowStyle.None"
- Window.AllowsTransparency="True"
- Window.Background="Transparent"
That gives you a transparent Window
. Then put an Ellipse
in the Window
:
<Ellipse Height="80" Width="80" Fill="White"/>
Though the previous answer has stated that you can do this using WPF, you can also do this using Windows Forms.
Create non rectangular Windows forms. Here's how.
精彩评论