1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
|
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;
using System.Drawing.Printing;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
bmp = new Bitmap(pictureBox1.Width, pictureBox1.Height);
Graphics g = Graphics.FromImage(bmp);
}
private Bitmap bmp;
private Graphics g;
int x, y, x2, y2, i;
private void closeToolStripMenuItem_Click(object sender, EventArgs e)
{
DialogResult res = MessageBox.Show("Are you sure ? ", "warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (res == DialogResult.Yes)
{
Close();
}
}
private void helpToolStripMenuItem_Click(object sender, EventArgs e)
{
MessageBox.Show("en cours de construction...", "Désolé !");
}
private void pictureBox1_MouseClick(object sender, MouseEventArgs e)
{
//Color clickedColor = pictureBox1.Image.GetPixel(e.X, e.Y);
//if (clickedColor == Color.Black)
// {
// On a cliqué sur le contour
x = e.Location.X;
y = e.Location.Y;
i++;
dessin();
// }
//else
//{
// MessageBox.Show("erreur ...", "erreur !");
//}
}
private void dessin()
{
g = pictureBox1.CreateGraphics();
g.DrawEllipse(new Pen(Color.Red, 2.0f), new Rectangle(new Point(x, y), new Size(4, 4)));
if (i % 2 != 0)
{
x2 = x;
y2 = y;
}
else
{
g.DrawLine(new Pen(Color.Red), new Point(x2, y2), new Point(x, y));
}
pictureBox1.Refresh();
}
private void openShapeToolStripMenuItem_Click(object sender, EventArgs e)
{
openFileDialog1.Title = "Choose a shape...";
openFileDialog1.DefaultExt = "jpg";
openFileDialog1.Filter = "Images file JPEG (*.jpg)|*.jpg|Bitmap file (*.bmp)|*.bmp";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
Bitmap img = new Bitmap(openFileDialog1.FileName);
pictureBox1.Image=img;
saveShapeToolStripMenuItem.Enabled = true;
}
}
private void saveShapeToolStripMenuItem_Click(object sender, EventArgs e)
{
SaveFileDialog sauve = new SaveFileDialog();
sauve.Title = "Save as ...";
sauve.InitialDirectory = "c:/";
sauve.Filter = "Jpeg files (*.jpg)|*.jpg|Bitmap files (*.bmp)|*.bmp";
if (sauve.ShowDialog() == DialogResult.OK)
{
g = pictureBox1.CreateGraphics();
pictureBox1.Image.Save(sauve.FileName);
}
}
}
} |
Partager