Advertisement
Luticus

C# Painter code (Visual Studio 2010, No GUI code)

May 27th, 2013
2,509
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.08 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9.  
  10. namespace Painter
  11. {
  12.     public partial class Painter : Form
  13.     {
  14.         bool shouldPaint = false;
  15.         string colorvar = "Blue";
  16.         int brushSize = 4;
  17.        
  18.         public Painter()
  19.         {
  20.             InitializeComponent();
  21.         }
  22.  
  23.         private void Painter_MouseDown(object sender, MouseEventArgs e)
  24.         {
  25.             if (e.Button == MouseButtons.Left) shouldPaint = true;
  26.         }
  27.  
  28.         private void Painter_MouseUp(object sender, MouseEventArgs e)
  29.         {
  30.             shouldPaint = false;
  31.         }
  32.  
  33.         private void Pinter_MouseClick(object sender, MouseEventArgs e)
  34.         {
  35.             if (e.Button == MouseButtons.Right)
  36.             {
  37.                 contextMenuStrip_Menu.Show(MousePosition.X, MousePosition.Y);
  38.             }
  39.         }
  40.  
  41.         private void Painter_MouseMove(object sender, MouseEventArgs e)
  42.         {
  43.             if (shouldPaint)
  44.             {
  45.                 Graphics graphics = CreateGraphics();
  46.                 graphics.FillEllipse(new SolidBrush(Color.FromName(colorvar)), e.X, e.Y, brushSize, brushSize);
  47.             }
  48.         }
  49.  
  50.         private void Menu_Click(object sender, EventArgs e)
  51.         {
  52.             ToolStripMenuItem menuItem = (ToolStripMenuItem)sender;
  53.             colorvar = menuItem.Text;
  54.             brushSize = 4;
  55.             Cursor = Cursors.Hand;
  56.             UpdateStatus();
  57.         }
  58.  
  59.         private void eraseToolStripMenuItem_Click(object sender, EventArgs e)
  60.         {
  61.             colorvar = "white";
  62.             brushSize = 15;
  63.             Cursor = Cursors.Cross;
  64.             UpdateStatus();
  65.         }
  66.  
  67.         private void UpdateStatus()
  68.         {
  69.             panel_Color.BackColor = Color.FromName(colorvar);
  70.         }
  71.  
  72.         private void clearToolStripMenuItem_click(object sender, EventArgs e)
  73.         {
  74.             Painter.ActiveForm.Refresh();
  75.         }
  76.     }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement