
MickParadiseLost
|
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Drawing.Imaging;
namespace Dessin
{
/// <summary>
/// Description résumée de Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.OpenFileDialog openFileDialog1;
private System.Windows.Forms.MainMenu mainMenu1;
private Image
monImage;
// image à afficher
private bool okImage =
false;
// image chargée ?
private
Pen
_pen = null;
private System.Windows.Forms.SaveFileDialog saveFileDialog1;
private TD.SandBar.SandBarManager sandBarManager1;
private TD.SandBar.ToolBarContainer leftSandBarDock;
private TD.SandBar.ToolBarContainer rightSandBarDock;
private TD.SandBar.ToolBarContainer bottomSandBarDock;
private TD.SandBar.ToolBarContainer topSandBarDock;
private TD.SandBar.MenuBarItem menuBarItem1;
private TD.SandBar.MenuBarItem menuBarItem2;
private TD.SandBar.MenuBarItem menuBarItem3;
private TD.SandBar.MenuBarItem menuBarItem4;
private TD.SandBar.MenuBarItem menuBarItem5;
private TD.SandBar.MenuButtonItem mnuOpen;
private TD.SandBar.MenuButtonItem mnuSave;
private TD.SandBar.MenuButtonItem mnuQuit;
private TD.SandBar.MenuButtonItem mnuStretch;
private TD.SandBar.MenuButtonItem mnuAutosize;
private TD.SandBar.MenuButtonItem menuButtonItem1;
private TD.SandBar.MenuButtonItem Zoom;
private TD.SandBar.MenuButtonItem z1;
private TD.SandBar.MenuButtonItem z2;
private TD.SandBar.MenuButtonItem z3;
private TD.SandBar.MenuButtonItem Z4;
private TD.SandBar.MenuButtonItem menuButtonItem2;
private TD.SandBar.MenuButtonItem menuButtonItem3;
private TD.SandBar.MenuButtonItem menuButtonItem4;
private TD.SandBar.LabelItem lbOutils;
private System.Windows.Forms.PictureBox pb_dessin;
private TD.SandBar.MenuBar menu;
private TD.SandBar.MenuBarItem Fichier;
private TD.SandBar.MenuBarItem Affichage;
private TD.SandBar.MenuBarItem Aide;
private TD.SandBar.ToolBar tbOutils;
private TD.SandBar.ButtonItem btPinceau;
private TD.SandBar.ButtonItem btTexte;
private TD.SandBar.ButtonItem btGomme;
private TD.SandBar.ToolBar toolBar1;
private TD.SandBar.ButtonItem buttonItem1;
private TD.SandBar.ComboBoxItem comboBoxItem1;
private System.Windows.Forms.ColorDialog paletteCouleur;
private System.Windows.Forms.Label lblColor;
private
System.Windows.Forms.StatusBar
statusBar;
/// <summary>
/// Variable nécessaire au concepteur.
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Requis pour la prise en charge du Concepteur Windows Forms
//
InitializeComponent();
//
// TODO :
ajoutez le code du constructeur après l'appel à InitializeComponent
//
_pen = new Pen(Color.Black);
lblColor.BackColor = Color.Black;
}
/// <summary>
/// Nettoyage des ressources utilisées.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Code généré par le Concepteur Windows Form
/// <summary>
/// Méthode requise pour la prise en charge du concepteur - ne modifiez pas
/// le contenu de cette méthode avec l'éditeur de code.
/// </summary>
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new
System.Resources.ResourceManager(typeof(Form1));
this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.pb_dessin = new System.Windows.Forms.PictureBox();
this.saveFileDialog1 = new System.Windows.Forms.SaveFileDialog();
this.sandBarManager1 = new TD.SandBar.SandBarManager();
this.leftSandBarDock = new TD.SandBar.ToolBarContainer();
this.rightSandBarDock = new TD.SandBar.ToolBarContainer();
this.bottomSandBarDock = new TD.SandBar.ToolBarContainer();
this.topSandBarDock = new TD.SandBar.ToolBarContainer();
this.menu = new TD.SandBar.MenuBar();
this.Fichier = new TD.SandBar.MenuBarItem();
this.mnuOpen = new TD.SandBar.MenuButtonItem();
this.mnuSave = new TD.SandBar.MenuButtonItem();
this.mnuQuit = new TD.SandBar.MenuButtonItem();
this.Affichage = new TD.SandBar.MenuBarItem();
this.mnuStretch = new TD.SandBar.MenuButtonItem();
this.mnuAutosize = new TD.SandBar.MenuButtonItem();
this.Zoom = new TD.SandBar.MenuButtonItem();
this.z1 = new TD.SandBar.MenuButtonItem();
this.z2 = new TD.SandBar.MenuButtonItem();
this.z3 = new TD.SandBar.MenuButtonItem();
this.Z4 = new TD.SandBar.MenuButtonItem();
this.menuButtonItem2 = new TD.SandBar.MenuButtonItem();
this.menuButtonItem3 = new TD.SandBar.MenuButtonItem();
this.menuButtonItem4 = new TD.SandBar.MenuButtonItem();
this.Aide = new TD.SandBar.MenuBarItem();
this.menuButtonItem1 = new TD.SandBar.MenuButtonItem();
this.tbOutils = new TD.SandBar.ToolBar();
this.lbOutils = new TD.SandBar.LabelItem();
this.btPinceau = new TD.SandBar.ButtonItem();
this.btTexte = new TD.SandBar.ButtonItem();
this.btGomme = new TD.SandBar.ButtonItem();
this.menuBarItem1 = new TD.SandBar.MenuBarItem();
this.menuBarItem2 = new TD.SandBar.MenuBarItem();
this.menuBarItem3 = new TD.SandBar.MenuBarItem();
this.menuBarItem4 = new TD.SandBar.MenuBarItem();
this.menuBarItem5 = new TD.SandBar.MenuBarItem();
this.toolBar1 = new TD.SandBar.ToolBar();
this.buttonItem1 = new TD.SandBar.ButtonItem();
this.comboBoxItem1 = new TD.SandBar.ComboBoxItem();
this.paletteCouleur = new System.Windows.Forms.ColorDialog();
this.lblColor = new System.Windows.Forms.Label();
this.statusBar = new System.Windows.Forms.StatusBar();
this.topSandBarDock.SuspendLayout();
this.SuspendLayout();
//
// pb_dessin
//
this.pb_dessin.BackColor = System.Drawing.SystemColors.ControlDarkDark;
this.pb_dessin.Dock = System.Windows.Forms.DockStyle.Fill;
this.pb_dessin.Location = new System.Drawing.Point(0, 76);
this.pb_dessin.Name = "pb_dessin";
this.pb_dessin.SizeMode =
System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.pb_dessin.TabIndex = 0;
this.pb_dessin.TabStop = false;
this.pb_dessin.MouseUp += new
System.Windows.Forms.MouseEventHandler(this.pb_dessin_MouseUp);
this.pb_dessin.MouseMove += new
System.Windows.Forms.MouseEventHandler(this.pb_dessin_MouseMove);
this.pb_dessin.MouseDown += new
System.Windows.Forms.MouseEventHandler(this.pb_dessin_MouseDown);
//
// sandBarManager1
//
this.sandBarManager1.OwnerForm = this;
//
// leftSandBarDock
//
this.leftSandBarDock.Dock = System.Windows.Forms.DockStyle.Left;
this.leftSandBarDock.Guid = new
System.Guid("e5ad2306-1eac-45ae-afb7-71c506f0dbc0");
this.leftSandBarDock.Location = new System.Drawing.Point(0, 76);
this.leftSandBarDock.Manager = this.sandBarManager1;
this.leftSandBarDock.Name = "leftSandBarDock";
this.leftSandBarDock.Size = new System.Drawing.Size(0, 210);
this.leftSandBarDock.TabIndex = 1;
//
// rightSandBarDock
//
this.rightSandBarDock.Dock = System.Windows.Forms.DockStyle.Right;
this.rightSandBarDock.Guid = new
System.Guid("5bea5e1c-2d2d-4ef0-8d42-67ba704f1320");
this.rightSandBarDock.Location = new System.Drawing.Point(432, 76);
this.rightSandBarDock.Manager = this.sandBarManager1;
this.rightSandBarDock.Name = "rightSandBarDock";
this.rightSandBarDock.Size = new System.Drawing.Size(0, 210);
this.rightSandBarDock.TabIndex = 2;
//
// bottomSandBarDock
//
this.bottomSandBarDock.Dock = System.Windows.Forms.DockStyle.Bottom;
this.bottomSandBarDock.Guid = new
System.Guid("d6e52537-5505-4458-8789-0aaedca07460");
this.bottomSandBarDock.Location = new System.Drawing.Point(0, 286);
this.bottomSandBarDock.Manager = this.sandBarManager1;
this.bottomSandBarDock.Name = "bottomSandBarDock";
this.bottomSandBarDock.Size = new System.Drawing.Size(432, 0);
this.bottomSandBarDock.TabIndex = 3;
//
// topSandBarDock
//
this.topSandBarDock.Controls.Add(this.menu);
this.topSandBarDock.Controls.Add(this.tbOutils);
this.topSandBarDock.Controls.Add(this.toolBar1);
this.topSandBarDock.Dock = System.Windows.Forms.DockStyle.Top;
this.topSandBarDock.Guid = new
System.Guid("35b2cd93-17ce-4fa2-b0a2-0250a002fe13");
this.topSandBarDock.Location = new System.Drawing.Point(0, 0);
this.topSandBarDock.Manager = this.sandBarManager1;
this.topSandBarDock.Name = "topSandBarDock";
this.topSandBarDock.Size = new System.Drawing.Size(432, 76);
this.topSandBarDock.TabIndex = 4;
//
// menu
//
this.menu.Guid
= new System.Guid("ba338c31-0e25-482a-adfc-29595dc086a8");
this.menu.Items.AddRange(new TD.SandBar.ToolbarItemBase[] {
this.Fichier,
this.Affichage,
this.Aide});
this.menu.Location = new System.Drawing.Point(2, 0);
this.menu.Movable = false;
this.menu.Name = "menu";
this.menu.OwnerForm = this;
this.menu.Size = new System.Drawing.Size(430, 24);
this.menu.TabIndex = 0;
this.menu.Text = "menuBar1";
//
// Fichier
//
this.Fichier.Items.AddRange(new TD.SandBar.ToolbarItemBase[] {
this.mnuOpen,
this.mnuSave,
this.mnuQuit});
this.Fichier.Text = "&Fichier";
//
// mnuOpen
//
this.mnuOpen.Text = "&Ouvrir...";
this.mnuOpen.Activate += new System.EventHandler(this.mnuOpen_Click);
//
// mnuSave
//
this.mnuSave.Text = "&Enregistrer sous...";
this.mnuSave.Activate += new System.EventHandler(this.mnuSave_Click);
//
// mnuQuit
//
this.mnuQuit.BeginGroup = true;
this.mnuQuit.Text = "&Quitter";
this.mnuQuit.Activate += new System.EventHandler(this.mnuQuit_Click);
//
// Affichage
//
this.Affichage.Items.AddRange(new TD.SandBar.ToolbarItemBase[] {
this.mnuStretch,
this.mnuAutosize,
this.Zoom});
this.Affichage.Text = "&Affichage";
//
// mnuStretch
//
this.mnuStretch.Text = "Etiré";
this.mnuStretch.Activate += new
System.EventHandler(this.mnuStretch_Click);
//
// mnuAutosize
//
this.mnuAutosize.Checked = true;
this.mnuAutosize.Text = "Taille réelle";
this.mnuAutosize.Activate += new
System.EventHandler(this.mnuAutosize_Click);
//
// Zoom
//
this.Zoom.BeginGroup = true;
this.Zoom.Items.AddRange(new TD.SandBar.ToolbarItemBase[] {
this.z1,
this.z2,
this.z3,
this.Z4,
this.menuButtonItem2,
this.menuButtonItem3,
this.menuButtonItem4});
this.Zoom.Text = "Zoom";
//
// z1
//
this.z1.Text = "100%";
//
// z2
//
this.z2.Text = "75%";
//
// z3
//
this.z3.Text = "50%";
//
// Z4
//
this.Z4.Text = "25%";
//
// menuButtonItem2
//
this.menuButtonItem2.BeginGroup = true;
this.menuButtonItem2.Text = "150%";
//
// menuButtonItem3
//
this.menuButtonItem3.Text = "200%";
//
// menuButtonItem4
//
this.menuButtonItem4.Text = "300%";
//
// Aide
//
this.Aide.Items.AddRange(new TD.SandBar.ToolbarItemBase[] {
this.menuButtonItem1});
this.Aide.Text = "?";
//
// menuButtonItem1
//
this.menuButtonItem1.Text = "A propos...";
this.menuButtonItem1.Activate += new
System.EventHandler(this.menuButtonItem1_Activate);
//
// tbOutils
//
this.tbOutils.AddRemoveButtonsVisible = false;
this.tbOutils.Closable = false;
this.tbOutils.DockLine = 1;
this.tbOutils.DrawActionsButton = false;
this.tbOutils.Guid = new
System.Guid("241eac44-1989-4a8d-9656-02890ee8c704");
this.tbOutils.Items.AddRange(new TD.SandBar.ToolbarItemBase[] {
this.lbOutils,
this.btPinceau,
this.btTexte,
this.btGomme});
this.tbOutils.Location = new System.Drawing.Point(2, 24);
this.tbOutils.Movable = false;
this.tbOutils.Name = "tbOutils";
this.tbOutils.Overflow = TD.SandBar.ToolBarOverflow.Wrap;
this.tbOutils.Resizable = false;
this.tbOutils.Size = new System.Drawing.Size(121, 26);
this.tbOutils.TabIndex = 2;
this.tbOutils.Text = "toolBar1";
//
// lbOutils
//
this.lbOutils.Text = "Outils :";
//
// btPinceau
//
this.btPinceau.Image =
((System.Drawing.Image)(resources.GetObject("btPinceau.Image")));
this.btPinceau.Activate += new
System.EventHandler(this.btPinceau_Activate);
//
// btTexte
//
this.btTexte.Image =
((System.Drawing.Image)(resources.GetObject("btTexte.Image")));
//
// btGomme
//
this.btGomme.Image =
((System.Drawing.Image)(resources.GetObject("btGomme.Image")));
//
// menuBarItem1
//
this.menuBarItem1.Text = "&File";
//
// menuBarItem2
//
this.menuBarItem2.Text = "&Edit";
//
// menuBarItem3
//
this.menuBarItem3.Text = "&View";
//
// menuBarItem4
//
this.menuBarItem4.MdiWindowList = true;
this.menuBarItem4.Text = "&Window";
//
// menuBarItem5
//
this.menuBarItem5.Text = "&Help";
//
// toolBar1
//
this.toolBar1.DockLine = 2;
this.toolBar1.Guid = new
System.Guid("34bc7edb-3e4a-4a9a-b938-f94f59ef5538");
this.toolBar1.Items.AddRange(new TD.SandBar.ToolbarItemBase[] {
this.buttonItem1,
this.comboBoxItem1});
this.toolBar1.Location = new System.Drawing.Point(2, 50);
this.toolBar1.Name = "toolBar1";
this.toolBar1.Size = new System.Drawing.Size(100, 26);
this.toolBar1.TabIndex = 2;
this.toolBar1.Text = "Outils";
this.toolBar1.Visible = false;
//
// buttonItem1
//
this.buttonItem1.Image =
((System.Drawing.Image)(resources.GetObject("buttonItem1.Image")));
this.buttonItem1.Activate += new
System.EventHandler(this.buttonItem1_Activate);
//
// comboBoxItem1
//
this.comboBoxItem1.ControlText = "1";
this.comboBoxItem1.Items.AddRange(new object[] {
"1",
"2",
"3",
"4"});
this.comboBoxItem1.MinimumControlWidth = 50;
this.comboBoxItem1.Padding.Bottom = 0;
this.comboBoxItem1.Padding.Left = 1;
this.comboBoxItem1.Padding.Right = 1;
this.comboBoxItem1.Padding.Top = 0;
this.comboBoxItem1.Tag = "";
//
// paletteCouleur
//
this.paletteCouleur.FullOpen = true;
//
// lblColor
//
this.lblColor.Anchor =
((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom
| System.Windows.Forms.AnchorStyles.Left)));
this.lblColor.BackColor = System.Drawing.SystemColors.ActiveCaption;
this.lblColor.BorderStyle =
System.Windows.Forms.BorderStyle.FixedSingle;
this.lblColor.Location = new System.Drawing.Point(95, 273);
this.lblColor.Name = "lblColor";
this.lblColor.Size = new System.Drawing.Size(41, 10);
this.lblColor.TabIndex = 5;
//
// statusBar
//
this.statusBar.Location = new System.Drawing.Point(0, 270);
this.statusBar.Name = "statusBar";
this.statusBar.Size = new System.Drawing.Size(432, 16);
this.statusBar.TabIndex = 6;
this.statusBar.Text = "Couleur en cours :";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.AutoScroll = true;
this.BackColor = System.Drawing.SystemColors.ControlDarkDark;
this.ClientSize = new System.Drawing.Size(432, 286);
this.Controls.Add(this.lblColor);
this.Controls.Add(this.statusBar);
this.Controls.Add(this.pb_dessin);
this.Controls.Add(this.leftSandBarDock);
this.Controls.Add(this.rightSandBarDock);
this.Controls.Add(this.bottomSandBarDock);
this.Controls.Add(this.topSandBarDock);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Menu = this.mainMenu1;
this.Name = "Form1";
this.StartPosition =
System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "Dessin";
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
this.topSandBarDock.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// Point d'entrée principal de l'application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private bool _mustDraw;
private Point _previousPosition;
private Graphics _pbGraphics;
Pen crayon=new Pen(Brushes.Black);
private void mnuQuit_Click(object sender, System.EventArgs e)
{
Close();
}
private void mnuOpen_Click(object sender, System.EventArgs e)
{
openFileDialog1.Filter = "Toutes les
images|*.bmp;*.gif;*.jpg;*.ico;*.emf,*.wmf|Fichiers bitmap
(*.bmp;*.gif;*.jpg;*.ico)|*.bmp;*.gif;*.jpg;*.ico|Fichiers Metafile
(*.emf;*.wmf)|*.emf;*.wmf";
// string filter = openFileDialog1.Filter;
openFileDialog1.InitialDirectory = Environment.CurrentDirectory;
openFileDialog1.Title = "Charger une image";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
okImage =
true;
// une image est chargée
monImage = Image.FromFile(openFileDialog1.FileName);
if (pb_dessin.SizeMode ==
PictureBoxSizeMode.StretchImage) // adaptation du mode
d'affichage
{
pb_dessin.Width = this.Width;
pb_dessin.Height = this.Height;
}
else
{
pb_dessin.Width = monImage.Width;
pb_dessin.Height = monImage.Height;
}
pb_dessin.Image =
monImage;
// affichage
}
}
private void mnuStretch_Click(object sender, System.EventArgs e)
{
if (okImage)
{
pb_dessin.SizeMode = PictureBoxSizeMode.StretchImage;
pb_dessin.Size =
this.ClientSize; // taille de la fenêtre
(surface client)
mnuStretch.Checked = true;
mnuAutosize.Checked = !mnuStretch.Checked;
}
}
private void mnuAutosize_Click(object sender, System.EventArgs e)
{
if (okImage)
{
pb_dessin.SizeMode = PictureBoxSizeMode.AutoSize;
pb_dessin.Width = monImage.Width; // taille de l'image
pb_dessin.Height = monImage.Height;
mnuAutosize.Checked = true;
mnuStretch.Checked = !mnuAutosize.Checked;
}
}
private void mnuSave_Click(object sender, System.EventArgs e)
{
saveFileDialog1.Filter = "Fichiers bitmap (*.bmp;*.gif;*.jpg)|*.bmp;*.gif;*.jpg";
saveFileDialog1.InitialDirectory = Environment.CurrentDirectory;
saveFileDialog1.Title = "Enregistrer l'image";
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
string extension =
saveFileDialog1.FileName.Substring (saveFileDialog1.FileName.Length -
3, 3);
if (extension == "bmp")
monImage.Save(saveFileDialog1.FileName, ImageFormat.Bmp);
if (extension == "jpg")
monImage.Save(saveFileDialog1.FileName, ImageFormat.Jpeg);
if (extension == "gif")
monImage.Save(saveFileDialog1.FileName, ImageFormat.Gif);
}
}
private void pb_dessin_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
if ( e.Button == MouseButtons.Left)
{
this._mustDraw = true;
}
}
private void pb_dessin_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
if ( e.Button == MouseButtons.Left)
{
this._mustDraw = false;
this._previousPosition = Point.Empty;
}
}
private void pb_dessin_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
if (btPinceau.Checked)
{
if (this._mustDraw)
{
// initilisation du Graphics
if ( this._pbGraphics == null )
{
//this._pbGraphics = this.pb_dessin.CreateGraphics();
this._pbGraphics = Graphics.FromImage(pb_dessin.Image);
this.pb_dessin.Refresh();
}
Point currentPosition = new
Point(e.X, e.Y);
// dessin
if ( this._previousPosition ==
Point.Empty )
{
this._previousPosition = currentPosition;
}
this._pbGraphics.DrawLine(Pens.Black, this._previousPosition,
currentPosition);
this._previousPosition =
currentPosition;
}
}
}
private void menuButtonItem1_Activate(object sender, System.EventArgs e)
{
apropos
apropos = new apropos();
apropos.Show();
}
private void buttonItem1_Activate(object sender, System.EventArgs e)
{
//couleur
originale
if (paletteCouleur.ShowDialog() == DialogResult.OK)
{
//assignation de la nouvelle couleur
_pen.Color = paletteCouleur.Color;
lblColor.BackColor = _pen.Color;
crayon=new Pen(paletteCouleur.Color);
}
}
private void btPinceau_Activate(object sender, System.EventArgs e)
{
btPinceau.Checked = true;
toolBar1.Visible = true;
}
}
}
Non, toujours pas. Peut etre que j'ai mis un truc qui fallait pas dans mon code?
|