Click here to Skip to main content
15,921,295 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello,

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?

Thanks

Ankit Agarwal
Software Engineer
Posted

You can't.
The best you can do is disable the Close button, and it alone: Disable the Close box on a form[^]
 
Share this answer
 
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:

XML
<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"/>
        </DockPanel>


C#
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;

C#
private void SearchDialogWindowOnClosing(object sender, CancelEventArgs cancelEventArgs)
       {
           searchDialogWindow.WindowState = WindowState.Minimized;
           cancelEventArgs.Cancel = isSearchInProgress;
       }
 
Share this answer
 
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
C#
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.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900