1 using System;
2 using System.Drawing;
3 using System.Drawing.Drawing2D;
4 using System.Collections;
5 //using System.ComponentModel;
6 using System.Windows.Forms;
7 //using System.Data;
8 using System.Diagnostics ;
9 using System.Text ;
10 using System.Xml ;
11
12 using XmlBlaster ;
13
14 namespace xmlrpc
15 {
16 /// <summary>
17 /// Description résumée de Form1.
18 /// </summary>
19 public class Form1 : System.Windows.Forms.Form
20 {
21 #region Code généré par le Concepteur Windows Form
22
23 private System.Windows.Forms.GroupBox groupBox1;
24 private System.Windows.Forms.Label label2;
25 private System.Windows.Forms.TextBox server_url;
26 private System.Windows.Forms.TextBox username;
27 private System.Windows.Forms.Label label3;
28 private System.Windows.Forms.TextBox password;
29 private System.Windows.Forms.Label label4;
30 private System.Windows.Forms.RichTextBox report;
31 private System.Windows.Forms.Button connect;
32 private System.Windows.Forms.PictureBox pictureBox1;
33 private System.Windows.Forms.GroupBox groupBox2;
34 private System.Windows.Forms.ImageList imageList;
35 private System.Windows.Forms.Label label5;
36 private System.Windows.Forms.PictureBox pictureBox2;
37 private System.Windows.Forms.Button toolColor;
38 private System.Windows.Forms.RadioButton toolEllipse;
39 private System.Windows.Forms.CheckBox toolFill;
40 private System.Windows.Forms.Button toolErase;
41 private System.Windows.Forms.RadioButton toolTriangle;
42 private System.Windows.Forms.RadioButton toolRectangle;
43 private System.Windows.Forms.RadioButton toolLine;
44 private System.Windows.Forms.ColorDialog colorDialog1;
45 private System.ComponentModel.IContainer components;
46
47 /// <summary>
48 /// Méthode requise pour la prise en charge du concepteur - ne modifiez pas
49 /// le contenu de cette méthode avec l'éditeur de code.
50 /// </summary>
51 private void InitializeComponent()
52 {
53 this.components = new System.ComponentModel.Container();
54 System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
55 this.groupBox1 = new System.Windows.Forms.GroupBox();
56 this.pictureBox2 = new System.Windows.Forms.PictureBox();
57 this.connect = new System.Windows.Forms.Button();
58 this.password = new System.Windows.Forms.TextBox();
59 this.label4 = new System.Windows.Forms.Label();
60 this.username = new System.Windows.Forms.TextBox();
61 this.label3 = new System.Windows.Forms.Label();
62 this.server_url = new System.Windows.Forms.TextBox();
63 this.label2 = new System.Windows.Forms.Label();
64 this.report = new System.Windows.Forms.RichTextBox();
65 this.pictureBox1 = new System.Windows.Forms.PictureBox();
66 this.groupBox2 = new System.Windows.Forms.GroupBox();
67 this.toolColor = new System.Windows.Forms.Button();
68 this.label5 = new System.Windows.Forms.Label();
69 this.imageList = new System.Windows.Forms.ImageList(this.components);
70 this.toolEllipse = new System.Windows.Forms.RadioButton();
71 this.toolFill = new System.Windows.Forms.CheckBox();
72 this.toolErase = new System.Windows.Forms.Button();
73 this.toolTriangle = new System.Windows.Forms.RadioButton();
74 this.toolRectangle = new System.Windows.Forms.RadioButton();
75 this.toolLine = new System.Windows.Forms.RadioButton();
76 this.colorDialog1 = new System.Windows.Forms.ColorDialog();
77 this.groupBox1.SuspendLayout();
78 this.groupBox2.SuspendLayout();
79 this.SuspendLayout();
80 //
81 // groupBox1
82 //
83 this.groupBox1.Controls.Add(this.pictureBox2);
84 this.groupBox1.Controls.Add(this.connect);
85 this.groupBox1.Controls.Add(this.password);
86 this.groupBox1.Controls.Add(this.label4);
87 this.groupBox1.Controls.Add(this.username);
88 this.groupBox1.Controls.Add(this.label3);
89 this.groupBox1.Controls.Add(this.server_url);
90 this.groupBox1.Controls.Add(this.label2);
91 this.groupBox1.Dock = System.Windows.Forms.DockStyle.Top;
92 this.groupBox1.Location = new System.Drawing.Point(0, 0);
93 this.groupBox1.Name = "groupBox1";
94 this.groupBox1.Size = new System.Drawing.Size(488, 76);
95 this.groupBox1.TabIndex = 1;
96 this.groupBox1.TabStop = false;
97 this.groupBox1.Text = "connection";
98 //
99 // pictureBox2
100 //
101 this.pictureBox2.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox2.Image")));
102 this.pictureBox2.Location = new System.Drawing.Point(424, 12);
103 this.pictureBox2.Name = "pictureBox2";
104 this.pictureBox2.Size = new System.Drawing.Size(56, 52);
105 this.pictureBox2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
106 this.pictureBox2.TabIndex = 8;
107 this.pictureBox2.TabStop = false;
108 //
109 // connect
110 //
111 this.connect.Location = new System.Drawing.Point(348, 44);
112 this.connect.Name = "connect";
113 this.connect.Size = new System.Drawing.Size(64, 24);
114 this.connect.TabIndex = 6;
115 this.connect.Text = "connect";
116 this.connect.Click += new System.EventHandler(this.connect_Click);
117 //
118 // password
119 //
120 this.password.Location = new System.Drawing.Point(208, 48);
121 this.password.Name = "password";
122 this.password.Size = new System.Drawing.Size(88, 20);
123 this.password.TabIndex = 5;
124 this.password.Text = "password";
125 //
126 // label4
127 //
128 this.label4.AutoSize = true;
129 this.label4.Location = new System.Drawing.Point(160, 48);
130 this.label4.Name = "label4";
131 this.label4.Size = new System.Drawing.Size(47, 16);
132 this.label4.TabIndex = 4;
133 this.label4.Text = "pasword";
134 //
135 // username
136 //
137 this.username.Location = new System.Drawing.Point(64, 48);
138 this.username.Name = "username";
139 this.username.Size = new System.Drawing.Size(88, 20);
140 this.username.TabIndex = 3;
141 this.username.Text = "username";
142 //
143 // label3
144 //
145 this.label3.AutoSize = true;
146 this.label3.Location = new System.Drawing.Point(8, 48);
147 this.label3.Name = "label3";
148 this.label3.Size = new System.Drawing.Size(55, 16);
149 this.label3.TabIndex = 2;
150 this.label3.Text = "username";
151 //
152 // server_url
153 //
154 this.server_url.Location = new System.Drawing.Point(64, 20);
155 this.server_url.Name = "server_url";
156 this.server_url.Size = new System.Drawing.Size(348, 20);
157 this.server_url.TabIndex = 1;
158 this.server_url.Text = "server_url";
159 //
160 // label2
161 //
162 this.label2.AutoSize = true;
163 this.label2.Location = new System.Drawing.Point(8, 20);
164 this.label2.Name = "label2";
165 this.label2.Size = new System.Drawing.Size(51, 16);
166 this.label2.TabIndex = 0;
167 this.label2.Text = "server url";
168 //
169 // report
170 //
171 this.report.Dock = System.Windows.Forms.DockStyle.Bottom;
172 this.report.Location = new System.Drawing.Point(0, 333);
173 this.report.Name = "report";
174 this.report.ReadOnly = true;
175 this.report.Size = new System.Drawing.Size(488, 72);
176 this.report.TabIndex = 2;
177 this.report.Text = "report";
178 //
179 // pictureBox1
180 //
181 this.pictureBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
182 | System.Windows.Forms.AnchorStyles.Left)
183 | System.Windows.Forms.AnchorStyles.Right)));
184 this.pictureBox1.BackColor = System.Drawing.Color.White;
185 this.pictureBox1.Location = new System.Drawing.Point(60, 80);
186 this.pictureBox1.Name = "pictureBox1";
187 this.pictureBox1.Size = new System.Drawing.Size(424, 248);
188 this.pictureBox1.TabIndex = 3;
189 this.pictureBox1.TabStop = false;
190 this.pictureBox1.Resize += new System.EventHandler(this.pictureBox1_Resize);
191 this.pictureBox1.Paint += new System.Windows.Forms.PaintEventHandler(this.pictureBox1_Paint);
192 this.pictureBox1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseMove);
193 this.pictureBox1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseDown);
194 //
195 // groupBox2
196 //
197 this.groupBox2.Controls.Add(this.toolColor);
198 this.groupBox2.Controls.Add(this.label5);
199 this.groupBox2.Controls.Add(this.toolEllipse);
200 this.groupBox2.Controls.Add(this.toolFill);
201 this.groupBox2.Controls.Add(this.toolErase);
202 this.groupBox2.Controls.Add(this.toolTriangle);
203 this.groupBox2.Controls.Add(this.toolRectangle);
204 this.groupBox2.Controls.Add(this.toolLine);
205 this.groupBox2.Dock = System.Windows.Forms.DockStyle.Left;
206 this.groupBox2.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
207 this.groupBox2.Location = new System.Drawing.Point(0, 76);
208 this.groupBox2.Name = "groupBox2";
209 this.groupBox2.Size = new System.Drawing.Size(60, 257);
210 this.groupBox2.TabIndex = 16;
211 this.groupBox2.TabStop = false;
212 this.groupBox2.Text = "tools";
213 //
214 // toolColor
215 //
216 this.toolColor.BackColor = System.Drawing.Color.Black;
217 this.toolColor.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
218 this.toolColor.Location = new System.Drawing.Point(28, 192);
219 this.toolColor.Name = "toolColor";
220 this.toolColor.Size = new System.Drawing.Size(20, 20);
221 this.toolColor.TabIndex = 22;
222 this.toolColor.Click += new System.EventHandler(this.toolColor_Click);
223 //
224 // label5
225 //
226 this.label5.ImageIndex = 7;
227 this.label5.ImageList = this.imageList;
228 this.label5.Location = new System.Drawing.Point(24, 188);
229 this.label5.Name = "label5";
230 this.label5.Size = new System.Drawing.Size(27, 28);
231 this.label5.TabIndex = 23;
232 //
233 // imageList
234 //
235 this.imageList.ColorDepth = System.Windows.Forms.ColorDepth.Depth32Bit;
236 this.imageList.ImageSize = new System.Drawing.Size(27, 28);
237 this.imageList.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList.ImageStream")));
238 this.imageList.TransparentColor = System.Drawing.Color.Empty;
239 //
240 // toolEllipse
241 //
242 this.toolEllipse.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
243 this.toolEllipse.ImageIndex = 2;
244 this.toolEllipse.ImageList = this.imageList;
245 this.toolEllipse.Location = new System.Drawing.Point(8, 84);
246 this.toolEllipse.Name = "toolEllipse";
247 this.toolEllipse.Size = new System.Drawing.Size(48, 32);
248 this.toolEllipse.TabIndex = 21;
249 this.toolEllipse.CheckedChanged += new System.EventHandler(this.radioButtonX_CheckedChanged);
250 //
251 // toolFill
252 //
253 this.toolFill.BackColor = System.Drawing.Color.Transparent;
254 this.toolFill.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
255 this.toolFill.ImageIndex = 5;
256 this.toolFill.ImageList = this.imageList;
257 this.toolFill.Location = new System.Drawing.Point(8, 152);
258 this.toolFill.Name = "toolFill";
259 this.toolFill.Size = new System.Drawing.Size(48, 32);
260 this.toolFill.TabIndex = 20;
261 this.toolFill.CheckedChanged += new System.EventHandler(this.radioButtonX_CheckedChanged);
262 //
263 // toolErase
264 //
265 this.toolErase.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
266 this.toolErase.ForeColor = System.Drawing.SystemColors.Control;
267 this.toolErase.ImageIndex = 6;
268 this.toolErase.ImageList = this.imageList;
269 this.toolErase.Location = new System.Drawing.Point(20, 216);
270 this.toolErase.Name = "toolErase";
271 this.toolErase.Size = new System.Drawing.Size(32, 32);
272 this.toolErase.TabIndex = 19;
273 this.toolErase.Click += new System.EventHandler(this.toolErase_Click);
274 //
275 // toolTriangle
276 //
277 this.toolTriangle.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
278 this.toolTriangle.ImageIndex = 3;
279 this.toolTriangle.ImageList = this.imageList;
280 this.toolTriangle.Location = new System.Drawing.Point(8, 120);
281 this.toolTriangle.Name = "toolTriangle";
282 this.toolTriangle.Size = new System.Drawing.Size(48, 32);
283 this.toolTriangle.TabIndex = 18;
284 this.toolTriangle.CheckedChanged += new System.EventHandler(this.radioButtonX_CheckedChanged);
285 //
286 // toolRectangle
287 //
288 this.toolRectangle.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
289 this.toolRectangle.ImageIndex = 1;
290 this.toolRectangle.ImageList = this.imageList;
291 this.toolRectangle.Location = new System.Drawing.Point(8, 52);
292 this.toolRectangle.Name = "toolRectangle";
293 this.toolRectangle.Size = new System.Drawing.Size(48, 32);
294 this.toolRectangle.TabIndex = 17;
295 this.toolRectangle.CheckedChanged += new System.EventHandler(this.radioButtonX_CheckedChanged);
296 //
297 // toolLine
298 //
299 this.toolLine.BackColor = System.Drawing.SystemColors.Control;
300 this.toolLine.Checked = true;
301 this.toolLine.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
302 this.toolLine.ImageIndex = 0;
303 this.toolLine.ImageList = this.imageList;
304 this.toolLine.Location = new System.Drawing.Point(8, 20);
305 this.toolLine.Name = "toolLine";
306 this.toolLine.Size = new System.Drawing.Size(48, 32);
307 this.toolLine.TabIndex = 16;
308 this.toolLine.TabStop = true;
309 this.toolLine.CheckedChanged += new System.EventHandler(this.radioButtonX_CheckedChanged);
310 //
311 // Form1
312 //
313 this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
314 this.BackColor = System.Drawing.SystemColors.Control;
315 this.ClientSize = new System.Drawing.Size(488, 405);
316 this.Controls.Add(this.groupBox2);
317 this.Controls.Add(this.pictureBox1);
318 this.Controls.Add(this.report);
319 this.Controls.Add(this.groupBox1);
320 this.MinimumSize = new System.Drawing.Size(496, 432);
321 this.Name = "Form1";
322 this.Text = "XmlBlaster C# demo using XML-RPC";
323 this.Closing += new System.ComponentModel.CancelEventHandler(this.Form1_Closing);
324 this.Load += new System.EventHandler(this.Form1_Load);
325 this.groupBox1.ResumeLayout(false);
326 this.groupBox2.ResumeLayout(false);
327 this.ResumeLayout(false);
328
329 }
330 #endregion
331
332 public Form1()
333 {
334 //
335 // Requis pour la prise en charge du Concepteur Windows Forms
336 //
337 InitializeComponent();
338
339 }
340
341 /// <summary>
342 /// Nettoyage des ressources utilisées.
343 /// </summary>
344 protected override void Dispose( bool disposing )
345 {
346 if( disposing )
347 {
348 if (components != null)
349 {
350 components.Dispose();
351 }
352 }
353 base.Dispose( disposing );
354 }
355
356 /// <summary>
357 /// Point d'entrée principal de l'application.
358 /// </summary>
359 [STAThread]
360 static void Main()
361 {
362 Application.EnableVisualStyles();
363 Application.Run(new Form1());
364 }
365
366
367 static readonly string EOL = Environment.NewLine ;
368
369 XmlBlasterClient xmlBlaster ;
370
371 void HandleException( Exception ex )
372 {
373 printError( ex.Message );
374 printError( ex.StackTrace );
375 //MessageBox.Show("Error: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
376 }
377
378
379 public void printLog( string msg )
380 {
381 string s = "[LOG] " + msg ;
382 this.report.AppendText( s + EOL );
383 Debug.WriteLine( s );
384 }
385 public void printError( string msg )
386 {
387
388 // Change some text properties
389
390 Color fc = this.report.SelectionColor ;
391 Font currentFont = this.report.SelectionFont ;
392 FontStyle newFontStyle;
393 newFontStyle = FontStyle.Bold;
394 this.report.SelectionColor = Color.Red ;
395 this.report.SelectionFont = new Font(
396 currentFont.FontFamily,
397 currentFont.Size,
398 newFontStyle
399 );
400
401 this.report.AppendText( "[ERROR] " );
402
403 // restore text properties
404 this.report.SelectionColor = fc ;
405 this.report.SelectionFont = currentFont ;
406
407 this.report.AppendText( msg + EOL );
408
409 Debug.WriteLine( "[ERROR] "+msg );
410 }
411
412
413 private void Form1_Load(object sender, System.EventArgs e)
414 {
415 this.report.Text = "" ;
416 //this.server_url.Text = "http://192.168.0.151:8080/" ;
417 this.server_url.Text = "http://127.0.0.1:8080/" ;
418 this.username.Text = "guest" ;
419 this.password.Text = "guest" ;
420
421 GraphicsInit();
422
423 numclicks=0;
424 color=toolColor.BackColor;
425
426 xmlBlaster = new XmlBlasterClient();
427 }
428
429
430 private void connect_Click(object sender, System.EventArgs e)
431 {
432 try
433 {
434 this.xmlBlaster.Connect( this.server_url.Text, this.username.Text, this.password.Text );
435
436 printLog( "Connect successful. sessionId = "+this.xmlBlaster.SessionId );
437 }
438 catch( XmlBlasterException ex )
439 {
440 HandleException( ex );
441 }
442
443 try
444 {
445 XmlBlasterCallback.messageArrived += new XmlBlasterCallback.MessageArrivedDelegate( MessageArrived );
446
447 this.xmlBlaster.Subscribe( MessageDrawing.message_topic );
448 printLog( "Subscribe successful. Topic : "+MessageDrawing.message_topic );
449 }
450 catch( Exception ex )
451 {
452 HandleException( ex );
453 }
454
455 }
456
457
458 void MessageArrived( string key, string xmlMessage )
459 {
460 printLog( "MessageArrived()" );
461 //printLog( "\t key: "+key );
462
463 try
464 {
465 MessageDrawing msg = MessageDrawing.CreateFromXml( xmlMessage );
466
467 msg.Draw( graphics );
468
469 pictureBox1.Invalidate();
470 }
471 catch( Exception ex )
472 {
473 HandleException( ex );
474 }
475
476 }
477
478
479 private Color color;
480 private Point[] pts;
481 private int mpx,mpy,numclicks;
482 private Bitmap bitmap;
483 private Graphics graphics;
484
485 void GraphicsInit()
486 {
487 Bitmap oldBitmap = null ;
488
489 if( bitmap != null )
490 {
491 oldBitmap = bitmap ;
492 }
493
494 // Create and clear buffer
495 bitmap=new Bitmap( this.pictureBox1.Width, this.pictureBox1.Height );
496
497 graphics=Graphics.FromImage(bitmap);
498 graphics.SmoothingMode=SmoothingMode.HighQuality;
499 graphics.Clear(Color.White);
500
501 if( oldBitmap != null )
502 {
503 graphics.DrawImage( oldBitmap, 0, 0 );
504 }
505
506 }
507
508
509 private void pictureBox1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
510 {
511 e.Graphics.SmoothingMode=SmoothingMode.HighQuality;
512 e.Graphics.DrawImageUnscaled(bitmap,0,0);
513
514 // Show clicks (progress)
515 if(numclicks!=0)
516 {
517 if(toolLine.Checked)
518 {
519 e.Graphics.DrawLine(new Pen(color),pts[1],new Point(mpx,mpy));
520
521 }
522 else if(toolRectangle.Checked)
523 {
524 int x=pts[1].X;
525 int y=pts[1].Y;
526 int w=mpx-x;
527 int h=mpy-y;
528 if(w<0)
529 {
530 x=mpx;
531 w=-w;
532 }
533 if(h<0)
534 {
535 y=mpy;
536 h=-h;
537 }
538 if(toolFill.Checked)
539 e.Graphics.FillRectangle(new SolidBrush(color),x,y,w,h);
540 else
541 e.Graphics.DrawRectangle(new Pen(color),x,y,w,h);
542 }
543 else if(toolTriangle.Checked)
544 {
545 if(numclicks==2)
546 e.Graphics.DrawLine(new Pen(color),pts[2],new Point(mpx,mpy));
547 else
548 {
549 if(toolFill.Checked)
550 e.Graphics.FillPolygon(new SolidBrush(color),new Point[]{pts[2],pts[1],new Point(mpx,mpy)});
551 else
552 e.Graphics.DrawPolygon(new Pen(color),new Point[]{pts[2],pts[1],new Point(mpx,mpy)});
553 }
554 }
555 else if(toolEllipse.Checked)
556 {
557 int x=pts[1].X;
558 int y=pts[1].Y;
559 int w=mpx-x;
560 int h=mpy-y;
561 if(w<0)
562 {
563 x=mpx;
564 w=-w;
565 }
566 if(h<0)
567 {
568 y=mpy;
569 h=-h;
570 }
571 if(toolFill.Checked)
572 e.Graphics.FillEllipse(new SolidBrush(color),x,y,w,h);
573 else
574 e.Graphics.DrawEllipse(new Pen(color),x,y,w,h);
575 }
576 }
577 }
578
579 private void pictureBox1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
580 {
581 if(e.Button==MouseButtons.Left)
582 {
583 if(numclicks==0)
584 {
585 // Set numclicks and first point to line
586 if(toolLine.Checked)
587 {
588 pts=new Point[2];
589 numclicks=1;
590 pts[numclicks]=new Point(e.X,e.Y);
591 }
592 // Set numclicks and first point to rectangle
593 if(toolRectangle.Checked)
594 {
595 pts=new Point[2];
596 numclicks=1;
597 pts[numclicks]=new Point(e.X,e.Y);
598 }
599 // Set numclicks and first point to triangle
600 if(toolTriangle.Checked)
601 {
602 pts=new Point[3];
603 numclicks=2;
604 pts[numclicks]=new Point(e.X,e.Y);
605 }
606 // Set numclicks and first point to ellipse
607 if(toolEllipse.Checked)
608 {
609 pts=new Point[2];
610 numclicks=1;
611 pts[numclicks]=new Point(e.X,e.Y);
612 }
613 }
614 else
615 {
616 MessageDrawing messageDrawing = null ;
617
618 numclicks--;
619 pts[numclicks]=new Point(e.X,e.Y);
620
621 if(numclicks==0)
622 {
623 // draw line
624 if(toolLine.Checked)
625 {
626 graphics.DrawLine(new Pen(color),pts[1],pts[0]);
627
628 messageDrawing = new MessageDrawingLine( color, pts[1], pts[0] );
629 }
630 // draw rectangle
631 else if(toolRectangle.Checked)
632 {
633 int x=pts[1].X;
634 int y=pts[1].Y;
635 int w=mpx-x;
636 int h=mpy-y;
637 if(w<0)
638 {
639 x=mpx;
640 w=-w;
641 }
642 if(h<0)
643 {
644 y=mpy;
645 h=-h;
646 }
647 if(toolFill.Checked)
648 graphics.FillRectangle(new SolidBrush(color),x,y,w,h);
649 else
650 graphics.DrawRectangle(new Pen(color),x,y,w,h);
651
652 messageDrawing = new MessageDrawingRectangle( toolFill.Checked, color, new Point(x,y), new Size(w,h) );
653 }
654 else if(toolTriangle.Checked)
655 // draw triangle
656 {
657 if(toolFill.Checked)
658 graphics.FillPolygon(new SolidBrush(color),new Point[]{pts[2],pts[1],pts[0]});
659 else
660 graphics.DrawPolygon(new Pen(color),new Point[]{pts[2],pts[1],pts[0]});
661
662 messageDrawing = new MessageDrawingTriangle( toolFill.Checked, color, pts[2],pts[1],pts[0] );
663 }
664 else if(toolEllipse.Checked)
665 // draw ellipse
666 {
667 int x=pts[1].X;
668 int y=pts[1].Y;
669 int w=mpx-x;
670 int h=mpy-y;
671 if(w<0)
672 {
673 x=mpx;
674 w=-w;
675 }
676 if(h<0)
677 {
678 y=mpy;
679 h=-h;
680 }
681 if(toolFill.Checked)
682 graphics.FillEllipse(new SolidBrush(color),x,y,w,h);
683 else
684 graphics.DrawEllipse(new Pen(color),x,y,w,h);
685
686 messageDrawing = new MessageDrawingEllipse( toolFill.Checked, color, new Point(x,y), new Size(w,h) );
687 }
688 }
689
690 if( messageDrawing != null ){
691 messageDrawing.Send( this, this.xmlBlaster );
692 }
693 }
694 }
695 }
696
697 private void pictureBox1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
698 {
699 if(numclicks!=0)
700 {
701 mpx=e.X;
702 mpy=e.Y;
703
704 pictureBox1.Invalidate();
705 }
706 }
707
708 private void pictureBox1_Resize(object sender, System.EventArgs e)
709 {
710 this.GraphicsInit();
711 }
712
713
714 private void radioButtonX_CheckedChanged(object sender, System.EventArgs e)
715 {
716 numclicks=0;
717 if( this.toolFill.Checked )
718 {
719 this.toolFill.ImageIndex = 4;
720 }
721 else
722 {
723 this.toolFill.ImageIndex = 5;
724 }
725 }
726
727 private void toolColor_Click(object sender, System.EventArgs e)
728 {
729 numclicks=0;
730 if(colorDialog1.ShowDialog()==DialogResult.OK)
731 color=toolColor.BackColor=colorDialog1.Color;
732
733 }
734
735 private void toolErase_Click(object sender, System.EventArgs e)
736 {
737 numclicks=0;
738 graphics.Clear(Color.White);
739 pictureBox1.Invalidate();
740 }
741
742 private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
743 {
744 try
745 {
746 this.xmlBlaster.Disconnect();
747 }
748 catch(Exception ex)
749 {
750 Debug.WriteLine( "Failed to disconnect : " + ex.Message );
751 }
752
753 }
754
755 }
756 }
syntax highlighted by Code2HTML, v. 0.9.1