Some1help me.... so how to save the pictures i drew to jpg if possible load and edit a jpg file.

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 @try
{
    public partial class Form1 : Form
    {
        private Graphics picture;
        private Color paint;    
        public Form1()
        {
            InitializeComponent();
            paint = Color.Green;
        }

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

        private void panel1_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left) 
            {
                picture.FillEllipse(new SolidBrush(paint), e.X, e.Y, 50, 50);
            }
            else if (e.Button == MouseButtons.Right)
            {
                picture.FillEllipse(new SolidBrush(Color.White), e.X, e.Y, 50, 50);
            }
            
        }

        private void panel1_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
               
                picture.FillEllipse(new SolidBrush(paint), e.X, e.Y, 50, 50);
            }
            else if (e.Button == MouseButtons.Right)
            {
              
                picture.FillEllipse(new SolidBrush(Color.White), e.X, e.Y, 50, 50);
            }
        }

        private void panel1_Paint(object sender, PaintEventArgs e)
        {
            picture = panel1.CreateGraphics();
        }
    }
}

So anyone can really please enlighten me? and not give me a damn diy code

Edited 4 Years Ago by Lowchernhwee: untidy.

Some1help me.... so how to save the pictures i drew to jpg if possible load and edit a jpg file.

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 @try
{
    public partial class Form1 : Form
    {
        private Graphics picture;
        private Color paint;    
        public Form1()
        {
            InitializeComponent();
            paint = Color.Green;
        }

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

        private void panel1_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left) 
            {
                picture.FillEllipse(new SolidBrush(paint), e.X, e.Y, 50, 50);
            }
            else if (e.Button == MouseButtons.Right)
            {
                picture.FillEllipse(new SolidBrush(Color.White), e.X, e.Y, 50, 50);
            }
            
        }

        private void panel1_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
               
                picture.FillEllipse(new SolidBrush(paint), e.X, e.Y, 50, 50);
            }
            else if (e.Button == MouseButtons.Right)
            {
              
                picture.FillEllipse(new SolidBrush(Color.White), e.X, e.Y, 50, 50);
            }
        }

        private void panel1_Paint(object sender, PaintEventArgs e)
        {
            picture = panel1.CreateGraphics();
        }
    }
}

So anyone can really please enlighten me? and not give me a damn diy code

People around here like to see effort put in. That 'damn diy code' may seem hard at first, but you will probably learn something from it and become a more proficient programmer.

A simple google search has your answer.

.... if i already know how to do, then i would not post it here in the 1st place.... And be4 i post it, i aldy google it, which is hard for me.... HELP!

.... if i already know how to do, then i would not post it here in the 1st place.... And be4 i post it, i aldy google it, which is hard for me.... HELP!

Programming is hard by design. If you don't like that fact then you probably won't like programming. That link I gave you has the full code you need by the way...

Why do you use CreatGraphics on line 56 of your code?
The PaintEventArgs parameter of your paint handler gives you one for free! It is called e.Graphics.

Edited 4 Years Ago by ddanbe: typo

thx ddanbe......
i searched from web on how to save to jpg... it works but i want it to be free drawing and not fix....
here is the code

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 WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        private Graphics g;
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog();

            saveFileDialog.DefaultExt = "bmp";
            saveFileDialog.Filter = "Bitmap files|*.bmp";
            if (saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                int width = panel1.Width;
                int height = panel1.Height;
                Rectangle rec = new Rectangle(0, 0, width, height);
                Bitmap bitMap = new Bitmap(panel1.Width, panel1.Height);
                panel1.DrawToBitmap(bitMap, new Rectangle(0, 0, panel1.Width, panel1.Height));
                bitMap.Save(saveFileDialog.FileName,
                System.Drawing.Imaging.ImageFormat.Jpeg);
            }    
        }

        private void button2_Click(object sender, EventArgs e)
        {
            
            g.DrawLine(new Pen(Brushes.Blue), new Point(0, 0), new Point(50, 50));
        }
        
        private void button3_Click(object sender, EventArgs e)
        {

            
        }

        private void panel1_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            //g.DrawLine(new Pen(Brushes.Blue), new Point(0, 0), new Point(50, 50));//works
        }

        private void panel1_MouseDown(object sender, MouseEventArgs e)
        {
            g.DrawLine(new Pen(Brushes.Blue), new Point(0, 0), new Point(50, 50));//problem
        }
    }
}

as u see the under panel1_MouseDown, got a damn big problem... NEED HELP!!!

Edited 4 Years Ago by Lowchernhwee: n/a

You don't have a graphics object within the scope of that event. You will need to save the coordinates of the mouse clicks, then render these coordinates in the panel1_paint event. A list<point> will work for this.

I'm not going to spoon feed it to you, but:

List<point> myPoints = new List<point>();

void myClickEvent(object Sender, MouseEventArgs e)
{
   myPoints.Add(new Point(e.X, e.Y));
}

void myPaintEvent(object Sender, PaintEventArgs e)
{
   foreach (Point p in myPoints)
      foreach (Point pp in myPoints)
         if (p != pp)         
             e.Graphics.Drawline(somePen, p, pp);
}

This will take each point you click on (as long as they're OnClick event subscribes to this method) and load it to a list.

Whatever paint event you subscribe to the myPaintEvent method (let's say it's a panel control) will iterate through all of the points in the list and draw a line between them, interconnecting all of them. This spirographic effect is probably not what you are looking for, so you may have to do a bit of thinking to decide which way you want to use these points and draw something with them.

Edited 4 Years Ago by skatamatic: n/a

This article has been dead for over six months. Start a new discussion instead.