1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80:
| using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms;
namespace Kombinationsübung_Aufgabe1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void cmdFarbe_Click(object sender, EventArgs e) { ColorDialog cdlg = new ColorDialog(); if (DialogResult.OK == cdlg.ShowDialog()) lblFarbe.BackColor = cdlg.Color; } struct struKreis { public int x; public int y; public int Durchmesser; public Color farbe; }
List<struKreis> m_kreise = new List<struKreis>();
private void Form1_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) {
struKreis aktkreis; aktkreis.x = e.X; aktkreis.y = e.Y; aktkreis.farbe = lblFarbe.BackColor; Random r = new Random(); aktkreis.Durchmesser = r.Next(100); m_kreise.Add(aktkreis); } -------------------------------------------------------------- else if (e.Button == MouseButtons.Right) { for (int i = 0; i < m_kreise.Count; i++) { struKreis k = m_kreise[i]; int dx = Math.Abs(e.X - k.x);
int dy = Math.Abs(e.Y - k.y); double Abstand = Math.Sqrt(dx * dx + dy * dy); if (k.Durchmesser / 2 >= Abstand) { m_kreise.RemoveAt(i); i--; ----------------------------------------------------------------- } } } this.Invalidate(); } private void Form1_Paint(object sender, PaintEventArgs e) { Graphics g = this.CreateGraphics(); for (int i = 0; i < m_kreise.Count; i++) { struKreis k = m_kreise[i]; Pen myPen = new Pen(k.farbe); g.DrawEllipse(myPen, k.x - k.Durchmesser / 2, k.y - k.Durchmesser / 2, k.Durchmesser, k.Durchmesser); } } } } |