I have a panel where I am drawing images on button click. But on the second button click, the previously drawn image is being replaced by the new Image.

void panel_Image_Paint(object sender, PaintEventArgs e)
{
if (Clipboard.ContainsImage())
{
Point p1 = new Point(i, 0);
e.Graphics.DrawImage(Clipboard.GetImage(), p1);
i += img.Width;
}
}

I want to retain the previously drawn image in the panel, when the new image is being drawn. The clipboard is being refreshed on each button click with the new image. Any help would be highly appreciated!!!!
Thanks..

Recommended Answers

All 3 Replies

You have to post more code for sure. At first I tought that you previous image is covered by the next image but i see that you have a "dynamic" variable i witch actually makes the other images next to the previous images(you are changing the position for the drawing point if I m correct). Please post more code.

Thanks for replying!!!!
Following is my code for the above controls:

 public Form1()
        {
            InitializeComponent();
            theInkOverlay = new Microsoft.Ink.InkOverlay();
            theInkOverlay.Handle = panel_Ink.Handle;
            theInkOverlay.Enabled = true;
            panel_Image.Paint += new PaintEventHandler(panel_Image_Paint);
        }

And inside the paint event handler:

void panel_Image_Paint(object sender, PaintEventArgs e)
        {
            if (Clipboard.ContainsImage())
            {
                Point p1 = new Point(i, 0);
                e.Graphics.DrawImage(Clipboard.GetImage(), p1);
                i += img.Width;
            }
        }

And the ink is being saved on a button click:

byte[] inkData = theInkOverlay.Ink.Save(PersistenceFormat.Gif);
                MemoryStream ms = new MemoryStream(inkData);
                img = (Bitmap)Image.FromStream(ms);



                Clipboard.SetDataObject(img);
                DataFormats.Format myFormat = DataFormats.GetFormat(DataFormats.Bitmap);

                theInkOverlay.Ink.DeleteStrokes(theInkOverlay.Ink.Strokes);
                panel_Ink.Invalidate();
                panel_Image.Invalidate();

Now the problem lies in the fact that, when I am writing the 2nd word and saving it, the first word which has already been written is being replaced by the new word. What I require is that the new word should come after the previously rendered word! Any help is appreciated!!!

Maybe you should put your images into a list or a array and then loop through them once the paint event fires. Other than that I can not find any bug in that code. I suppose that you are developing something for tablets and you have a sdk equivalent to that. It is hard to reproduce the code as I don't have access to dll's. Anyways, try the list thing.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.