473,397 Members | 2,056 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,397 software developers and data experts.

A question about ShowDialog() form

Hello!

I have a modal dialog lets call it TestDialog that is shown by using method
showDialog().

This TestDialog has three controls it's one richtextbox and two buttons.
The buttons is one Ok button and one Cancel button.

When this TestDialog is shown the user has two alternatives either write
something in the richtext box and then click the Ok button or click the
Cancel button ignoring whatever was written in the richtextbox field.

The user is not allowed to click the Ok button without writing anything in
the richtextbox. If he does some
information must be displayed telling him that some text must be written
when clicking the Ok button.

Assume the following sequence:
1. The user click the Ok button without writing anything in the richtextbox.
2. When the Ok button is clicked the TestDialog is closed.
3. I check if the Ok button is clicked and if the richtextbox is empy then I
use the MessageBox to give some information. When this information is given
from the MessageBox there is no visible TestDialog. When the user click Ok
in the MessageBox I display the TestDialog again. This works but I'm not
fully satisfied with the solution.
4. When this MessageBox is displayed the user can't do anything else because
this testDialog is modal but the user might be confused when the MessageBox
is saying something like enter text in the TestDialog when no TestDialog is
visible.

What I do want instead is if it would be possible to keep the TestDialog
visible if the user click the Ok button without writing anything in the
richtextbox. Then this MessageBox with some information is displayed above
this TestDialog given a better solution.

//Tony



Aug 15 '06 #1
3 2305
Tony Johansson wrote:
The user is not allowed to click the Ok button
without writing anything in the richtextbox. If he
does some information must be displayed [...]
No, you should simply disable the OK button until text has been typed.

Start with it disabled, and whenever you get a TextChanged event from
the textbox, change the state of the OK button depending on whether
the box is now empty.

Eq.
Aug 15 '06 #2
Tony,

Why go through all that? Why not just disable the OK button until something
is in the RichTextBox? That way the user can't click the OK button at all,
and you have a LOT less coding to worry about, and you are already sure that
there is something in the textbox.

Just a thought.

WhiteWizard
aka Gandalf
MCSD.NET, MCAD, MCT
"Tony Johansson" wrote:
Hello!

I have a modal dialog lets call it TestDialog that is shown by using method
showDialog().

This TestDialog has three controls it's one richtextbox and two buttons.
The buttons is one Ok button and one Cancel button.

When this TestDialog is shown the user has two alternatives either write
something in the richtext box and then click the Ok button or click the
Cancel button ignoring whatever was written in the richtextbox field.

The user is not allowed to click the Ok button without writing anything in
the richtextbox. If he does some
information must be displayed telling him that some text must be written
when clicking the Ok button.

Assume the following sequence:
1. The user click the Ok button without writing anything in the richtextbox.
2. When the Ok button is clicked the TestDialog is closed.
3. I check if the Ok button is clicked and if the richtextbox is empy then I
use the MessageBox to give some information. When this information is given
from the MessageBox there is no visible TestDialog. When the user click Ok
in the MessageBox I display the TestDialog again. This works but I'm not
fully satisfied with the solution.
4. When this MessageBox is displayed the user can't do anything else because
this testDialog is modal but the user might be confused when the MessageBox
is saying something like enter text in the TestDialog when no TestDialog is
visible.

What I do want instead is if it would be possible to keep the TestDialog
visible if the user click the Ok button without writing anything in the
richtextbox. Then this MessageBox with some information is displayed above
this TestDialog given a better solution.

//Tony

Aug 15 '06 #3
Tony Johansson wrote:
Hello!

I have a modal dialog lets call it TestDialog that is shown by using
method showDialog().

This TestDialog has three controls it's one richtextbox and two buttons.
The buttons is one Ok button and one Cancel button.

When this TestDialog is shown the user has two alternatives either write
something in the richtext box and then click the Ok button or click the
Cancel button ignoring whatever was written in the richtextbox field.

The user is not allowed to click the Ok button without writing anything in
the richtextbox. If he does some
information must be displayed telling him that some text must be written
when clicking the Ok button.

Assume the following sequence:
1. The user click the Ok button without writing anything in the
richtextbox. 2. When the Ok button is clicked the TestDialog is closed.
3. I check if the Ok button is clicked and if the richtextbox is empy then
I use the MessageBox to give some information. When this information is
given from the MessageBox there is no visible TestDialog. When the user
click Ok in the MessageBox I display the TestDialog again. This works but
I'm not fully satisfied with the solution.
4. When this MessageBox is displayed the user can't do anything else
because this testDialog is modal but the user might be confused when the
MessageBox is saying something like enter text in the TestDialog when no
TestDialog is visible.

What I do want instead is if it would be possible to keep the TestDialog
visible if the user click the Ok button without writing anything in the
richtextbox. Then this MessageBox with some information is displayed above
this TestDialog given a better solution.

//Tony
Hi Tony,

You can check the contents of the RichTextBox in the click event of your Ok
button, and then either:

1) Display your error message, and return out of the method

2) Set the DialogResult property of your form, and call the 'Close' method
on your form.

If you are using the 'DialogResult' property of the button itself to cause
automatic closing of the form, you'll need to take that off of your Ok
button.

Here's a short sample:

///
private void OnOkClicked ( object s, EventArgs e )
{
if ( rtb.Text.Length == 0 )
{
MessageBox.Show( "Please enter some text" );
return;
}

this.DialogResult = DialogResult.Ok;
this.Close();
}
///

(This was typed straight into my news reader... I haven't tested it <g>)

--
Hope this helps,
Tom Spink

Google first, ask later.
Aug 15 '06 #4

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

Similar topics

3
by: Richard L Rosenheim | last post by:
I would like to detect when a form is invoked as the result of a ShowDialog call. Anyone have any ideas or suggestions on how to do that? TIA, Richard Rosenheim
5
by: Josh Golden | last post by:
3 forms. form 1, when button clicked instantiates form 2 which opens but is not shown. form 2 instantiates form 3 as showdialog. form 3 finishes, raises an event that form 2 catches. during the...
4
by: Dennis Sjogren | last post by:
Greetings! First, I'm not 100% sure where to post this question. I use VB.NET for this project, but it's really a design question (a question on which method to use when solving this problem). ...
4
by: trialproduct2004 | last post by:
Hi all I am new to vb.net application. I am using showdialog property of form to display form. First time it is working properly. But next time it is giving me error that ' object reference not...
2
by: sonu | last post by:
Hi all, I have a problem regarding use of a usercontrol in .NET. My usercontrol consists of two listviews which I say as source and destination lisviews which contains the files and folders. I...
4
by: Chris Dunaway | last post by:
I have a main form with a "lock" button. When the lock button is clicked, another form is shown using ShowDialog(this). The user must enter their PIN on this form to close it and resume the main...
5
by: Miro | last post by:
I will try my best to ask this question correctly. I think in the end the code will make more sence of what I am trying to accomplish. I am just not sure of what to search for on the net. I...
2
by: Franky | last post by:
Threre is a Form containing a usercontrol In the form's Load event it references a usercontrol property, say, zz The first showdialog(formx) causes 1 usercontrol_load event 2 form_load event...
1
by: Frank Rizzo | last post by:
I am not grokking the difference between Form.ShowDialog() and Form.ShowDialog(this). I have a form (parent form) that kicks off a modal dialog using Form.ShowDialog(). The modal dialog has a 3rd...
10
by: Descartes | last post by:
Dear All, Coming from another development environment, it appears that I bang my head in the wall on very basic matters, so I hope you can give me a push in the right direction. The...
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: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.