Learn the fundamentals of Angular 2, a JavaScript framework for developing dynamic single page applications.
private void GetCast(int id)
{
using (var context = new MoviesEntities())
{
var Movies = context.movielinkpersons.Where(p => p.movieId == id).ToList();
int i = 1;
foreach(var person in Movies)
{
string Thumb = "";
if (person.person.profile_path == "/JohnWayneBig.png")
{
Thumb = ImgPath + "JohnWayneSml.png";
BigPicturePath = ImgPath + "JohnWayneBig.png";
}
else
{
Thumb = ImgURL + "w45" + person.person.profile_path;
BigPicturePath = ImgURL + "original" + person.person.profile_path;
}
var picture = new PictureBox
{
Name = "pictureBox" + i.ToString(),
Size = new Size(45, 70),
};
picture.Tag = BigPicturePath;
picture.MouseHover += ThumbPictureBox_MouseHover;
picture.LoadAsync(Thumb);
flowLayoutPanel1.Controls.Add(picture);
i++;
}
}
}
private void ThumbPictureBox_MouseHover(object sender, EventArgs e)
{
//BigPicturePath = this.Tag.ToString();
if (BigPicturePath != null)
{
string Orientation = "P";
FilmsDB.PictureForm frm = new PictureForm(Orientation);
frm.SetValues(BigPicturePath);
frm.ShowDialog();
}
}
Do more with
public class ActorBox : Panel
{
public ActorObject Actor { get; set; }
private PictureBox pbPhoto { get; set; }
public string ThumbPhotoPath { get; set; }
public string FullPhotoPath { get; set; }
public ActorBox(ActorObject actor)
{
Actor = actor;
ThumbPhotoPath = "...";
FullPhotoPath = "...";
pbPhoto = new PictureBox() { ... };
pbPhoto.MouseHover += ThumbPictureBox_MouseHover
this.Controls.Add(pbPhoto);
pbPhoto.LoadAsync(ThumbPhotoPath);
}
private void ThumbPictureBox_MouseHover(object sender, EventArgs e)
{
if (FullPhotoPath != null)
{
string Orientation = "P";
FilmsDB.PictureForm frm = new PictureForm(Orientation);
frm.SetValues(FullPhotoPath);
frm.ShowDialog();
}
}
}
foreach(var person in Movies)
{
var actorBox = new ActorBox(person);
flowLayoutPanel1.Controls.Add(actorBox);
}
private void ThumbPictureBox_MouseHover(object sender, EventArgs e)
{
string bigPicturePath = ((PictureBox)sender).Tag.ToString();
if (bigPicturePath != null)
{
string Orientation = "P";
FilmsDB.PictureForm frm = new PictureForm(Orientation);
frm.SetValues(bigPicturePath);
frm.ShowDialog();
}
}
namespace FilmsDB
{
public partial class ActorBox : UserControl
{
...existing code...
private void FilterBTN_Click(object sender, EventArgs e)
{
// STEP 2: Raise your new "OnFilterClick" event for anyone
// who might be listening/subscribing to this event, and pass
// the current ActorBox (this) as the sender, and
// ActorNameLbl.Text as the string.
OnFilterClick?.Invoke(this, ActorNameLbl.Text);
}
// STEP 1: Create a new event that passes a string
public event EventHandler<string> OnFilterClick;
}
}
private void GetCast(int id)
{
using (var context = new MoviesEntities())
{
var Movies = context.movielinkpersons.Where(p => p.movieId == id).OrderBy(mp => mp.role) .ToList();
foreach(var movielinkperson in Movies)
{
var person = movielinkperson.person;
var actorBox = new ActorBox(person);
actorBox.OnFilterClick += ActorBox_OnFilterClick; // <===================
flowLayoutPanel1.Controls.Add(actorBox);
}
}
}
...
private void ActorBox_OnFilterClick(object sender, string actorName)
{
var actorBox = (ActorBox)sender;
/*
Add whatever code you want into this event handler - you have access to
both the actorName string and ALSO the instance of the ActorBox
where the filter button was clicked.
*/
}
private string _myField;
public string MyField
{
get { return _myField; }
set
{
if(_myField != value)
{
_myField = value;
NotifyPropertyChanged();
}
}
}
Premium Content
You need an Expert Office subscription to comment.Start Free Trial