473,471 Members | 1,860 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

have a form return a value when it closes

hi, im attempting to create an intellisense type form and have hit a
roadblock. I need the form to return (like the ShowDialog method returns the
dialog result) the value that was selected when the form closes. however, i
cannot just create a method that shadows ShowDialog and return it that way
because the form needs to close when the user clicks elsewhere on the screen,
or Alt-Tabs away from the window. i already have the code to close the window
when the user clicks or aalt-tabs away, but how can i have the form return a
result when this occurs? thanks
--
-iwdu15
Feb 24 '07 #1
7 15093
You can create a public property on the form and then after the return from
ShowDialog get the value. When the form returns the class object (which is
the form) is still available and you can read the value from the property.
I do this lots.

LS

"iwdu15" <jmmgoalsteratyahoodotcomwrote in message
news:15**********************************@microsof t.com...
hi, im attempting to create an intellisense type form and have hit a
roadblock. I need the form to return (like the ShowDialog method returns
the
dialog result) the value that was selected when the form closes. however,
i
cannot just create a method that shadows ShowDialog and return it that way
because the form needs to close when the user clicks elsewhere on the
screen,
or Alt-Tabs away from the window. i already have the code to close the
window
when the user clicks or aalt-tabs away, but how can i have the form return
a
result when this occurs? thanks
--
-iwdu15
Feb 24 '07 #2
You can invoke a function on the form that returns a value, and in the
function do a me.showdialog(). Like this:

'to invoke this class, do this: X = SelectDatabase.PromptUser
' X will be the returned ConnectionString.
'Return empty string if user clicks Cancel.
Public Function PromptUser() As String
Me.ShowDialog()
If (Me.DialogResult = Windows.Forms.DialogResult.OK) Then
My.Settings.DBConnString = CreateConnectionString("Y")
My.Settings.DatabaseName = DatabaseComboBox.Text
My.Settings.ServerName = ServerTextBox.Text
My.Settings.Save()
Return DatabaseComboBox.Text
Else
Return String.Empty
End If
End Function

Robin S.
--------------------------
"iwdu15" <jmmgoalsteratyahoodotcomwrote in message
news:15**********************************@microsof t.com...
hi, im attempting to create an intellisense type form and have hit a
roadblock. I need the form to return (like the ShowDialog method returns
the
dialog result) the value that was selected when the form closes. however,
i
cannot just create a method that shadows ShowDialog and return it that
way
because the form needs to close when the user clicks elsewhere on the
screen,
or Alt-Tabs away from the window. i already have the code to close the
window
when the user clicks or aalt-tabs away, but how can i have the form
return a
result when this occurs? thanks
--
-iwdu15

Feb 24 '07 #3
i realize i can do those things, the issue is that if the user clicks away or
alt-tabs away from the window, ShowDialog does not let the window close. i
want the window to close if the user clicks away or alt-tabs away, so i
cannot use ShowDialog.....i pretty much need to make an exact replica of
Intellisense
--
-iwdu15
Feb 24 '07 #4
I thought you said (in your first post) that you solved the problem of
closing the form when the user clicks away. Are you now saying you
didn't solve that? I'd probably try putting a me.close() in the
form's LostFocus event. And I may need to show the form modeless with
a Show() method rather than modally with a ShowDialog() method (if it
beeps at you when you try to click somewhere else).

I still think Lloyd's solution should work for you. Not sure why you
don't.
Regards,
ImageAnalyst

On Feb 24, 3:22 pm, iwdu15 <jmmgoalsteratyahoodotcomwrote:
i realize i can do those things, the issue is that if the user clicks away or
alt-tabs away from the window, ShowDialog does not let the window close. i
want the window to close if the user clicks away or alt-tabs away, so i
cannot use ShowDialog.....i pretty much need to make an exact replica of
Intellisense
--
-iwdu15

Feb 25 '07 #5
If you want click away functionallity then perhaps you can use the context
menu. It can be shown thru code as well as auto and as a control's context
menu.

Then when you click away the dialog (context menu) will disappear.

LS
"iwdu15" <jmmgoalsteratyahoodotcomwrote in message
news:28**********************************@microsof t.com...
>i realize i can do those things, the issue is that if the user clicks away
or
alt-tabs away from the window, ShowDialog does not let the window close. i
want the window to close if the user clicks away or alt-tabs away, so i
cannot use ShowDialog.....i pretty much need to make an exact replica of
Intellisense
--
-iwdu15
Feb 25 '07 #6
On Feb 24, 9:34 pm, "ImageAnalyst" <imageanal...@mailinator.com>
wrote:
I thought you said (in your first post) that you solved the problem of
closing the form when the user clicks away. Are you now saying you
didn't solve that? I'd probably try putting a me.close() in the
form's LostFocus event. And I may need to show the form modeless with
a Show() method rather than modally with a ShowDialog() method (if it
beeps at you when you try to click somewhere else).
If he uses the Show method, as soon as the form closes, it will be
disposed and if he then tries to access a custom property he will
likely get an exception.
Feb 26 '07 #7

"Chris Dunaway" <du******@gmail.comwrote in message
news:11********************@q2g2000cwa.googlegroup s.com...
On Feb 24, 9:34 pm, "ImageAnalyst" <imageanal...@mailinator.com>
wrote:
>I thought you said (in your first post) that you solved the problem of
closing the form when the user clicks away. Are you now saying you
didn't solve that? I'd probably try putting a me.close() in the
form's LostFocus event. And I may need to show the form modeless with
a Show() method rather than modally with a ShowDialog() method (if it
beeps at you when you try to click somewhere else).

If he uses the Show method, as soon as the form closes, it will be
disposed and if he then tries to access a custom property he will
likely get an exception.

He could put a property in his first form, and set it from the second form
in the form_closing event.

Robin S.
Feb 26 '07 #8

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

Similar topics

0
by: Steve Wark | last post by:
I'm trying to develop a lookup form in asp.net (vb), when a button is clicked a small search form will open in a second window which will display a list of values. When a value is selected the...
2
by: alpha_male | last post by:
Hello What way would be the best of selecting value by using another form? I use command button wizard to open another form. But in what way I can return the current record's value to the...
1
by: Chris Bruce | last post by:
In my application I need a way to distiguish between the following events: 1. When a user closes an MDI child window. 2. When the user closes the MDI parent window which subsequently closes the...
5
by: Tilfried Weissenberger | last post by:
Hi, I would like to specify a group of Properties/Fields of some objects on a WinForm, for which I would like to have the values loaded from the Registry, and saved to it upon closing of the...
6
by: James Radke | last post by:
Hello, I have a multithreaded windows NT service application (vb.net 2003) that I am working on (my first one), which reads a message queue and creates multiple threads to perform the processing...
5
by: manningfan | last post by:
I have a single form that I want to make as generic as possible. The form contains a Calendar control. Using OpenArgs I pass values from the form that's calling the calendar, and the field the...
4
by: c_shah | last post by:
Windows form application I have an accounting application, the main form of that application can be launched from other application passing the account number or it can be started as a...
1
by: genius.jain | last post by:
HI i am opening a form as showdialog In amin form MDI Private Sub ToolStripMenuItem5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem5.Click Try Dim...
3
by: rom15becs | last post by:
Hi everyone, I'm working on a project that uses 2 forms : one to select an object and one other to display its attributes. I mean that in the first one I select an object (from a ComboBox), then...
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
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...
1
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
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,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.