add dragging
This commit is contained in:
parent
7bf20c2a12
commit
91c1faefdf
2 changed files with 39 additions and 22 deletions
4
networkPaint/MainForm.Designer.cs
generated
4
networkPaint/MainForm.Designer.cs
generated
|
@ -48,7 +48,9 @@
|
||||||
this.paintArea.Size = new System.Drawing.Size(640, 480);
|
this.paintArea.Size = new System.Drawing.Size(640, 480);
|
||||||
this.paintArea.TabIndex = 0;
|
this.paintArea.TabIndex = 0;
|
||||||
this.paintArea.TabStop = false;
|
this.paintArea.TabStop = false;
|
||||||
this.paintArea.Click += new System.EventHandler(this.paintArea_Click);
|
this.paintArea.MouseDown += new System.Windows.Forms.MouseEventHandler(this.paintArea_MouseDown);
|
||||||
|
this.paintArea.MouseMove += new System.Windows.Forms.MouseEventHandler(this.paintArea_MouseMove);
|
||||||
|
this.paintArea.MouseUp += new System.Windows.Forms.MouseEventHandler(this.paintArea_MouseUp);
|
||||||
//
|
//
|
||||||
// timer
|
// timer
|
||||||
//
|
//
|
||||||
|
|
|
@ -8,30 +8,44 @@ namespace networkPaint
|
||||||
{
|
{
|
||||||
public partial class MainForm : Form
|
public partial class MainForm : Form
|
||||||
{
|
{
|
||||||
Color color;
|
|
||||||
Random r = new Random();
|
Random r = new Random();
|
||||||
WebClient client = new WebClient();
|
WebClient client = new WebClient();
|
||||||
Bitmap bitmap;
|
Bitmap bitmap = new Bitmap(640, 480);
|
||||||
Graphics graphics;
|
Graphics graphics;
|
||||||
|
|
||||||
|
Color color;
|
||||||
string url = "http://kawaiizenbo.me/toys/networkpaint/";
|
string url = "http://kawaiizenbo.me/toys/networkpaint/";
|
||||||
|
bool dragging = false;
|
||||||
|
|
||||||
public MainForm()
|
public MainForm()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
color = intToRGB(r.Next(0, 0xFFFFFF));
|
color = intToRGB(r.Next(0, 0xFFFFFF));
|
||||||
bitmap = new Bitmap(640, 480);
|
|
||||||
paintArea.Image = bitmap;
|
paintArea.Image = bitmap;
|
||||||
graphics = Graphics.FromImage(bitmap);
|
graphics = Graphics.FromImage(bitmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void paintArea_Click(object sender, EventArgs e)
|
private void paintArea_MouseUp(object sender, MouseEventArgs e)
|
||||||
{
|
{
|
||||||
MouseEventArgs em = (MouseEventArgs)e;
|
dragging = false;
|
||||||
NameValueCollection values = new NameValueCollection();
|
}
|
||||||
values["color"] = rgbToInt(color).ToString();
|
|
||||||
values["x"] = em.X.ToString();
|
private void paintArea_MouseDown(object sender, MouseEventArgs e)
|
||||||
values["y"] = em.Y.ToString();
|
{
|
||||||
values["size"] = brushSizeNumericUpDown.Value.ToString();
|
dragging = true;
|
||||||
client.UploadValues(url + "post.php", values);
|
}
|
||||||
|
|
||||||
|
private void paintArea_MouseMove(object sender, MouseEventArgs e)
|
||||||
|
{
|
||||||
|
if (dragging)
|
||||||
|
{
|
||||||
|
NameValueCollection values = new NameValueCollection();
|
||||||
|
values["color"] = rgbToInt(color).ToString();
|
||||||
|
values["x"] = e.X.ToString();
|
||||||
|
values["y"] = e.Y.ToString();
|
||||||
|
values["size"] = brushSizeNumericUpDown.Value.ToString();
|
||||||
|
client.UploadValues(url + "post.php", values);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void MainForm_Load(object sender, EventArgs e)
|
private void MainForm_Load(object sender, EventArgs e)
|
||||||
|
@ -44,6 +58,7 @@ namespace networkPaint
|
||||||
string responseString = client.DownloadString(url + "data.ppf");
|
string responseString = client.DownloadString(url + "data.ppf");
|
||||||
client.Dispose();
|
client.Dispose();
|
||||||
if (responseString.Trim() == "") return;
|
if (responseString.Trim() == "") return;
|
||||||
|
graphics.Clear(Color.White);
|
||||||
foreach (string packet in responseString.Split(';'))
|
foreach (string packet in responseString.Split(';'))
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
@ -63,16 +78,6 @@ namespace networkPaint
|
||||||
paintArea.Image = bitmap;
|
paintArea.Image = bitmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int rgbToInt(Color color)
|
|
||||||
{
|
|
||||||
return ((255 & 0x0ff) << 24) | ((color.R & 0x0ff) << 16) | ((color.G & 0x0ff) << 8) | (color.B & 0x0ff);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Color intToRGB(int color)
|
|
||||||
{
|
|
||||||
return Color.FromArgb(0xFF, (color & 0x00FF0000) >> 16, (color & 0x0000FF00) >> 8, color & 0x000000FF);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void changeColorButton_Click(object sender, EventArgs e)
|
private void changeColorButton_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
colorDialog.ShowDialog();
|
colorDialog.ShowDialog();
|
||||||
|
@ -98,5 +103,15 @@ namespace networkPaint
|
||||||
paintArea.Image = bitmap;
|
paintArea.Image = bitmap;
|
||||||
graphics = Graphics.FromImage(bitmap);
|
graphics = Graphics.FromImage(bitmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int rgbToInt(Color color)
|
||||||
|
{
|
||||||
|
return ((255 & 0x0ff) << 24) | ((color.R & 0x0ff) << 16) | ((color.G & 0x0ff) << 8) | (color.B & 0x0ff);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Color intToRGB(int color)
|
||||||
|
{
|
||||||
|
return Color.FromArgb(0xFF, (color & 0x00FF0000) >> 16, (color & 0x0000FF00) >> 8, color & 0x000000FF);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue