This is the VB version and below is the C# version. C# version works. I used (in the VB version) Dim myStream As Stream = ... and I used GetEntryAssembly() to no avail. Still get the same MessageBox to trap the Null exception that gets thrown.
Private Overloads Sub Refresh(tag As String)
Dim profile As New Profile(tag)
Dim list As List(Of Hero) = profile.HeroList
Me.panelHeroList.Controls.Clear()
Dim index As Integer = 0
For Each hero As Hero In list
btn.Location = New Point(2 + index * 110, 2)
btn.Size = New Size(108, 128)
btn.Text = [String].Format("{0} {1}( {2} )", list(index).Level, list(index).Name, list(index).ParagonLevel)
btn.ImageAlign = ContentAlignment.MiddleCenter
btn.TextAlign = ContentAlignment.BottomCenter
btn.Tag = hero
Dim myStream As Stream = Assembly.GetEntryAssembly().GetManifestResourceStream(hero.HeadPicture)
If myStream Is Nothing Then
MessageBox.Show("Image cannot be opened...Sorry", "System Error!", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
Else
Dim bmp As New Bitmap(myStream)
btn.BackgroundImage = bmp
btn.BackgroundImageLayout = ImageLayout.None
End If
AddHandler btn.Click, AddressOf btn_Click
panelHeroList.Controls.Add(btn)
System.Math.Max(System.Threading.Interlocked.Increment(index), index - 1)
Next
End Sub
It works in C# just fine, and NO I'm not switching to C#.
private void Refresh(string tag)
{
Profile profile = new Profile(tag);
List<Hero> list = profile.HeroList;
this.panelHeroList.Controls.Clear();
int index = 0;
foreach (Hero hero in list)
{
Button btn = new Button();
btn.Location = new Point(2 + index * 110, 2);
btn.Size = new Size(108, 128);
btn.Text = String.Format("{0} {1}( {2} )", list[index].Level, list[index].Name, list[index].ParagonLevel);
btn.ImageAlign = ContentAlignment.MiddleCenter;
btn.TextAlign = ContentAlignment.BottomCenter;
btn.Tag = hero;
using (Stream myStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(hero.HeadPicture))
{
Bitmap bmp = new Bitmap(myStream);
btn.BackgroundImage = bmp;
btn.BackgroundImageLayout = ImageLayout.None;
}
btn.Click += new EventHandler(btnHero_Click);
panelHeroList.Controls.Add(btn);
index++;
}
}