1 Replies - 4600 Views - Last Post: 06 November 2006 - 12:39 AM Rate Topic: -----

#1 alarthame   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 27-September 06

changing user controls inside panels

Posted 23 October 2006 - 05:12 PM

Hey all,

I've been kinda tinkering around with VB.NET 2005 trying to get my legs with it again, but I figured I might be able to post on here and get a little boost.

I've made a user control with 8 panels on it which will each have the same embedded user control on them. This user control will have 3 buttons that switch between 3 other user controls that would go in the panel that the button was clicked from. I was wondering if anyone could spell out for me what thecode would be to make UC find which panel it was in and send the next designated UC in its place. I keep getting NullReferenceExceptions which I assume is because I'm not pointing to the place that it's supposed to go. The code I have now is pretty basic:

Public Class MonsterInterface

	Dim m_MonsterInitializePart1 As MonsterInitialize
	Dim m_MonsterInitializePart2 As MonsterInitialize
	Dim m_MonsterInitializePart3 As MonsterInitialize
	Dim m_MonsterInitializePart4 As MonsterInitialize
	Dim m_MonsterInitializePart5 As MonsterInitialize
	Dim m_MonsterInitializePart6 As MonsterInitialize
	Dim m_MonsterInitializePart7 As MonsterInitialize
	Dim m_MonsterInitializePart8 As MonsterInitialize

Friend ReadOnly Property MonsterInitializePart1() As MonsterInitialize
		Get
			'initialize the new custom instead of standard
			If Me.m_MonsterInitializePart1 Is Nothing Then
				Me.m_MonsterInitializePart1 = New MonsterInitialize

				Me.MonsterPanel1.Controls.Add(Me.m_MonsterInitializePart1)
				Me.m_MonsterInitializePart1.Dock = DockStyle.Fill
			End If

			Return Me.m_MonsterInitializePart1

		End Get
	End Property

 Friend Sub ShowMonsterInitialize()
		If Me.MonsterInitializePart1 IsNot Nothing Then
			Me.MonsterInitializePart1.Visible = False
		End If
.
.
.
	 'show all panels
	  Me.MonsterInitializePart1.Visible = True
.
.
.
 End Sub
End Class

'first user control
Public Class MonsterInitialize

	Dim m_MonsterSearch As MonsterSearch
	Dim m_CriteriaSearch As CriteriaSearch
	Dim m_CreateMonster As CreateMonster

	Private Sub MonsterSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MonsterSearch.Click
		Me.ShowMonsterSearch()
	End Sub

	Private Sub CriteriaSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CriteriaSearch.Click
		Me.ShowCriteriaSearch()
	End Sub

	Private Sub CreateMonster_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CreateMonster.Click
		Me.ShowCreateMonster()
	End Sub

	Private Sub ShowMonsterSearch()
		Me.m_MonsterSearch.Dock = DockStyle.Fill
	End Sub

	Private Sub ShowCriteriaSearch()
		Me.m_CriteriaSearch.Dock = DockStyle.Fill
	End Sub

	Private Sub ShowCreateMonster()
		Me.m_CreateMonster.Dock = DockStyle.Fill
	End Sub
End Class



Hope someone can help. :)

Patrick

Is This A Good Question/Topic? 0
  • +

Replies To: changing user controls inside panels

#2 sontek   User is offline

  • D.I.C Regular
  • member icon

Reputation: 8
  • View blog
  • Posts: 283
  • Joined: 13-September 01

Re: changing user controls inside panels

Posted 06 November 2006 - 12:39 AM

View Postalarthame, on 23 Oct, 2006 - 05:12 PM, said:

Hey all,

I've been kinda tinkering around with VB.NET 2005 trying to get my legs with it again, but I figured I might be able to post on here and get a little boost.

I've made a user control with 8 panels on it which will each have the same embedded user control on them. This user control will have 3 buttons that switch between 3 other user controls that would go in the panel that the button was clicked from. I was wondering if anyone could spell out for me what thecode would be to make UC find which panel it was in and send the next designated UC in its place. I keep getting NullReferenceExceptions which I assume is because I'm not pointing to the place that it's supposed to go. The code I have now is pretty basic:

Public Class MonsterInterface

	Dim m_MonsterInitializePart1 As MonsterInitialize
	Dim m_MonsterInitializePart2 As MonsterInitialize
	Dim m_MonsterInitializePart3 As MonsterInitialize
	Dim m_MonsterInitializePart4 As MonsterInitialize
	Dim m_MonsterInitializePart5 As MonsterInitialize
	Dim m_MonsterInitializePart6 As MonsterInitialize
	Dim m_MonsterInitializePart7 As MonsterInitialize
	Dim m_MonsterInitializePart8 As MonsterInitialize

Friend ReadOnly Property MonsterInitializePart1() As MonsterInitialize
		Get
			'initialize the new custom instead of standard
			If Me.m_MonsterInitializePart1 Is Nothing Then
				Me.m_MonsterInitializePart1 = New MonsterInitialize

				Me.MonsterPanel1.Controls.Add(Me.m_MonsterInitializePart1)
				Me.m_MonsterInitializePart1.Dock = DockStyle.Fill
			End If

			Return Me.m_MonsterInitializePart1

		End Get
	End Property

 Friend Sub ShowMonsterInitialize()
		If Me.MonsterInitializePart1 IsNot Nothing Then
			Me.MonsterInitializePart1.Visible = False
		End If
.
.
.
	 'show all panels
	  Me.MonsterInitializePart1.Visible = True
.
.
.
 End Sub
End Class

'first user control
Public Class MonsterInitialize

	Dim m_MonsterSearch As MonsterSearch
	Dim m_CriteriaSearch As CriteriaSearch
	Dim m_CreateMonster As CreateMonster

	Private Sub MonsterSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MonsterSearch.Click
		Me.ShowMonsterSearch()
	End Sub

	Private Sub CriteriaSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CriteriaSearch.Click
		Me.ShowCriteriaSearch()
	End Sub

	Private Sub CreateMonster_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CreateMonster.Click
		Me.ShowCreateMonster()
	End Sub

	Private Sub ShowMonsterSearch()
		Me.m_MonsterSearch.Dock = DockStyle.Fill
	End Sub

	Private Sub ShowCriteriaSearch()
		Me.m_CriteriaSearch.Dock = DockStyle.Fill
	End Sub

	Private Sub ShowCreateMonster()
		Me.m_CreateMonster.Dock = DockStyle.Fill
	End Sub
End Class



Hope someone can help. :)

Patrick



From a quick look at the code it seems that you are accessing the private datamember of your control ( m_CreateMonster.Dock, m_CriteriaSearch.Dock ) but you are initializing the Control inside the property. So since you aren't calling the Property it isn't being initialized which will give you a null exception
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1