Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
hi all ,
I need a method where I can give it an image and in returns it gives out the very same image placed within a placeholder with a check box displayed on the placeholder ..

thnx ,
Posted
Updated 9-Nov-11 18:09pm
v2
Comments
Prerak Patel 9-Nov-11 23:59pm    
Any efforts?
iampradeepsharma 10-Nov-11 0:07am    
I m not getting how can i do that ...yeah I tried but not succeed...
sahabiswarup 10-Nov-11 0:00am    
did u try any code?
iampradeepsharma 10-Nov-11 0:07am    
may be picture box as an image holder would do , what u say ?
LanFanNinja 10-Nov-11 1:19am    
Check my solution for some suggestions.

1 solution

Sounds like you will want to create your own custom control. You will probably want to do the using the visual designer but I thought I would give an example of how you might go about doing this.

First the UserControl:
C#
class CustomPictureBoxControl : UserControl
{
    public CustomPictureBoxControl(Image img, int width, int height, Color backgroundColor)
    {
        //you could also use something like 
        //this.Width = img.Width;
        //this.Height = img.Height + checkBox.Height;
        this.Width = width;
        this.Height = height;
        this.Padding = new System.Windows.Forms.Padding(5);
        this.BackColor = backgroundColor;
        PictureBox picBox = new PictureBox();
        //you could also pass the image path as a string
        //i.e. CustomPictureBoxControl(string imgPath)
        //in that case you would use picBox.ImageLocation = imgPath;
        picBox.Image = img;
        //or any of the other PictureBoxSizeModes
        picBox.SizeMode = PictureBoxSizeMode.StretchImage;
        CheckBox checkBox = new CheckBox();
        checkBox.Checked = true;
        checkBox.Text = "Some text if any";
        checkBox.Dock = DockStyle.Top;
        picBox.Dock = DockStyle.Fill;
        this.Controls.Add(checkBox);
        this.Controls.Add(picBox);
    }
}


And an example of how you could use it:
C#
private void Form1_Load(object sender, EventArgs e)
{
    Image img = (Image)new Bitmap("test2.png");
    CustomPictureBoxControl customPicBox = CreateCustomPicBoxControl(img);
    this.Controls.Add(customPicBox);
}

private CustomPictureBoxControl CreateCustomPicBoxControl(Image img)
{
    CustomPictureBoxControl customPicBox = new CustomPictureBoxControl(img, 128, 128, Color.CornflowerBlue);
    return customPicBox;
}


Of course you will need to modify it to your needs. Hope this helps some.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900