473,386 Members | 1,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Building a custom blocking dialog

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

Nov 17 '05 #1
5 1621
I think you should use the ShowModal (if such a method exists) instead of Show.

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

Nov 17 '05 #2
You simply need to create a Form to represent your custom dialog box.
Invoke your dialog box using the ShowDialog method of the Form passing
the current Form as the owner. The ShowDialog method returns a
DialogResult value.

DialogResult customDialogResult = CustomDialog.ShowDialog(this);

if(customDialogResult==DialogResult.OK)
{
//OK button was clicked
}
else
{
//Cancel button was clicked
}

In your CustomDialog form, you need to set the DialogResult property
appropriately.

i.e. in the click handler for the OK button
this.DialogResult=DialogResult.OK;

and in the click handler for the Cancel butotn
this.DialogResult=DialogResult.Cancel;

Hope this helps.

Regards,
Sarin.

Nov 17 '05 #3
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

Nov 17 '05 #4
Thank you Sarin and J.V.

The problem is that I'm developing a completely custom dialog, so I
don't have the luxury of using .net platform UI components. I've
gotten some traction with some win32 experts who have pointed me in the
direction of making my own message loop to handle the UI events while
my dialog is blocking the main UI thread. I'm currently trying to get
that working. I'll let you know how it turns out.

--pete

Nov 17 '05 #5
Norm's idea (from the user32 group) to take over the responsibility of
handling messages was just what I needed. I ended up very closely
following his workflow. Thank you very much for the help.

Reference
title: Building a custom blocking dialog
group: microsoft.public.win32.programmer.ui

Nov 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Rikkert | last post by:
I can't get my custom-made modeless dialog box (Visual C++.net Win32) to respond to clicking the close button or pressing Alt-F4. I am using the IsDialogMessage to check if messages are for my...
7
by: WindAndWaves | last post by:
Hi Gurus I am trying to make a custom message box with a dialog form. Here is how I would like to do it: 1- anywhere in the database, in any procedure, I call the function that opens a dialog...
4
by: logicalfeline | last post by:
Hi there, I'm creating an installation project where at a particular point in the installation I want the user to be able to specify a filepath for use in the program. My idea was to create a...
4
by: LhK-Soft | last post by:
Hi, I'm active in VC++ for several years now, so I know some things (I think). Using MS-Access I store a db with lots of entries and uses the VBA techniques to export those data to e.g. HTML, XML...
2
by: J-Rod | last post by:
Hi everyone/anyone, I am using a button in my app that opens the color dialog, and allows the user to select a color which changes the backcolor of a label. I then store the color in my db as a...
3
by: boney.dalwani | last post by:
Hello All, I m new to JavaScript and widely Exploring programming in js i have a situation where in i do not want to use alert(message); / prompt(message) kind of functionility. rather i want...
0
by: Gancy | last post by:
Hi In my setup project I need a custom dialog box containing a drop down list box. Since this is not avaialble from standard user interface dialog boxes that visual studio supplies, I am using...
1
by: rn5a | last post by:
I want to create a custom control that encapsulates a Button & a TextBox. When the Button is clicked, the user is asked a question using JavaScript confirm (which shows 2 buttons - 'OK' &...
9
by: Gord | last post by:
In VB6, a custom dialog can be easily created by adding a new form, adding whatever controls you like, sizing it as you like, adding code and then just loading/unloading it whenever you like....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.