Sorry about the previous post. I did not have VS.Net readily available so had
to guess. But the following class works.
You can use the following class. Set the WindowPosition to CenterOwner. The
user will not be able to quit this dialog without clicking on the Ok or
Cancel button.
using System;
using System.Windows.Forms;
namespace WindowsApplication3
{
/// <summary>
/// Summary description for CustomDialog.
/// </summary>
public class CustomDialog:Form
{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
public CustomDialog()
{
//
// TODO: Add constructor logic here
//
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
//
// button1
//
this.button1.Location = new System.Drawing.Point(40, 128);
this.button1.Name = "button1";
this.button1.TabIndex = 0;
this.button1.Text = "Ok";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(152, 128);
this.button2.Name = "button2";
this.button2.TabIndex = 1;
this.button2.Text = "Cancel";
this.button2.Click += new System.EventHandler(this.button2_Click);
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.BackColor = System.Drawing.Color.IndianRed;
this.ClientSize = new System.Drawing.Size(272, 168);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.ShowDialog();
}
bool okClicked=false;
private void button1_Click(object sender, System.EventArgs e)
{
okClicked=true;
this.Hide();
}
private void button2_Click(object sender, System.EventArgs e)
{
okClicked=false;
this.Hide();
}
}
}
Regards,
Jv
"ps******@gmail.com" wrote:
Hey everyone,
for reasons I can't explain quickly, I'm developing a completely custom
OK/OK_CANCEL dialog, though I think many people would benifit from this
knowledge. I basically need to re-invent the wheel and provide a
simple API like:
Result result = CustomDialog.Show( Mode.OK_CANCEL, aMessage );
The problem that I'm not sure how to solve is the blocking aspect that
dialogs I've used in the past offer. Obviously I'd like to invoke this
line of code from various points in my application and have it block
until user input is received.
Does anyone have experience with this type of problem? I think I need
a way to "hand-off" processing to a secondary GUI thread, or something
like that. Especially since this dialog will arise as a result of user
interaction with the main UI.
Any and all advice would be great. The solution may not be available
from a high-level C# api, but I still wanted to post here. Thanks.
--pete