Рисование лининий на форме - C#
Формулировка задачи:
на форме распологаются 2 picturebox. Как провести между ними линию, кроме того если целкнуть на 1м picturebox а после этого на 2м линию должна менять цвет.
Решение задачи: «Рисование лининий на форме»
textual
Листинг программы
using System; using System.Collections.Generic; using System.Windows.Forms; using System.Drawing; namespace pros { public class Program:Form { private PictureBox pictureBox1; private PictureBox pictureBox2; /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { Application.Run(new Program()); } Rectangle line; bool flag = false; Random rnd = new Random(); Program() { InitializeComponent(); line = new Rectangle(pictureBox1.Left + pictureBox1.Width, pictureBox1.Top + pictureBox1.Height /2, pictureBox2.Left, pictureBox2.Top + pictureBox2.Height /2); this.Paint += new PaintEventHandler(Program_Paint); } void Program_Paint(object sender, PaintEventArgs e) { e.Graphics.DrawLine (new Pen(Color.FromArgb(rnd.Next(255), rnd.Next(255), rnd.Next(255)),5), line.Left, line.Top ,line.Width, line.Height); } private void InitializeComponent() { this.pictureBox1 = new System.Windows.Forms.PictureBox(); this.pictureBox2 = new System.Windows.Forms.PictureBox(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).BeginInit(); this.SuspendLayout(); // // pictureBox1 // this.pictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; this.pictureBox1.Location = new System.Drawing.Point(43, 58); this.pictureBox1.Name = "pictureBox1"; this.pictureBox1.Size = new System.Drawing.Size(48, 48); this.pictureBox1.TabIndex = 0; this.pictureBox1.TabStop = false; this.pictureBox1.Click += new System.EventHandler(this.pictureBox1_Click); // // pictureBox2 // this.pictureBox2.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; this.pictureBox2.Location = new System.Drawing.Point(205, 46); this.pictureBox2.Name = "pictureBox2"; this.pictureBox2.Size = new System.Drawing.Size(54, 59); this.pictureBox2.TabIndex = 1; this.pictureBox2.TabStop = false; this.pictureBox2.Click += new System.EventHandler(this.pictureBox2_Click); // // Program // this.ClientSize = new System.Drawing.Size(292, 273); this.Controls.Add(this.pictureBox2); this.Controls.Add(this.pictureBox1); this.Name = "Program"; ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).EndInit(); this.ResumeLayout(false); } private void pictureBox1_Click(object sender, EventArgs e) { flag = true; } private void pictureBox2_Click(object sender, EventArgs e) { if(flag) Invalidate(); flag = false; } } }
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д