我有一个窗体窗体没有在应用程序中运行它。没有应用程序处理窗体事件
这是我必须在窗体内调用的核心功能......有一些类变量唯一真正重要的是闭锁许可。用户必须按下一个按钮关闭窗口。
不幸的是我无法得到它来更新和处理事件。 this.Update()
,this.Refresh()
不会做伎俩。
internal short ask(String question, String RegExFilter, out String answer)
{
this.RegExFilter = RegExFilter;
this.Text = question;
this.Show();
while (!closingpermission)
{
//Window needs to process its events and allow the user to interact.
}
answer = answerBox.Text;
this.Close();
return RetVal;
}
编辑:
“应用程序” 是指单身申请 - 我不有。
循环必须保持窗体显示 - 我认为soution是Hans Passant写道。我需要抽取一个消息循环。
Ken2K的解决方案不适合我。
编辑#2:
这里是一个可编译示例 - 更新methos刷新我的窗口,但我不能编辑文本框 - 没关系有关按钮或下一步与文本我会做。我甚至不能编辑文本。
using System.Windows.Forms;
using System.Drawing; //System.Drawing.dll
namespace StackOverFlowDemo
{
class Example
{
public static void Main()
{
Input input = new Input();
input.Ask("Something");
}
}
class Input : Form
{
TextBox textbox = new TextBox();
public Input()
{
this.Controls.AddRange(new Control[] { textbox });
this.Bounds = new Rectangle(0, 0, 500, 500);
this.textbox.Bounds = new Rectangle(10, 10, 480, 200);
}
internal void Ask(string question)
{
this.Text = question;
this.Show();
while (true)
{
this.Update();
}
}
}
}
编辑#3
我想我要不能做什么。我对这个主题进行了阅读,似乎你需要“某种东西”,一直呼叫protected override void WndProc(ref Message m);
。这东西似乎是应用程序。我不知道有什么方法可以在没有应用程序的应用程序中执行此操作。请不同意我:)
我不明白。“没有申请”是什么意思? – Steve 2012-03-09 12:25:58
显然它不起作用,因为你没有“应用程序”。需要Application.Run()调用来保持表单活着,它会泵送消息循环。或Form.ShowDialog()。 – 2012-03-09 12:34:34
看看[这个问题](http://stackoverflow.com/questions/4721962/c-sharp-application-run-without-form)和在接受的答案。 – Steve 2012-03-09 13:17:34