pborawski

C# obsluga myszki / rysowanie w oknie.

Mar 25th, 2012
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.20 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. namespace WindowsFormsApplication1
  10. {
  11.     public partial class Form1 : Form
  12.     {
  13.         private int x, y;
  14.         private bool rysuj;
  15.  
  16.  
  17.         private void mysz_wcisnieta(Object Sender, MouseEventArgs e)
  18.         {
  19.  
  20.             rysuj = true;
  21.             x = e.X;
  22.             y = e.Y;
  23.  
  24.         }
  25.         private void mysz_niewcisnieta(Object Sender, MouseEventArgs e)
  26.         {
  27.  
  28.             rysuj = false;
  29.         }
  30.         public Form1()
  31.         {
  32.  
  33.             MouseDown += new MouseEventHandler(mysz_wcisnieta);
  34.             MouseUp += new MouseEventHandler(mysz_niewcisnieta);
  35.             MouseMove += new MouseEventHandler(delegate(Object Sender, MouseEventArgs e)
  36.             {
  37.                 if (rysuj == true)
  38.                 {
  39.                     Graphics g = CreateGraphics();
  40.                     g.DrawLine(Pens.Blue, x, y, e.X, e.Y);
  41.                     x = e.X;
  42.                     y = e.Y;
  43.                 }
  44.             });
  45.             InitializeComponent();
  46.         }
  47.        
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment