|
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Net.Sockets;
using System.Net;
using System.Data;
namespace WindowsFormsApplication1
{
public class MyPanel : Panel
{
public static Pen p;
public string pen_color = "blue";
private bool mouse_down = false;
public static Point last_point = Point.Empty;
private Graphics g;
ArrayList pointss;
public static UdpClient client;
public MyPanel()
{
g = this.CreateGraphics();
p = new Pen(Color.FromName(pen_color));
g.Clip.MakeInfinite();
pointss = new ArrayList();
}
protected override void OnMouseDown(MouseEventArgs e)
{
mouse_down = true;
}
protected override void OnMouseUp(MouseEventArgs e)
{
mouse_down = false;
if (Form1.isDrawer)
{
string msg = "draw";
for (int i = 0; i < pointss.Count; i++)
{
Point poi = (Point)pointss[i];
msg += ("x" + poi.X + "y" + poi.Y);
}
msg += "x";
pointss.Clear();
byte[] data = Encoding.ASCII.GetBytes(msg);
if (client != null)
client.Send(data, data.Length);
}
}
protected override void OnMouseMove(MouseEventArgs e)
{
if (Form1.isDrawer)
{
if (last_point.Equals(Point.Empty))
last_point = new Point(e.X, e.Y);
if (mouse_down)
{
IntPtr hwnd = this.Handle;
using (Graphics graphics = Graphics.FromHwnd(hwnd))
{
Point pMousePos = new Point(e.X, e.Y);
graphics.DrawLine(p, pMousePos, last_point);
Console.WriteLine(pMousePos + " last " + last_point);
pointss.Add(pMousePos);
}
}
last_point = new Point(e.X, e.Y);
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.