如何在c#.net windows应用程序中隐藏关闭按钮并仅显示最小化按钮? [英] How to hide close button and only show of minimize button in c# .net windows application?
问题描述
您好,
我想在我的c#.net windows应用程序中仅显示最小化选项。
关闭按钮不应禁用或启用,它应该隐藏。
最小化按钮应该只显示。
怎么可能?
谢谢
Ankit Agarwal
软件工程师
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
推荐答案
你不能。
你能做的最好就是禁用关闭按钮,它就是一个人:禁用窗体上的关闭框 [ ^ ]
我遇到了类似的问题。 />
你可以删除整个控制盒(最大,最小和关闭按钮)。
然后在对话框的右上角添加一个按钮看起来像Minimize按钮。
为该按钮添加最小化按钮功能。
以下可能是UI代码:
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"/>
</DockPanel>
searchDialogWindow.ResizeMode = ResizeMode.CanMinimize;
searchDialogWindow.WindowStartupLocation = WindowStartupLocation.CenterScreen;
searchDialogWindow.WindowStyle = WindowStyle.None;
但是,这样做的一个缺点可能就是你无法拖动对话框..
其他解决方案我认为是在关闭事件中放置一个方法并且只在某些条件下关闭窗口以最小化其他条件。
searchDialogWindow.Closing + = SearchDialogWindowOnClosing;
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;
}
如果您使用的是WinForms,可以试试这个:
1 )禁用表单的最大化按钮(将其MaximizeBox
属性设置为false
),并让它显示最小化和关闭框。
2)添加一个变量(初始化为false)类似于
If you are using WinForms you could try this:
1) Disable the form's maximize button (set it'sMaximizeBox
property tofalse
), and let it show the minimize and close boxes.
2) Add one variable (initialized to false) similar to
bool m_IDoWantToClose;
3)在按钮中(我想这是你的情况)你想要的地方使表单关闭添加代码以在调用表单的 m_IDoWantToClose
变量设置为 true
>关闭()方法。
4)为表单的 FormClosing $ c $添加一个事件处理程序c>事件,因此当变量
参数(类型 m_IDoWantToClose
未设置为true时,您可以取消关闭表单。为此你可以设置为 true
方法的 e e.Cancel
的属性 FormClosingEventArgs
)。
将显示关闭按钮框,但不会关闭表格。
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.
这篇关于如何在c#.net windows应用程序中隐藏关闭按钮并仅显示最小化按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!