|
Public Class ctrlMain
#Region "Event Handlers"
Private Sub btnViewAddressBook_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnViewAddressBook.Click
' The next statement (in comments) will display the myMainForm's Text,
' as this control's Parent is the Panel,
' but the ParentForm is the Form above it, i.e. the myMainForm
' MessageBox.Show(Me.ParentForm.Text)
' To access the panel from here we have to use the following statement:
' Me.ParentForm.Controls.Item("myPanel")
' Similarly, To Access the controls in the Panel:
' Me.ParentForm.Controls.Item("myPanel").Controls
' A major thing to note here is that we cannot use the 'tempObject' as
' a key to access the user control. It is by default at '0' index of Controls.
' As the panel is being used to display one control at a time,
' the control will always be at '0' index:
' Me.ParentForm.Controls.Item("myPanel").Controls(0)
' Now we create a new object of the new control and add it to the controls of the panel.
Dim tempObject As New ctrlViewAddressBook
Me.ParentForm.Controls.Item("myPanel").Controls.Add(tempObject)
' Next we want to remove the previous control so that the new control will be displayed.
' Note: When we remove the control at index '0', the original (old) control is removed.
' And the new control is moved to index '0'.
Me.ParentForm.Controls.Item("myPanel").Controls.RemoveAt(0)
End Sub
Private Sub btnAddNewEntry_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddNewEntry.Click
Dim tempObject As New ctrlAddNewEntry
Me.ParentForm.Controls.Item("myPanel").Controls.Add(tempObject)
Me.ParentForm.Controls.Item("myPanel").Controls.RemoveAt(0)
End Sub
Private Sub btnManageCategories_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnManageCategories.Click
Dim tempObject As New ctrlAddNewCategory
Me.ParentForm.Controls.Item("myPanel").Controls.Add(tempObject)
Me.ParentForm.Controls.Item("myPanel").Controls.RemoveAt(0)
End Sub
Private Sub btnSearchAddressBook_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrintAddressBook.Click
Try
Dim tempReport As New rptAddressBook
Dim tempViewer As New rptViewer
Dim tempDs As New Data.DataSet
tempDs = DataLayer.selectAllRecord()
If tempDs.Tables("tblAddressBook").Rows.Count > 0 Then
tempReport.SetDataSource(tempDs)
tempViewer.viewer.ReportSource = tempReport
tempViewer.ShowDialog()
Else
Dim tempMessage(1) As String
tempMessage(0) = "Address Book is currently Empty."
tempMessage(1) = "Printing Cancelled."
Dim tempForm As New myMessageBox
tempForm.txtMessage.Lines = tempMessage
tempForm.Text = "Printing Aborted!!!"
tempForm.ShowDialog()
End If
Catch ex As Exception
Dim tempForm As New myMessageBox
tempForm.Text = "Error!"
tempForm.lblHeader.Text = "Crystal Report Error!!!"
Dim temp(2) As String
temp(0) = "An error occurred while creating the report for printing."
temp(1) = ""
temp(2) = "Possibly missing updated Crystal Report Extenstions."
tempForm.txtMessage.Lines = temp
tempForm.ShowDialog()
End Try
End Sub
#End Region
End Class
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I am currently working as a Senior Software Developer (.Net) in Premier POS, Inc. Focused mainly on Windows Application Development, i am now looking for inspiration to work on Windows Presentation Foundation.