I have a windows form without running it in an application.
this is the core function that i have to call within the form… there are some class variables the only really important one is the closingpermission. the user has to press a button to close the window.
Unfortunately i cant get it to update and process events. this.Update(), this.Refresh() wont do the trick.
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;
}
EDIT:
“Application” means the singleton Application – i dont have that.
The loop has to keep the form displayed – i think the soution is something Hans Passant wrote. I need to pump a message loop.
The solution of Ken2K does not work for me.
Edit #2:
Here is a compileable Example – the update methos refreshes my window but i can not edit the textbox – nevermind about the button or what i will do next with the text. I cant even edit the text.
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();
}
}
}
}
Edit #3
I think what i want can not be done. I read up on the Topic and it seems that you need “something” that calls protected override void WndProc(ref Message m); all the time. That something seems to be Application. I am unaware of any way to do this in an application that does not have an application. Please disagree with me 🙂
One of the first commenters had it rigth from the start.
If you want to use Froms you also have to use application – i you dont want to use application you have to switch to some other framework for visualisation like XNA as an example.
Accept that there is a singleton in your app and use the application.