//Method to load or change the user's profile picture on the home panel public void loadProfilePicHome() { //Get the image from the database PicModel getImg = new PicModel(); Image target = getImg.getImage(currentUser.getUsername()); //Set it to be the image inside picBoxProfPicThumb picBoxProfPicThumb.Image = target; if (target == null) { picBoxProfPicThumb.Image = Properties.Resources.iconprofile; } }
//Button to change the user's profile picture private void btnChangeProfilePic_Click(object sender, EventArgs e) { OpenFileDialog fileSearch = new OpenFileDialog(); //Filter so the user can only select jpeg or png files fileSearch.Filter = "Images (*.JPG;*.PNG)|*.JPG;*.PNG"; //if statement that means the code will only continue if the user clicks OK and doesn't cancel the window if (fileSearch.ShowDialog() == DialogResult.OK) { //This is the path and file name. Not sure if we need it but we have it //SAFEFileName has the full path String filename = fileSearch.FileName; try { //Set image location to be the loading one picBoxProfilePic.ImageLocation = filename; //This is where we put it into the database PicModel insert = new PicModel(); //Call PicModel's insert image insert.setImage(filename, currentUser.getUsername()); //Set the parent to be the home page HomePage parent = (HomePage)this.Parent; //And call the method to change the profile pic on the home panel parent.loadProfilePicHome(); } catch (Exception IOException) { MessageBox.Show("ABORT ABORT "); Console.WriteLine("Error occured on things " + IOException); } } }