3 Replies - 5405 Views - Last Post: 30 October 2008 - 01:39 PM Rate Topic: -----

#1 asme  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 28-October 08

saving a background image in a Picturebox

Post icon  Posted 28 October 2008 - 11:17 AM

hey! please help me out with this problem ,, I have an assignment that i have to make a windows application form in C# in which i have to give background ,then have to draw a circle on it ,,and then have to translate it..!



BUT THe main problem is that , the position where i ll draw a circle ,,first i have to copy that background in some picturebox ,then after drawing circle there ,, hav eto translate it.. and then affter translation of circle ...Hav to paste that copied background to its original place..


Thats what i have done till now...

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace circle
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
             this.Paint += new PaintEventHandler(f1_paint);

        }

        float x = 130, y = 120, nx = 40, ny = 30;
        Graphics g1;

        private void translate()
        {          

            for (int i = 1; i <= 16; i++)
            {
                nx = x + nx;
                ny = y + ny;

                g1.DrawEllipse(new Pen(Color.Red), nx, ny, 40, 40);
                g1.FillEllipse(new SolidBrush(Color.Red), nx, ny, 40, 40);
           }
                    }
        private void f1_paint(object sender, PaintEventArgs e)
        {

            // Get Graphics Object
            Graphics g = e.Graphics;

            // Method under System.Drawing.Graphics

            g.DrawString("Translating Circle", new Font("Matisse", 20), new SolidBrush(Color.Blue), 100, 20);
            g.FillEllipse(new SolidBrush(Color.Blue), x, y, 40, 40);
            g.DrawEllipse(new Pen(Color.Blue), 130, 120, 40, 40);
           

        }


  private void button1_Click(object sender, EventArgs e)
         {
             translate();
         }



             }
}


Mod Edit: Please use code tags when posting your code. Code tags are used like so => :code:

Thanks,
PsychoCoder :)

Is This A Good Question/Topic? 0
  • +

Replies To: saving a background image in a Picturebox

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 8939
  • View blog
  • Posts: 33,521
  • Joined: 12-June 08

Re: saving a background image in a Picturebox

Posted 28 October 2008 - 11:25 AM

Can you restate the problem? That made no sense.
Was This Post Helpful? 0
  • +
  • -

#3 asme  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 28-October 08

Re: saving a background image in a Picturebox

Posted 29 October 2008 - 11:41 AM

Ok! Inshort I have to translate/move a circle on that image/background , But when that circle moves from its initial position ,the background should not be disturbed.



I tried to do this by placing a background on form , then moving circle on that background .Now the only problem is that how to save that specific area of background where circle is initially placed.Because After translating the circle ,the saved background area should be placed back to that position. So this all will give an animation look ,that an object is moved on background without disturbing background.


Is that a good practice to use picturebox ,to save that specific area of background and pasting it again to that position.Please tell me how to do that ,I dont know how to save a specific area of background in a picture box.!
Was This Post Helpful? 0
  • +
  • -

#4 gbertoli3  Icon User is offline

  • DIC at Heart + Code
  • member icon

Reputation: 40
  • View blog
  • Posts: 1,162
  • Joined: 23-June 08

Re: saving a background image in a Picturebox

Posted 30 October 2008 - 01:39 PM

I think it is updating(disturbing) the Form's Background because you are applying the drawing methods(Graphics) from the Form's Paint() Event

Try putting the drawing methods inside of a PictureBox's Paint() event.
// Get Graphics Object
Graphics g = e.Graphics;

// Method under System.Drawing.Graphics

g.DrawString("Translating Circle", new Font("Matisse", 20), new SolidBrush(Color.Blue), 100, 20);
g.FillEllipse(new SolidBrush(Color.Blue), x, y, 40, 40);
g.DrawEllipse(new Pen(Color.Blue), 130, 120, 40, 40);




Side Note:
Please put your code inside of the code tags like so: :code:


Hope this helps
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1