how to link picture boxes with different people in a database
Loading
how to link picture boxes with different people in a database
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Jayraj ChhayaRank #304 · 8.2K reputationPosted Mar 31, 2024, 10:30 AM EDT
To link picture boxes with different people in a database in C#, you can follow these steps:
Here's a simplified example to illustrate the concept:
// Assuming you have a Dictionary to map between picture boxes and people Dictionary pictureBoxPersonMap = new Dictionary(); // Assigning image and person to a picture box pictureBoxPersonMap[pictureBox1] = "John Doe"; pictureBoxPersonMap[pictureBox2] = "Jane Smith"; // Click event handler for a picture box pictureBox1.Click += (sender, e) => { string selectedPerson = pictureBoxPersonMap[pictureBox1]; // Use the selected person's information as needed };Naimish MakwanaRank #324 · 7.7K reputationPosted Apr 1, 2024, 12:29 AM EDT
To link picture boxes with different people in a database, you can follow these steps:
Store the Image Paths: Store the paths of the images in your database. Each person in your database should have a field that contains the path to their image1.
Create Picture Boxes: In your application, create a picture box for each person. You can do this programmatically if the number of people (and thus picture boxes) can change2.
Link Picture Boxes to Images: For each picture box, set the Image property to the image path from the database1. You can do this when you are creating the picture boxes, or afterwards if the images can change2.
Here’s a simple example in C# for a Windows Forms application:
foreach (var person in people) { PictureBox pictureBox = new PictureBox { Image = Image.FromFile(person.ImagePath), SizeMode = PictureBoxSizeMode.StretchImage, }; this.Controls.Add(pictureBox); }In this example,
peopleis a list of person objects, and each person object has anImagePathproperty that contains the path to the person’s image. ThePictureBoxobjects are added to the form’sControlscollection, which causes them to be displayed on the form.Please replace the placeholders with your actual data.
Thanks