Venkatesan Dinesh
asked on
PictureBox Inside panel C#/C++ windows application
I have panel that has multiple pictureboxes which are added dynamically at runtime. The pictureboxes can be moved around the panel individually or as a user defined group. I want the user to be able to drag a mouse across the screen to "define" which pictureboxes are selected.
here is the code
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog d = new OpenFileDialog();
// allow multiple selection
d.Multiselect = true;
// filter the desired file types
d.Filter = "JPG |*.jpg|PNG|*.png|BMP|*.bmp ";
// show the dialog and check if the selection was made
if (d.ShowDialog() == DialogResult.OK)
{
int n = 4;
foreach (string image in d.FileNames)
{
// create a new control
PictureBox pb = new PictureBox();
// assign the image
pb.Image = new Bitmap(image);
// stretch the image
pb.SizeMode = PictureBoxSizeMode.Stretch Image;
// set the size of the picture box
pb.Height = pb.Image.Height / 10;
pb.Width = pb.Image.Width / 10;
// add the control to the container
panel1.Controls.Add(pb);
}
}
and now my query is if i select any of the add control that should get highlight and i need to move around panel1.
now i can count how many control are there but i cant find name of the each control
sample code
MessageBox.Show(panel1.Con trols.Coun t.ToString ());
thanks in advance
here is the code
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog d = new OpenFileDialog();
// allow multiple selection
d.Multiselect = true;
// filter the desired file types
d.Filter = "JPG |*.jpg|PNG|*.png|BMP|*.bmp
// show the dialog and check if the selection was made
if (d.ShowDialog() == DialogResult.OK)
{
int n = 4;
foreach (string image in d.FileNames)
{
// create a new control
PictureBox pb = new PictureBox();
// assign the image
pb.Image = new Bitmap(image);
// stretch the image
pb.SizeMode = PictureBoxSizeMode.Stretch
// set the size of the picture box
pb.Height = pb.Image.Height / 10;
pb.Width = pb.Image.Width / 10;
// add the control to the container
panel1.Controls.Add(pb);
}
}
and now my query is if i select any of the add control that should get highlight and i need to move around panel1.
now i can count how many control are there but i cant find name of the each control
sample code
MessageBox.Show(panel1.Con
thanks in advance
now i can count how many control are there but i cant find name of the each controlYour dynamic controls don't have names because you never assigned names to them. You can assign names, but it's not actually necessary. Just collect all the "selected" controls in a List<> and update their positions using the references in it.
The pictureboxes can be moved around the panel individually or as a user defined group.Does this mean you already have it so they can be moved around?...or are you asking how to make it so you can move them around? If you want to be able to move them around individually then you'll have to wire up some events for them when you create them. This can be done with a common handler and you simply use the "sender" parameter to determine which control was the source of the event.
I want the user to be able to drag a mouse across the screen to "define" which pictureboxes are selected.So...it seems like this part is NOT done yet (since you have the word "want" in there). This is called "rubberbanding" or "rubberband selection", and is usually accomplished with ControlPaint.DrawReversibl
ASKER
best best solution... by reading i can understand, but im just a fresher can u share some code to do this, please..
code for "I want the user to be able to drag a mouse across the screen to "define" which pictureboxes are selected."
and now i can count how many control are there but i cant find name of the each control,
me already shared some coding if there is any error please let me know
code for "I want the user to be able to drag a mouse across the screen to "define" which pictureboxes are selected."
and now i can count how many control are there but i cant find name of the each control,
me already shared some coding if there is any error please let me know
This question needs an answer!
Become an EE member today
7 DAY FREE TRIALMembers can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
if PictureBox is 3rdParty class, derive a new class from PictureBox, say 'class NamedPictureBox' and define a string member 'pictureName' and a constructor that takes the string as argument. you then would create NamedPictureBox instead of PictureBox but still could use a NamedPictureBox pointer wherever a PictureBox pointer was required.
both ways would allow you to get the name of the stored picturebox by providing a GetName member function.
Sara