codice del form:codice del componente:codice:using System; using System.Collections; using System.Xml; using System.Xml.Linq; using System.Data; using System.Text; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Linq; using System.Windows.Forms; using System.Linq; namespace Chitarra { public partial class Form1 : Form { int t = 0; List<tasto> E= new List<tasto>(); List<tasto> D = new List<tasto>(); List<tasto> C = new List<tasto>(); public Form1() { InitializeComponent(); E.Add(new tasto(2, 2)); E.Add(new tasto(3, 2)); E.Add(new tasto(4, 2)); D.Add(new tasto(1, 2)); D.Add(new tasto(2, 3)); D.Add(new tasto(3, 2)); C.Add(new tasto(2, 2)); C.Add(new tasto(4, 3)); C.Add(new tasto(5, 4)); guitarControl1.Inizialize(E, D); } private void timer1_Tick(object sender, EventArgs e) { +t = t % 3; if (t == 0) guitarControl1.Play(E); else if (t == 1) guitarControl1.Play(D); else guitarControl1.Play(C); t++; } private void Form1_Load(object sender, EventArgs e) { } } }codice:namespace Chitarra { public struct tasto { public int corda; public int tastiera; public tasto(int corda, int tastiera) { this.corda = corda; this.tastiera = tastiera; } } public partial class GuitarControl : UserControl { public List<tasto> PremiNow = new List<tasto>(); public List<tasto> PremiDopo = new List<tasto>(); public List<tasto> buffer = new List<tasto>(); public GuitarControl() { InitializeComponent(); } public void Inizialize(List<tasto> now, List<tasto> dopo) { PremiNow = now; PremiDopo = dopo; } public void Play(List<tasto> next) { PremiNow = PremiDopo; PremiDopo = next; this.Invalidate(); } private void GuitarControl_Load(object sender, EventArgs e) { } private void GuitarControl_Paint(object sender, PaintEventArgs e) { } private void GuitarControl_BackgroundImageChanged(object sender, EventArgs e) { } protected override void OnPaint(PaintEventArgs e) { Pen p = new Pen(Color.Silver); SolidBrush r = new SolidBrush(Color.Red); SolidBrush g = new SolidBrush(Color.Gray); e.Graphics.FillRectangle(new SolidBrush(Color.Brown), new Rectangle(0, 0, 1020, 140)); e.Graphics.DrawLine(p, new Point(20, 20), new Point(1000, 20)); e.Graphics.DrawLine(p, new Point(20, 40), new Point(1000, 40)); e.Graphics.DrawLine(p, new Point(20, 60), new Point(1000, 60)); e.Graphics.DrawLine(p, new Point(20, 80), new Point(1000, 80)); e.Graphics.DrawLine(p, new Point(20, 100), new Point(1000, 100)); e.Graphics.DrawLine(p, new Point(20, 120), new Point(1000, 120)); for (int i = 0; i < 10; i++) { e.Graphics.DrawLine(p, new Point(i * 40 - 20, 10), new Point(i * 40 - 20, 125)); } foreach (tasto t in PremiDopo) { e.Graphics.FillEllipse(g, t.tastiera * 40 - 12, t.corda * 20 - 7, 14, 14); } foreach (tasto t in PremiNow) { e.Graphics.FillEllipse(r, t.tastiera * 40 - 10, t.corda * 20 - 5, 10, 10); } base.OnPaint(e); } } }

Rispondi quotando