codice:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WindowsFormsApplication1.Chitarra;
namespace WindowsFormsApplication1
{
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>();
Timer timer1 = new Timer();
public Form1()
{
InitializeComponent();
this.timer1.Tick+=new EventHandler(timer1_Tick);
this.timer1.Interval = 100;
this.timer1.Start();
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++;
}
}
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 : PictureBox
{
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();
}
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);
}
}
}
}
e non ho notato nessuno sfarfallio