Hi ,I don't know where do I have to add form and module? I want add both module and form in an application.
how can I call form in my module?
Please explain me by example.
Thanks
Hi ,I don't know where do I have to add form and module? I want add both module and form in an application.
how can I call form in my module?
Please explain me by example.
Thanks
Generally speaking if you want to interact between a module and a form I'd recommend using a class (rather than a module) with a delegate/event.
Your delegate can send information to the form or perhaps send a signal to a form and when the form gets the signal do something. The signal could be a number, an enum or an instance of a class and more if needed.
Example, we want to interact with a object, in this case
Public Class PersonGrades
Public Property PersonID() As Integer
Public Property FirstName() As String
Public Property LastName() As String
Public Property Grade() As Decimal?
Public Property GradeLetter() As String
End Class
Our super simple class
Public Class Operations
Public Delegate Sub OnIteratePersonGrades(ByVal personData As PersonGrades)
Public Shared Event OnIteratePersonGradesEvent As OnIteratePersonGrades
Public Shared Sub DoSomething()
RaiseEvent OnIteratePersonGradesEvent(New PersonGrades() With
{
.PersonID = -1,
.FirstName = "Karen",
.LastName = "Payne",
.Grade = 100
})
End Sub
End Class
Form code where in form shown event we subscribe to the event in the Operations class then for simplicity call a do nothing method and send a person object to the form. In turn the form looks at the id, if -1 we do something for a new record while greater than -1 we have an edit. The do something may then interact with form controls for instance.
Public Class MainForm
Private Sub MainForm_Shown(sender As Object, e As EventArgs) Handles Me.Shown
AddHandler Operations.OnIteratePersonGradesEvent, AddressOf OnIteration
End Sub
Private Sub OnIteration(persondata As PersonGrades)
If persondata.PersonID = -1 Then
' do something for a new person
Else
' do something for an edited person
End If
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Operations.DoSomething()
End Sub
End Class
In closing, many developers never learn about delegates/events and are well worth time placed to learn about them.
Hi,
try this module in console demo:
Imports System.Windows.Forms
Module Module1
Sub Main()
Try
Dim c As New Demo
c.Execute()
Catch ex As Exception
Console.WriteLine(ex.ToString)
End Try
Console.WriteLine("Continue enter key")
Console.ReadKey()
End Sub
Friend Class Demo
Friend Sub Execute()
Application.EnableVisualStyles()
Application.SetCompatibleTextRenderingDefault(False)
Application.DoEvents()
Application.Run(New Form1())
End Sub
End Class
Friend Class Form1
Inherits Form
Private Label1 As New Label() With {.Text = "Form 1 loaded"}
Public Sub New()
AddHandler Me.Load, Sub()
Me.Controls.Add(Label1)
End Sub
End Sub
End Class
End Module
Please explain about that where can I use this
In my solution or project?
5 people are following this question.