ShowDialog and Dialog Result???

Z

Zanna

Hi all!

I've a little problem that I cannot resolve.

I'v a MyForm that inherits from S.W.F.Form, with MinimizeButton = False
(so I have the (Ok) button on the top-right corner).

in this form I have

Public Shadows Function ShowDialog() As DialogResult
Return MyBase.ShowDialog
End Function

So, when the (ok) is pressed I expect to have the Cancel as result.

In another place I do:

Dim f As New MyForm
MessageBox.Show(f.ShowDialog.ToString)

But this returns always "Ok".

Why?

I need to have the correct result! :(

Bye
 
P

Peter Foot [MVP]

The Ok button will return DialogResult.Ok, if you want to return
DialogResult.Cancel you can add a button or menu item to the form and set
the dialogresult from its Click handler e.g.

this.DialogResult = DialogResult.Cancel

This will close the dialog and return the selected DialogResult.

Peter
 
Z

Zanna

Peter said:
The Ok button will return DialogResult.Ok, if you want to return
DialogResult.Cancel you can add a button or menu item to the form and set
the dialogresult from its Click handler e.g.

There is no way do get a workaround for this so that when I click the ok
button the DialogResult is Cancel?

Thank you!
 
G

Guest

| There is no way do get a workaround for this so that when I click the ok
| button the DialogResult is Cancel?

Maybe you could catch the Form_Closing-Event and set the DialogResult to
Cancel. But I'm not sure if it works. Otherwise you could add an extra
property to your form (friend myResult as s.w.f.DialogResult) that is filled
with the value you want and that is read by the caller after the ShowDialog.

BTW: Are there other buttons that force your Form to close or is the
OK-button the only one? In this case it would be unimportant, what the
result of your dialog is.

| So, when the (ok) is pressed I expect to have the Cancel as result.
I think there are only a few people expecting Cancel on pressing an
OK-Button...

D.Barisch
 
Z

Zanna

Daniel said:
| So, when the (ok) is pressed I expect to have the Cancel as result.
I think there are only a few people expecting Cancel on pressing an
OK-Button...

It's true, but the documentation tell that che (X) button on
dialog-windows will cause the Cancel result.
Since in CF the (ok) is equivalent to the desktop (X) I will expect the
same behavior.

P.s.: yes, I've others buttons on the form, and one of these is the one
that should result in "Ok", that's why I neet others to result in Cancel :)

Bye
 
R

Rüdiger Kardel

what about spending your form your own result access?
by default it is something like "cancel" and your special "OK"-button will
put in whatever you want.

after a showdialog() you can access this property as well as a Dialgoresult

Ruediger
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top