473,785 Members | 2,882 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Does WinForm return anything?

Ken
How can I have my WinForm return something to the caller so it knows which
button is clicked? The following is calling a system message box, just want
to do the samething with my own winform. Thanks.

If MsgBox("Data added.", MsgBoxStyle.OKC ancel, "Message") = MsgBoxResult.OK
Then
' do something

End If
Nov 21 '05 #1
3 2837
Ken,

"Ken" <Ke*@discussion s.microsoft.com > schrieb:
How can I have my WinForm return something to the
caller so it knows which button is clicked?


Set the form's 'DialogResult' property and check the value of this property
after closing the form:

\\\
Dim f As New FooForm()
Select Case f.ShowDialog()
Case DialogResult.OK
...
Case DialogResult.Ca ncel
...
Case...
...
...
End Select
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 21 '05 #2
In article <43************ *************** *******@microso ft.com>, Ken wrote:
How can I have my WinForm return something to the caller so it knows which
button is clicked? The following is calling a system message box, just want
to do the samething with my own winform. Thanks.

If MsgBox("Data added.", MsgBoxStyle.OKC ancel, "Message") = MsgBoxResult.OK
Then
' do something

End If

Simple example...

Create a solution with two forms, form1 and form2 copy in the following
code:

' Form1 Code
Imports System.Windows. Forms
Public Class Form1
Inherits System.Windows. Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeCompo nent()

'Add any initialization after the InitializeCompo nent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As
Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Disp ose()
End If
End If
MyBase.Dispose( disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.Componen tModel.IContain er

'NOTE: The following procedure is required by the Windows Form
Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Button1 As System.Windows. Forms.Button
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()
Me.Button1 = New System.Windows. Forms.Button
Me.SuspendLayou t()
'
'Button1
'
Me.Button1.Loca tion = New System.Drawing. Point(8, 4)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing. Size(196, 23)
Me.Button1.TabI ndex = 0
Me.Button1.Text = "&Show Custom Dialog"
'
'Form1
'
Me.AutoScaleBas eSize = New System.Drawing. Size(5, 13)
Me.ClientSize = New System.Drawing. Size(212, 34)
Me.Controls.Add (Me.Button1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout (False)

End Sub

#End Region

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Dim dialog As New Form2
Dim result As DialogResult = dialog.ShowDial og()
Select Case result
Case DialogResult.Ab ort
MessageBox.Show ("Abort Selected")
Case DialogResult.Ca ncel
MessageBox.Show ("Cancel Selected")
Case DialogResult.Re try
MessageBox.Show ("Retry Selected")
End Select
End Sub
End Class

'Form2 Code
Imports System.Windows. Forms
Public Class Form2
Inherits System.Windows. Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeCompo nent()

'Add any initialization after the InitializeCompo nent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As
Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Disp ose()
End If
End If
MyBase.Dispose( disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.Componen tModel.IContain er

'NOTE: The following procedure is required by the Windows Form
Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Button1 As System.Windows. Forms.Button
Friend WithEvents Button2 As System.Windows. Forms.Button
Friend WithEvents Button3 As System.Windows. Forms.Button
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()
Me.Button1 = New System.Windows. Forms.Button
Me.Button2 = New System.Windows. Forms.Button
Me.Button3 = New System.Windows. Forms.Button
Me.SuspendLayou t()
'
'Button1
'
Me.Button1.Dial ogResult =
System.Windows. Forms.DialogRes ult.Abort
Me.Button1.Loca tion = New System.Drawing. Point(8, 12)
Me.Button1.Name = "Button1"
Me.Button1.TabI ndex = 0
Me.Button1.Text = "Abort"
'
'Button2
'
Me.Button2.Dial ogResult =
System.Windows. Forms.DialogRes ult.Cancel
Me.Button2.Loca tion = New System.Drawing. Point(92, 12)
Me.Button2.Name = "Button2"
Me.Button2.TabI ndex = 1
Me.Button2.Text = "Cancel"
'
'Button3
'
Me.Button3.Dial ogResult =
System.Windows. Forms.DialogRes ult.Retry
Me.Button3.Loca tion = New System.Drawing. Point(176, 12)
Me.Button3.Name = "Button3"
Me.Button3.TabI ndex = 2
Me.Button3.Text = "Retry"
'
'Form2
'
Me.AutoScaleBas eSize = New System.Drawing. Size(5, 13)
Me.ClientSize = New System.Drawing. Size(262, 48)
Me.Controls.Add (Me.Button3)
Me.Controls.Add (Me.Button2)
Me.Controls.Add (Me.Button1)
Me.FormBorderSt yle =
System.Windows. Forms.FormBorde rStyle.FixedDia log
Me.MaximizeBox = False
Me.MinimizeBox = False
Me.Name = "Form2"
Me.ShowInTaskba r = False
Me.Text = "Form2"
Me.ResumeLayout (False)

End Sub

#End Region
End Class

HTH
--
Tom Shelton [MVP]
Nov 21 '05 #3
Ken
Very well. Thank you all.

"Tom Shelton" wrote:
In article <43************ *************** *******@microso ft.com>, Ken wrote:
How can I have my WinForm return something to the caller so it knows which
button is clicked? The following is calling a system message box, just want
to do the samething with my own winform. Thanks.

If MsgBox("Data added.", MsgBoxStyle.OKC ancel, "Message") = MsgBoxResult.OK
Then
' do something

End If

Simple example...

Create a solution with two forms, form1 and form2 copy in the following
code:

' Form1 Code
Imports System.Windows. Forms
Public Class Form1
Inherits System.Windows. Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeCompo nent()

'Add any initialization after the InitializeCompo nent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As
Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Disp ose()
End If
End If
MyBase.Dispose( disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.Componen tModel.IContain er

'NOTE: The following procedure is required by the Windows Form
Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Button1 As System.Windows. Forms.Button
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()
Me.Button1 = New System.Windows. Forms.Button
Me.SuspendLayou t()
'
'Button1
'
Me.Button1.Loca tion = New System.Drawing. Point(8, 4)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing. Size(196, 23)
Me.Button1.TabI ndex = 0
Me.Button1.Text = "&Show Custom Dialog"
'
'Form1
'
Me.AutoScaleBas eSize = New System.Drawing. Size(5, 13)
Me.ClientSize = New System.Drawing. Size(212, 34)
Me.Controls.Add (Me.Button1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout (False)

End Sub

#End Region

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Dim dialog As New Form2
Dim result As DialogResult = dialog.ShowDial og()
Select Case result
Case DialogResult.Ab ort
MessageBox.Show ("Abort Selected")
Case DialogResult.Ca ncel
MessageBox.Show ("Cancel Selected")
Case DialogResult.Re try
MessageBox.Show ("Retry Selected")
End Select
End Sub
End Class

'Form2 Code
Imports System.Windows. Forms
Public Class Form2
Inherits System.Windows. Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeCompo nent()

'Add any initialization after the InitializeCompo nent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As
Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Disp ose()
End If
End If
MyBase.Dispose( disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.Componen tModel.IContain er

'NOTE: The following procedure is required by the Windows Form
Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Button1 As System.Windows. Forms.Button
Friend WithEvents Button2 As System.Windows. Forms.Button
Friend WithEvents Button3 As System.Windows. Forms.Button
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()
Me.Button1 = New System.Windows. Forms.Button
Me.Button2 = New System.Windows. Forms.Button
Me.Button3 = New System.Windows. Forms.Button
Me.SuspendLayou t()
'
'Button1
'
Me.Button1.Dial ogResult =
System.Windows. Forms.DialogRes ult.Abort
Me.Button1.Loca tion = New System.Drawing. Point(8, 12)
Me.Button1.Name = "Button1"
Me.Button1.TabI ndex = 0
Me.Button1.Text = "Abort"
'
'Button2
'
Me.Button2.Dial ogResult =
System.Windows. Forms.DialogRes ult.Cancel
Me.Button2.Loca tion = New System.Drawing. Point(92, 12)
Me.Button2.Name = "Button2"
Me.Button2.TabI ndex = 1
Me.Button2.Text = "Cancel"
'
'Button3
'
Me.Button3.Dial ogResult =
System.Windows. Forms.DialogRes ult.Retry
Me.Button3.Loca tion = New System.Drawing. Point(176, 12)
Me.Button3.Name = "Button3"
Me.Button3.TabI ndex = 2
Me.Button3.Text = "Retry"
'
'Form2
'
Me.AutoScaleBas eSize = New System.Drawing. Size(5, 13)
Me.ClientSize = New System.Drawing. Size(262, 48)
Me.Controls.Add (Me.Button3)
Me.Controls.Add (Me.Button2)
Me.Controls.Add (Me.Button1)
Me.FormBorderSt yle =
System.Windows. Forms.FormBorde rStyle.FixedDia log
Me.MaximizeBox = False
Me.MinimizeBox = False
Me.Name = "Form2"
Me.ShowInTaskba r = False
Me.Text = "Form2"
Me.ResumeLayout (False)

End Sub

#End Region
End Class

HTH
--
Tom Shelton [MVP]

Nov 21 '05 #4

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

Similar topics

3
2887
by: jdionne | last post by:
I have a WInform app that runs a DTS. When I developed it on the SQL box and executed it, it ran fine. I used the Trusted connection parameter for the DTS. I don't want to use passwords. I packaged up the project and put in on another box. Now I get SQL Server errors: Description: SQL Server does not exist or access denied. Even when I change the connection type for the DTS back to default and put in the sa password I get the same...
0
1271
by: Thom Little | last post by:
..NET Framework 1.1 I have a C# WinForm that invokes a C# WebForm using System.Diagnostics.Process.Start( ) to invoke the default browser and access a specific URL. This works great but I can not provide status information from the WebForm to the WinForm. How can I modify this approach to permit the WebForm to return status information to the WinForm?
1
2079
by: i | last post by:
Hi, I'm trying to get a seperate class, initialized by a form class, to manipulate certain objects on the form (ex: add to a listbox). The manipulation will occur via a thread that is not the normal WinForm GUI thread. How would I go about doing this? I have this code for cross-thread WinForm manipulation, but only from within the WinForm class:
2
1234
by: Wayne | last post by:
I have a winform that runs on its own, is it possible to wrap a stand-alone winform in a class? More accurately, is it possible to use a class to call an already established winform?
5
4332
by: Matthew Hood | last post by:
Here's a interesting question for the guru's out there. I've created a VB.NET class library with a couple of forms that I have successfully got to work from within MS Access using COM interop and VBA. (Working, meaning it hasn't crashed on me yet... ;-). I Would anybody know how to take this VB.NET Winform (using it's handle, subclassing, or other means) and set it's parent to be the Access MDI client area so that it will behave as if...
11
11765
by: jjbutera | last post by:
I know how to use the ErrorProvider in my winforms..or do I? I validate the values and set the ErrorProvider in the validating event. If not valid, I set e.Cancel = True. I clear the ErrorProvider in the validated event. Is there a way to know if all validated controls pass validation when the user clicks an OK button? In ASP.Net there's the Page.IsValid method. Is there something similar in winforms, or do I still have to write an...
3
8310
by: Nick Gilbert | last post by:
Hi, In my VS.NET 2005, if I choose Build Clean Solution, the BIN folder is not touched. Shouldn't it delete all the dll and pdb files in that folder first? Instead, I'm finding I have to do it manually. Also, when I change from Debug to Release, all the pdb files remain in the bin folder. Shouldn't these be deleted automatically? Please let me know what the "Clean Solution" is supposed to do (if it's
6
2811
by: WT | last post by:
Hello, Using VS2005. I have an assembly library that can be called from a Web site asp.net application or from a winform application. From this library I need to retrieve a path using simply a key like 'libPath'. As far as winform and asp.net share the same common base class for settings, SettingsBase, how to manage this ? For winform the value should be set in app.config and for web site in
1
7209
by: jabbari | last post by:
Hello, Please Help us...! I have a big problem ,so i searched on google and other search engine ,then I realized that so many other people have the same problem and they, all, have'nt been able to solve it. My problem is: I want to import a dll in asp.net, and I have a major problem First i want to say that this dll works fine in a windows application written in C#, and It works fine when I use the ASP.NET development server (Local...
0
9645
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10151
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9950
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8973
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5381
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4053
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 we have to send another system
2
3647
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2879
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.