ArmandoCircuitos
Inicio
Electronica
Programacion
Resultado
Codigo
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Runtime.InteropServices; namespace Dado_electronico_LPT_01 { public partial class Form1 : Form { class ControlPort { [DllImport("inpout32.dll", EntryPoint = "Out32")] public static extern void Output(int adress, int value); } public Form1() { InitializeComponent(); } SolidBrush brocha1; Graphics puntos; byte cnt = 1; byte num = 0; private void button1_MouseDown(object sender, MouseEventArgs e) { timer1.Enabled = true; button1.Text = "Suelte para detener"; } private void panel1_Paint(object sender, PaintEventArgs e) { brocha1 = new SolidBrush(Color.Black); puntos = e.Graphics; if((cnt == 1) || (cnt == 3) || (cnt == 5)){ puntos.FillEllipse(brocha1, 80, 80, 40, 40); // 1, 3, 5 num += 1; } if ((cnt == 2) || (cnt == 3) || (cnt == 4) || (cnt == 5) || (cnt == 6)) { puntos.FillEllipse(brocha1, 140, 20, 40, 40); // 2, 3, 4, 5, 6 puntos.FillEllipse(brocha1, 20, 140, 40, 40); // 2, 3, 4, 5, 6 num += 2; } if ((cnt == 4) || (cnt == 5) || (cnt == 6)) { puntos.FillEllipse(brocha1, 20, 20, 40, 40); // 4, 5, 6 puntos.FillEllipse(brocha1, 140, 140, 40, 40); // 4, 5, 6 num += 4; } if (cnt == 6) { puntos.FillEllipse(brocha1, 20, 80, 40, 40); // 6 puntos.FillEllipse(brocha1, 140, 80, 40, 40); // 6 num += 8; } ControlPort.Output(0x378, num); num = 0; } private void button1_MouseUp(object sender, MouseEventArgs e) { timer1.Enabled = false; button1.Text = "Mantenga presionado para lanzar"; } private void timer1_Tick(object sender, EventArgs e) { panel1.Invalidate(); if (cnt >= 6) cnt = 1; else cnt++; } } }
Descarga del archivo
Descargar archivo