2

I have been dealing with this issue and i dont know how to proceed.

I have a project with both windows forms and WPF forms.

I want every form to be displayed like this (its a WPF one):

WPF = http://imageshack.us/photo/my-images/545/wpfk.png/

I achieved this windows style = none and canresize = yes. I dont actually want it to be resized. I just want that thin border arround the form. But if i put canresize = false i lose the border. I also want to be able to move the window in the screen, not to be static in that place.

I need all that for my winforms too.

Winforms: WINFORM = http://imageshack.us/photo/my-images/836/winforms.png/

I hope you guys understand what i need. Graphically, it has to be like the first image.

GEOCHET
  • 21,119
  • 15
  • 74
  • 98
Andres
  • 2,729
  • 5
  • 29
  • 60
  • Can you `e.Cancel` the `MouseDown` event if `e.OriginalSource` is the window border? – Rachel Dec 05 '12 at 16:05
  • That could work in my WPF window where sizable = true makes the border visible, but in winforms i dont have that property. – Andres Dec 05 '12 at 16:56
  • Ahh I understand your question a bit better now. Unfortunately, I don't know much about Winforms as I prefer to use WPF whenever possible, so can't help you there – Rachel Dec 05 '12 at 17:10

3 Answers3

1

I'm not sure if it helps, but you can create Forms collection for this. (a)

http://support.microsoft.com/kb/815707/en-us

t1w
  • 1,408
  • 5
  • 25
  • 55
1

You just need to set the WinForms FormBorderStyle property in the designer to Sizable, FixedDialog, Fixed3D etc. One of these is bound to give you the behaviour you require.

GEOCHET
  • 21,119
  • 15
  • 74
  • 98
MoonKnight
  • 23,214
  • 40
  • 145
  • 277
  • Im not sure you understood the issue. I just want the form to have a thin border like the first image and to be able to move the form without beign sizable. None of the FormBorderStyle fits my need. – Andres Dec 05 '12 at 15:48
  • `FixedDialog` is your only option then. Unless you want to undertake a fairly massive job of writing your own WInForms container!? – MoonKnight Dec 05 '12 at 16:38
  • Is there any way to hide that close button? I found this too.. http://customerborderform.codeplex.com/ but dont know if you can hide buttons. Have to see. – Andres Dec 05 '12 at 16:41
  • Cool. You can't hide it but you can disable it using http://www.codeproject.com/Articles/20379/Disabling-Close-Button-on-Forms. – MoonKnight Dec 05 '12 at 17:05
  • Actually, check this answer http://stackoverflow.com/a/7301913/626442 you can remove it along with the Min and Max buttons... – MoonKnight Dec 05 '12 at 17:06
  • thanks! that amazingly worked! i will write the solution below so the ones who need it can use it. – Andres Dec 05 '12 at 22:03
1

Solution: Paste this code into your form or base form.

private const int WS_SYSMENU = 0x80000;
protected override CreateParams CreateParams
{
    get
    {
        CreateParams cp = base.CreateParams;
        cp.Style &= ~WS_SYSMENU;
        return cp;
    }
}

Thanks Killercam for the help!

Solution for WPF Window:

public MainWindow()
    {
        SourceInitialized += Window_SourceInitialized;
        InitializeComponent();
    }

    private void button2_Click(object sender, RoutedEventArgs e)
    {
        this.Close();
    }

    private void button3_Click(object sender, RoutedEventArgs e)
    {
        this.WindowState = WindowState.Minimized;
    }

    private void Window_SourceInitialized(object sender, EventArgs e)
    {
        WindowInteropHelper wih = new WindowInteropHelper(this);
        int style = GetWindowLong(wih.Handle, GWL_STYLE);
        SetWindowLong(wih.Handle, GWL_STYLE, style & ~WS_SYSMENU);
    }

    private const int GWL_STYLE = -16;
    private const int WS_SYSMENU = 0x00080000;

    [DllImport("user32.dll")]
    private extern static int SetWindowLong(IntPtr hwnd, int index, int value);
    [DllImport("user32.dll")]
    private extern static int GetWindowLong(IntPtr hwnd, int index);
Andres
  • 2,729
  • 5
  • 29
  • 60