Hi all Im converting code from vb.net to c# an im stuck again! :O)
anyway ive included both vb and c# versions and if anyone could see
where im going wrong it would much appreaciated.
i've tried to simplify the code as much as i can.
here is the vb first.
this displayHomePage() is first called from the new sub in frmShell.vb
class
Private Sub displayHomePage()
Try
Dim pg As Page
While history.Count > 0
pg = CType(history.Pop, Page)
pg.Dispose()
End While
If Not currentPage Is Nothing Then
currentPage.Dispose()
currentPage = Nothing
End If
Dim newPage As New HomePage()
currentPage = newPage
newPage.DisplayPage(Me)
Catch ex As System.Exception
ErrorHandler.GenericHandler(ex)
End Try
End Sub
//This is in a new class called page and overridden from two inherited
pages navigationpage and homepage.
Public Overridable Sub DisplayPage(ByRef myForm As frmMain)
myForm.currentPage = Me
Me.albumList = myForm.albumList
Me.detailList = myForm.detailList
Me.mainList = myForm.listNavigation
Me.sideList = myForm.sideNavigation
Me.softKeyboard = myForm.softKeyboard
Me.theForm = myForm
If Me.softKeyboard.Visible Then
Me.softKeyboard.Text = softKeyboardText
End If
If Me.albumList.Visible Then
Me.albumList.SelectedIndex = albumListSelectedIndex
End If
If Me.detailList.Visible Then
Me.detailList.SelectedIndex = detailListSelectedIndex
End If
If Me.mainList.Visible Then
Me.mainList.SelectedIndex = mainListSelectedIndex
End If
If Me.sideList.Visible Then
Me.sideList.SelectedIndex = sideListSelectedIndex
End If
Select Case hasFocus
Case "softKeyboard"
Me.softKeyboard.Focus()
Case "albumList"
Me.albumList.Focus()
Case "detailList"
Me.detailList.Focus()
Case "mainList"
Me.mainList.Focus()
Case "sideList"
Me.sideList.Focus()
End Select
End Sub
//The override in Navigation page
Public Overrides Sub DisplayPage(ByRef myForm As frmMain)
'handle events
With myForm
.HideControls()
.SetUpFullListView()
.listNavigation.DataSource = navArray
.listNavigation.Visible = True
.listNavigation.RightSelect = True
.listNavigation.Focus()
End With
MyBase.DisplayPage(myForm)
End Sub
//The override in Homepage
Public Overrides Sub DisplayPage(ByRef myForm As frmMain)
MyBase.DisplayPage(myForm)
myForm.wmp.Visible = True
myForm.SetUpHomeView()
End Sub
End Class
//this method in the page class handles an event on the homepage and
calls another method in the HomePage class. this is where i think
things go wrong in the c# version
Private Sub mainList_Selected(ByVal sSelected As String, ByVal Data
As Object) Handles mainList.Selected
Sounds.PlaySelectSound()
RaiseEvent MainListSelected(sSelected, Data)
End Sub
//this is the method it calls in the Homepage class
Private Sub HomePage_MainListSelected(ByVal sSelected As String, ByVal
Data As Object) Handles MyBase.MainListSelected
Debug.WriteLine("HomePage_MainListSelected")
Select Case sSelected
Case "Browse Artists"
Dim page2 As New ArtistListing()
Dim myForm As frmMain = Me.theForm
Me.SavePageState(Me.theForm)
Me.theForm.history.Push(Me)
Debug.WriteLine("HomePage Push")
page2.DisplayPage(myForm)
Case "Browse All Albums"
Dim page2 As New AlbumListPage()
Dim myForm As frmMain = Me.theForm
Me.SavePageState(Me.theForm)
Me.theForm.history.Push(Me)
Debug.WriteLine("HomePage Push")
page2.DisplayPage(myForm)
...........................
.......................
End Select
End Sub
when Me.SavePageState(Me.theForm) is called in the vb version its fine
and passes it but in the c# conversion it is null for some reason
Me.SavePageState(Me.theForm)
Anyway if anybody is still reading :O) here is the c# code in the same
order.
private void displayHomePage()
{
try
{
Page pg;
while (history.Count > 0)
{
pg = (Page) history.Pop();
pg.Dispose();
}
if (currentPage != null)
{
currentPage.Dispose();
currentPage = null;
}
HomePage newPage = new HomePage();
currentPage = newPage;
MusicXP.frmMain X = this;
newPage.DisplayPage(ref X);
}
catch (System.Exception ex)
{
ErrorHandler.GenericHandler(ex);
}
}
This is in the page class
public virtual void DisplayPage(ref frmMain myForm)
{
myForm.currentPage = this;
this.albumList = myForm.albumList;
this.detailList = myForm.detailList;
this.mainList = myForm.listNavigation;
this.sideList = myForm.sideNavigation;
this.softKeyboard = myForm.softKeyboard;
this.theForm = myForm;
this.mainList.Selected += new
dmControls.ListControl.SelectedEventHandler(mainLi st_Selected);
MainListSelectedEvent += new
MainListSelectedEventHandler(mainList_Selected);
//......................more event stuff here but i just
left one on show
if (this.softKeyboard.Visible)
{
this.softKeyboard.Text = softKeyboardText;
}if (this.albumList.Visible)
{
this.albumList.SelectedIndex = albumListSelectedIndex;
}if (this.detailList.Visible)
{
this.detailList.SelectedIndex = detailListSelectedIndex;
}if (this.mainList.Visible)
{
this.mainList.SelectedIndex = mainListSelectedIndex;
}if (this.sideList.Visible)
{
this.sideList.SelectedIndex = sideListSelectedIndex;
}
switch (hasFocus)
{
case "softKeyboard":
this.softKeyboard.Focus();
break;
case "albumList":
this.albumList.Focus();
break;
case "detailList":
this.detailList.Focus();
break;
case
"mainList":
this.mainList.Focus();
break;
case "sideList":
this.sideList.Focus();
break;
}
}
//the one in navigation page
public override void DisplayPage(ref frmMain myForm)
{
//handle events
frmMain with_1 = myForm;
with_1.HideControls();
with_1.SetUpFullListView();
with_1.listNavigation.DataSource = navArray;
with_1.listNavigation.Visible = true;
with_1.listNavigation.RightSelect = true;
with_1.listNavigation.Focus();
base.DisplayPage(ref
myForm);
}
//the one in Home page
public override void DisplayPage(ref frmMain myForm)
{
base.DisplayPage(ref myForm);
myForm.wmp.Visible = true;
myForm.SetUpHomeView();
}
//This is where i think it goes wrong because i have to create a new
homepage to call HomePage_MainListSelected
private void mainList_Selected(string sSelected, object Data)
{
Sounds.PlaySelectSound();
if (MainListSelectedEvent != null)
{
// frmMain tmp = this.theForm;
HomePage hp = new HomePage();
hp.HomePage_MainListSelected(sSelected, Data);
}
}
public void HomePage_MainListSelected(string sSelected, object Data)
{
MusicXP.Page page2;
Debug.WriteLine("HomePage_MainListSelected");
System.Diagnostics.Process proc;
frmMain myForm;
switch (sSelected)
{
case "Browse Artists":
page2 = new ArtistListing();
myForm = this.theForm;
this.SavePageState(ref this.theForm); //
<-----------this is where this.theForm is null and im not sure why?
this.theForm.history.Push(this);
Debug.WriteLine("HomePage Push");
page2.DisplayPage(ref myForm);
break;
case "Browse All Albums":
page2 = new AlbumListPage();
myForm = this.theForm;
this.SavePageState(ref myForm);
this.theForm.history.Push(this);
Debug.WriteLine("HomePage Push");
page2.DisplayPage(ref myForm);
break;
//..........................more here but you get the
idea
}
}
Ok i know thats really long but if anyone could help i would really
appreaciate it.
thank you very much
Bryan.