• Advertisement
Sign in to follow this  

C# PictureBox Copy&Paste

This topic is 2929 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've implemented a little trick with the PictureBox control, where I added a context menu with "Paste" that when you click does this:
        private void pasteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (Clipboard.GetDataObject().GetDataPresent("Bitmap"))
            {
                object o = Clipboard.GetDataObject().GetData("Bitmap");
                if (o != null)
                {
                    PBox.Image = (Image)o;
                    PBox.Width = PBox.Image.Width;
                    PBox.Height = PBox.Image.Height;
                }
            }
        }
This works like a charm copy & pasting straight out of firefox. However, it doesn't copy over the alpha channel if the source is a .gif or .png or something. Is there anyway to get that data too? Right now it just converts these pixels to black (0, 0, 0, 255).

Share this post


Link to post
Share on other sites
Advertisement
nah its not a dumb question. im actually just playing around with c# for the first time, and i'm surprised at how easy it is to add all kinds of features like this. that's what i've ended up doing anyway, and since i need to load TGAs i've been planning to load from the disk from the get go

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement