PC Review


Reply
Thread Tools Rate Thread

Code for Button Click Event

 
 
Sarah
Guest
Posts: n/a
 
      5th Sep 2003
I have code that I want to run so that if the result is true, it changes the
current button's ".DialogResult" property to "DialogResult.OK". Problem is,
when I run this code on the ".Click" event for the current button and then
run this code, if the ".DialogResult" property is change, it does not take
affect until the button is pressed again.

I do I workaround this?


 
Reply With Quote
 
 
 
 
Armin Zingler
Guest
Posts: n/a
 
      5th Sep 2003
"Sarah" <(E-Mail Removed)> schrieb
> I have code that I want to run so that if the result is true, it
> changes the current button's ".DialogResult" property to
> "DialogResult.OK". Problem is, when I run this code on the ".Click"
> event for the current button and then run this code, if the
> ".DialogResult" property is change, it does not take affect until the
> button is pressed again.
>
> I do I workaround this?


Why don't you execute the code on the first click?


--
Armin

 
Reply With Quote
 
Sarah
Guest
Posts: n/a
 
      5th Sep 2003

>
> Why don't you execute the code on the first click?
>
>


I am executing the code on the buttons "click" event. When the code
evaluates to true, it changes the current buttons control ".DialogResult"
property to ".DialogResult.OK". The problem is, when I change this setting
in this buttons click event, the change does not take place right away -
i.e. since the button was already pressed, changing the property of it after
it is pressed is not having the desired result -- which is to change the
".DialogResult" property was this click event. (The .DialogResult.OK
property change only works for the next time the button is pressed_).

Any help would be appreciated to find out how to run code to change the
..DialogResult property so that the change would change the behavior of the
button right away.

Thanks.


 
Reply With Quote
 
Armin Zingler
Guest
Posts: n/a
 
      5th Sep 2003
"Sarah" <(E-Mail Removed)> schrieb
>
> >
> > Why don't you execute the code on the first click?
> >
> >

>
> I am executing the code on the buttons "click" event. When the
> code evaluates to true, it changes the current buttons control
> ".DialogResult" property to ".DialogResult.OK". The problem is, when
> I change this setting in this buttons click event, the change does
> not take place right away - i.e. since the button was already
> pressed, changing the property of it after it is pressed is not
> having the desired result -- which is to change the ".DialogResult"
> property was this click event. (The .DialogResult.OK property change
> only works for the next time the button is pressed_).
>
> Any help would be appreciated to find out how to run code to change
> the .DialogResult property so that the change would change the
> behavior of the button right away.


Whenever I change the dialogresult property it does change right away.


--
Armin

 
Reply With Quote
 
Sarah
Guest
Posts: n/a
 
      5th Sep 2003

>
> Whenever I change the dialogresult property it does change right away.
>
>

This is my scenerio:

- I launch a dialog box (form 2) from form 1 using "Dialog_AddName_Results =
CustomerName.ShowDialog()"
- On the dialog box, the "Add" button "DialogResult" property is set to
"None" by default
- On the "Add" button click event, some code evaluates to true or false
- If the above code evaluates to true, it sets "DialogResult" to OK (1)

The thing is, the dialog box does not close up right away - as when the
"Add" button was first pressed, the "DialogResult" was set to "None"

Hope that gets you to the point where I am. Is there an event that I can run
before the click event of the button that will run when the button is
clicked?


 
Reply With Quote
 
Richard Brown
Guest
Posts: n/a
 
      5th Sep 2003
Why don't you just set the Form.DialogResult property in your button, then
close the form?
(Read that in the SDK.... but you may just "Hide" the form, closing it may
free the resources)

"Sarah" <(E-Mail Removed)> wrote in message
news:xn66b.75207$(E-Mail Removed)...
>
> >
> > Whenever I change the dialogresult property it does change right away.
> >
> >

> This is my scenerio:
>
> - I launch a dialog box (form 2) from form 1 using "Dialog_AddName_Results

=
> CustomerName.ShowDialog()"
> - On the dialog box, the "Add" button "DialogResult" property is set to
> "None" by default
> - On the "Add" button click event, some code evaluates to true or false
> - If the above code evaluates to true, it sets "DialogResult" to OK (1)
>
> The thing is, the dialog box does not close up right away - as when the
> "Add" button was first pressed, the "DialogResult" was set to "None"
>
> Hope that gets you to the point where I am. Is there an event that I can

run
> before the click event of the button that will run when the button is
> clicked?
>
>



 
Reply With Quote
 
Richard Brown
Guest
Posts: n/a
 
      5th Sep 2003
Dont set the DialogResult property on the button, set it on the form, then
as I said, close or hide the form.

"Sarah" <(E-Mail Removed)> wrote in message
news:xn66b.75207$(E-Mail Removed)...
>
> >
> > Whenever I change the dialogresult property it does change right away.
> >
> >

> This is my scenerio:
>
> - I launch a dialog box (form 2) from form 1 using "Dialog_AddName_Results

=
> CustomerName.ShowDialog()"
> - On the dialog box, the "Add" button "DialogResult" property is set to
> "None" by default
> - On the "Add" button click event, some code evaluates to true or false
> - If the above code evaluates to true, it sets "DialogResult" to OK (1)
>
> The thing is, the dialog box does not close up right away - as when the
> "Add" button was first pressed, the "DialogResult" was set to "None"
>
> Hope that gets you to the point where I am. Is there an event that I can

run
> before the click event of the button that will run when the button is
> clicked?
>
>



 
Reply With Quote
 
Armin Zingler
Guest
Posts: n/a
 
      5th Sep 2003
"Sarah" <(E-Mail Removed)> schrieb
>
> >
> > Whenever I change the dialogresult property it does change right
> > away.
> >
> >

> This is my scenerio:
>
> - I launch a dialog box (form 2) from form 1 using
> "Dialog_AddName_Results = CustomerName.ShowDialog()"
> - On the dialog box, the "Add" button "DialogResult" property is set
> to "None" by default
> - On the "Add" button click event, some code evaluates to true or
> false - If the above code evaluates to true, it sets "DialogResult"
> to OK (1)
>
> The thing is, the dialog box does not close up right away - as when
> the "Add" button was first pressed, the "DialogResult" was set to
> "None"
>
> Hope that gets you to the point where I am. Is there an event that I
> can run before the click event of the button that will run when the
> button is clicked?


I still don't understand. Why don't you simply put

If <evaluationIsTrue> Then
Me.DialogResult = Dialogresult.Ok
Me.Close
End If

in the button's click event? Now you don't have to click twice.


--
Armin

 
Reply With Quote
 
Sarah
Guest
Posts: n/a
 
      5th Sep 2003
Then, the calling form does not get the information via :

"Dialog_AddName_Results = CustomerName.ShowDialog()"




 
Reply With Quote
 
Armin Zingler
Guest
Posts: n/a
 
      6th Sep 2003
"Sarah" <(E-Mail Removed)> schrieb
> Then, the calling form does not get the information via :
>
> "Dialog_AddName_Results = CustomerName.ShowDialog()"



Here it does get the result.

Code in Form2, Button_Click:

Me.DialogResult = DialogResult.OK
Me.Close()

Code in Form1:
Dim result As DialogResult
Dim f As New Form2
result = f.ShowDialog
MsgBox(result.ToString)

The msgbox shows "OK"


--
Armin

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to call a command button click event from code tsison7 Microsoft Access VBA Modules 5 23rd Jan 2008 02:25 AM
How to raise by code the click event of a button in C# polocar Microsoft C# .NET 2 3rd Nov 2006 03:20 PM
code for calling a button event (click) ? (asp.net 2) moi Microsoft ASP .NET 2 8th Mar 2006 02:32 PM
Button.Init? how Do I know if click event has been fired? TextBox.TextChanged event before Button.Click in a CompositeCustomControl. jorge Microsoft ASP .NET 2 26th May 2004 12:45 AM
Running command button click event code Marishah Warren Microsoft Excel Programming 1 31st Dec 2003 07:53 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:15 PM.