Neeraj

How to delete default minimize and maximize button of window using c#.

Add namespaces : using System.Windows.Interop; using System.Runtime.InteropServices;

public Window1()
{
InitializeComponent();
}

private void Window_Loaded(object sender, RoutedEventArgs e)
{
RemoveControlBoxes();
}

[DllImport("User32.dll", EntryPoint = "GetWindowLong")]
private extern static Int32 GetWindowLongPtr(IntPtr hWnd, Int32 nIndex);

[DllImport("User32.dll", EntryPoint = "SetWindowLong")]
private extern static Int32 SetWindowLongPtr(IntPtr hWnd, Int32 nIndex, Int32 dwNewLong);

private const Int32 GWL_STYLE = -16;
private void RemoveControlBoxes()
{
IntPtr hWnd = new WindowInteropHelper(this).Handle;
long WindowLong = GetWindowLongPtr(hWnd, GWL_STYLE);
WindowLong = WindowLong & -131073 & -65537;
SetWindowLongPtr(hWnd, GWL_STYLE, Convert.ToInt32(WindowLong));
}

You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>