views:

568

answers:

1

Hi,

I am trying to change window style of a window in c#.

I have handle of the window. How do I send message to the window to change its window style?

My purpose is to make the window borderless.

+1  A: 

Do you actually need to change the style of the existing window, or do you need to create it with a given style from the get go? If it's the former (sounds like it, by the rest of your question), then you just override CreateParams property on your Form (or whatever it is) and change the value of ClassStyle, Style and ExStyle properties on the return value:

    protected override CreateParams CreateParams
    {
        get
        {
            CreateParams createParams = base.CreateParams;
            createParams.Style |= WS_...;
            return createParams;
        }
    }

To change style of an existing window, you'll have to use P/Invoke to call GetWindowLong to retrieve the current value of GWL_STYLE (or GWL_EXSTYLE, whichever you need) for the window, flip the bits as needed, and call SetWindowLong to set it back. You can find P/Invoke signatures for both functions, as well as an example that uses them with GWL_EXSTYLE, here.

Pavel Minaev
I need to change the style of the existing window.
Moon
Updated answer to cover that case.
Pavel Minaev