Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > pasting images onto a control and saving it as bitmap
 

pasting images onto a control and saving it as bitmap

Hello all,

I have my requirement as follows.
I have a windows form with 5 textboxes and 6th (to be decided). in all the 5 text boxes I will give text data and on 6th control I have to manually paste an image (and also I should be able to save that pasted image through code).
After clicking a button all the details should get saved into database. Im ready with that part of code where I will save that image into an ole column.

So what exactly I want is, what is the control I need to use for 6th control where I can paste it and which is also be able to save that image.

What I have tried till now is with rich textbox where eventhough I can able to paste my images, I couldn't able to save that image as a bmp or......
So can anybody suggest a solution for my problem

Regards,
Krishna.

satyam821  Friday, October 02, 2009 6:03 PM
Maybe this custom developed control helps.

User must right click on the panel and select paste.

You can call save method to save image to a file.

Here is the code.

    public class MyPictureBox : Panel
    {
        ContextMenuStrip cms = new ContextMenuStrip();
        public MyPictureBox()
        {
            this.BorderStyle = BorderStyle.Fixed3D;
            this.AutoSize = false;
            this.Text = "";
            cms.Items.Add(new ToolStripButton("Paste"));
            cms.Items.Add(new ToolStripButton("Clear"));
            this.ContextMenuStrip = cms;
            cms.ItemClicked += new ToolStripItemClickedEventHandler(cms_ItemClicked);
            this.BackgroundImageLayout = ImageLayout.Stretch;
        }

        void cms_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            if (e.ClickedItem.Text == "Paste")
            {
                if (Clipboard.ContainsImage())
                {
                    this.BackgroundImage = Clipboard.GetImage();
                }
            }
            else if (e.ClickedItem.Text == "Clear")
            {
                this.BackgroundImage = null;
            }
        }
        public void Save(string fileName, System.Drawing.Imaging.ImageFormat format)
        {
            if (this.BackgroundImage == null)
            {
                throw new Exception("No Image To Save");
            }
            this.BackgroundImage.Save(fileName, format);
        }
    }
Tamer Oz  Friday, October 02, 2009 8:04 PM
Hello all,

I have my requirement as follows.
I have a windows form with 5 textboxes and 6th (to be decided). in all the 5 text boxes I will give text data and on 6th control I have to manually paste an image (and also I should be able to save that pasted image through code).
After clicking a button all the details should get saved into database. Im ready with that part of code where I will save that image into an ole column.

So what exactly I want is, what is the control I need to use for 6th control where I can paste it and which is also be able to save that image.

What I have tried till now is with rich textbox where eventhough I can able to paste my images, I couldn't able to save that image as a bmp or......
So can anybody suggest a solution for my problem

Regards,
Krishna.

satyam821  Friday, October 02, 2009 6:00 PM
Maybe this custom developed control helps.

User must right click on the panel and select paste.

You can call save method to save image to a file.

Here is the code.

    public class MyPictureBox : Panel
    {
        ContextMenuStrip cms = new ContextMenuStrip();
        public MyPictureBox()
        {
            this.BorderStyle = BorderStyle.Fixed3D;
            this.AutoSize = false;
            this.Text = "";
            cms.Items.Add(new ToolStripButton("Paste"));
            cms.Items.Add(new ToolStripButton("Clear"));
            this.ContextMenuStrip = cms;
            cms.ItemClicked += new ToolStripItemClickedEventHandler(cms_ItemClicked);
            this.BackgroundImageLayout = ImageLayout.Stretch;
        }

        void cms_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            if (e.ClickedItem.Text == "Paste")
            {
                if (Clipboard.ContainsImage())
                {
                    this.BackgroundImage = Clipboard.GetImage();
                }
            }
            else if (e.ClickedItem.Text == "Clear")
            {
                this.BackgroundImage = null;
            }
        }
        public void Save(string fileName, System.Drawing.Imaging.ImageFormat format)
        {
            if (this.BackgroundImage == null)
            {
                throw new Exception("No Image To Save");
            }
            this.BackgroundImage.Save(fileName, format);
        }
    }
Tamer Oz  Friday, October 02, 2009 8:04 PM
Tamer Oz  Saturday, October 03, 2009 5:41 PM

You can use google to search for other answers

Custom Search

More Threads

• does binding source filter work on objects?
• Connect a Collection of Integers to a Collection of Strings and display the corresponding data matches
• extracting Info
• Drop Down List "blanking out" first entry
• Find select Row in datagrid
• DataGridViewComboBoxColumn problem
• Datagrid
• Dispose order
• Returning a Collection Class
• Master-Details on object data source where child is *not* a collection