Click here to Skip to main content
13,086,662 members (56,007 online)
Rate this:
Please Sign up or sign in to vote.

I want to show only minimize option in my c# .net windows application.
close button should not disable or enable,it should be hide.
Minimize button should be show only.

How it can be possible?


Ankit Agarwal
Software Engineer
Posted 27-Jun-13 20:19pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You can't.
The best you can do is disable the Close button, and it alone: Disable the Close box on a form[^]
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

I had the similar problem.

You can remove the entire control box (Maximum, Minimum and Close buttons).
Then add a button at the top right of the dialog which looks like Minimize button.

Add Minimize button functionality to that button.

Following could be the UI code for that:

<DockPanel LastChildFill="True">
        <DockPanel VerticalAlignment="Center" DockPanel.Dock="Top">
            <Button  DockPanel.Dock="Right" Content="-" Width="20" Height="20" Margin="5,5,5,5" FontSize="15" HorizontalAlignment="Right"/>

searchDialogWindow.ResizeMode = ResizeMode.CanMinimize;
            searchDialogWindow.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            searchDialogWindow.WindowStyle = WindowStyle.None;

However, one drawback of this could be you cannot drag the dialog..

Other solution I thought is putting a method in closing event and close the window only in certain condition minimize other conditions.

searchDialogWindow.Closing += SearchDialogWindowOnClosing;

private void SearchDialogWindowOnClosing(object sender, CancelEventArgs cancelEventArgs)
           searchDialogWindow.WindowState = WindowState.Minimized;
           cancelEventArgs.Cancel = isSearchInProgress;
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

If you are using WinForms you could try this:

1) Disable the form's maximize button (set it's MaximizeBox property to false), and let it show the minimize and close boxes.

2) Add one variable (initialized to false) similar to
bool m_IDoWantToClose;

3) In the button (I suppose that's your case) where you want to make the form close add code to set the m_IDoWantToClose variable to true just before calling the form's Close() method.

4) Add one event handler for the form's FormClosing event so you can cancel the form closing when the variable m_IDoWantToClose is not set to true. For that you can set to true the property e.Cancel of the method's e argument (of type FormClosingEventArgs).

The 'Close' button box will be shown, but will not close the form.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.170813.1 | Last Updated 17 Sep 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100