有没有办法停止在Windows窗体中隐藏显示对话框 [英] Is there any way to stop hiding Show Dialog in windows forms

查看:64
本文介绍了有没有办法停止在Windows窗体中隐藏显示对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用form.showDialog()显示表单。



但它的工作正常,一旦完成,对话框就会消失。



有没有办法停止使用showdialog显示的表格。







I tried showing a form using form.showDialog().

But its works fine and as soon as the process finished the dialog disappears.

Is there any way to stop hiding the form shown using showdialog.



Find findBox = new Find();
findBox.ShowDialog();
string findWord = Find.TextValue;
txtWritingBox.Select(txtWritingBox.Text.IndexOf(findWord), findWord.Length);







在这里我想显示findbox,直到我点击关闭或取消。



我试过findBox.Show()但是它不能用于我的任务..



帮助我




Here I want to show findbox until I click close or cancel.

I tried findBox.Show() but it not working for my task..

Help Me

推荐答案

这似乎是一个简单的目标:保持表单显示,而不是隐藏。



如果您希望表单保持可见,除非用户通过单击其ControlBox关闭它,或者采取其他一些操作然后回复,否则不要关闭通过关闭或隐藏表格:然后我不得不问:你为什么使用'ShowDialog?



ShowDialog的全部目的是提交一份表格 modally:意味着表单以模态方式显示暂停/暂停您的应用程序,并且使用鼠标或键盘专注于所有用户操作...除非您有一些WinAPI内容正在进行,像GlobalH一样ook。



那么,你的目标是什么:在什么情况下你希望表格被移动,隐藏,关闭?



如果您希望表单保持打开状态,即使最终用户关闭它,您也可以为FormClosing事件定义一个EventHandler,并取消实际关闭它,并隐藏它:
This seems like a simple goal here: to keep a Form showing, rather than hidden.

If you want the Form to remain visible, to not close unless the user closes it by clicking on its ControlBox, or by taking some other action that you then respond to by closing, or hiding, the Form: then I have to ask: why are you using 'ShowDialog ?

The whole purpose of ShowDialog is to present a Form "modally:" meaning that the Form shown modally halts/pauses your application, and has the exclusive focus for all user actions with mouse, or keyboard ... unless you've got some WinAPI stuff going on, like a GlobalHook.

So, what is your goal: under what circumstances do you wish the Form to be moved, hidden, closed ?

If you want the Form to remain open, even if the end-user closes it, you can define an EventHandler for the FormClosing Event, and cancel actually closing it, and hide it:
private void Form2_FormClosing(object sender, FormClosingEventArgs e)
{
    if (MessageBox.Show(
         "Close this Form",
         "Confirm Form Close",
         MessageBoxButtons.YesNo,
         MessageBoxIcon.Question,
         MessageBoxDefaultButton.Button2
    ) == DialogResult.No)
    {
     this.Hide();
     e.Cancel = true;
    }
}

此示例演示如何使用FormClosing事件。当用户单击Form2上的ControlBox时,将触发FormClosing事件。出现一个DialogBox:如果用户只是点击'Enter:它就像用户单击否按钮一样,并且表单被隐藏,并且关闭它将被取消。如果用户单击是按钮,则表单将被关闭。

This example demonstrates using the FormClosing Event. When the user clicks the ControlBox on Form2, the FormClosing Event fires. A DialogBox appears: if the user just hits 'Enter: it's the same as if the user clicked the "No" Button, and the Form is hidden, and closing it is canceled. If the user clicked the "Yes" Button, then the Form would be closed.


private void button1_Click(object sender, System.EventArgs e)
{
   Form frm1= new Form();
   frm1.ShowDialog();
}


这篇关于有没有办法停止在Windows窗体中隐藏显示对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆