Tengo imágenes .gif en un pictureBox que lo cambio al pulsar un botón. Lo curisoso es que se borra o desaparace la iamgen cuando cambio de imagen y no se porque es.
Tiene que funcioinar así.
Si pulso botón ON, se ve una imagen de una luz encendida. Si pulso el otro botón OFF, se ve la otra imagen del mismo pictureBox pero con la imgen de la luz apagada, así de sencillo.
Descargar proyecto completo de Visual C# 2010 Espress
Código
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using PicParallel_WPF.Properties; // No olvidar. // http://social.msdn.microsoft.com/Forums/es-ES/wpfes/thread/924e79ae-3c84-4f28-bb6d-f97022942717/ // http://social.msdn.microsoft.com/Forums/es-ES/wpfes/thread/3a647448-313e-4da1-84d1-d3f25504309e#f22663da-6251-484f-ae4e-4eccb00bbef2 namespace PicParallel_WPF { /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public partial class MainWindow : Window { // No olvidar estas variables. public int i = 0, j = 0, adress = 888; public int D7, D6, D5, D4, D3, D2, D1, D0; public MainWindow() { InitializeComponent(); } private void Reset_LEDs() // Resetea todos los Led al iniciar el programa. { try { PicParallel_WPF.PortInterop.Output(adress, 0); PicParallel_WPF.PortInterop.Input(adress); } catch (DllNotFoundException) { Alerta_1(); } //Reset_LEDs(); } #region Opciones public void opciones() { int value = 0; if (D0 == 1) { value += (int)Math.Pow(2, 0); LoadNewPict_D0(); } else LoadOldPict_D0(); value += 0; if (D1 == 1) { value += (int)Math.Pow(2, 1); LoadNewPict_D1(); } else LoadOldPict_D1(); value += 0; if (D2 == 1) { value += (int)Math.Pow(2, 2); LoadNewPict_D2(); } else LoadOldPict_D2(); value += 0; if (D3 == 1) { value += (int)Math.Pow(2, 3); LoadNewPict_D3(); } else LoadOldPict_D3(); value += 0; if (D4 == 1) { value += (int)Math.Pow(2, 4); LoadNewPict_D4(); } else LoadOldPict_D4(); value += 0; if (D5 == 1) { value += (int)Math.Pow(2, 5); LoadNewPict_D5(); } else LoadOldPict_D5(); value += 0; if (D6 == 1) { value += (int)Math.Pow(2, 6); LoadNewPict_D6(); } else LoadOldPict_D6(); value += 0; if (D7 == 1) { value += (int)Math.Pow(2, 7); LoadNewPict_D7(); } else LoadOldPict_D7(); value += 0; try { PicParallel_WPF.PortInterop.Output(adress, value); } catch (DllNotFoundException) { Alerta_1(); } } #endregion static void Alerta_1() { MessageBox.Show(@"No se escuentra la dll especificada. Asegúrate que la dll 'inpout32.dl' esté al lado del ejecutable principal. La reinstalación puede resolver el problema.", "Aviso:", MessageBoxButton.OK, MessageBoxImage.Stop); } #region Cargando los Led de la imagen. private void LoadNewPict_D0() { } private void LoadNewPict_D1() { } private void LoadNewPict_D2() { } private void LoadNewPict_D3() { } private void LoadNewPict_D4() { } private void LoadNewPict_D5() { } private void LoadNewPict_D6() { } private void LoadNewPict_D7() { } private void LoadOldPict_D0() { } private void LoadOldPict_D1() { } private void LoadOldPict_D2() { } private void LoadOldPict_D3() { } private void LoadOldPict_D4() { } private void LoadOldPict_D5() { } private void LoadOldPict_D6() { } private void LoadOldPict_D7() { } #endregion */ private void button_Enviar_Click(object sender, RoutedEventArgs e) { try { PicParallel_WPF.PortInterop.Output(adress, Int32.Parse(textBox_byte.Text)); } catch (DllNotFoundException) { Alerta_1(); } } private void button_Address_Click(object sender, RoutedEventArgs e) { if (textBox_port_adress.Text == "378") { adress = 888; } else { adress = 632; } } private void button_Reset_Leds_Click(object sender, RoutedEventArgs e) { j = 0; i = 0; Reset_LEDs(); D7 = 0; D6 = 0; D5 = 0; D4 = 0; D3 = 0; D2 = 0; D1 = 0; D0 = 0; } #region Bontones de control. private void button_D0_ON_Click(object sender, RoutedEventArgs e) { D0 = 1; opciones(); } private void button_D0_OFF_Click(object sender, RoutedEventArgs e) { D0 = 0; opciones(); } private void button_D1_ON_Click(object sender, RoutedEventArgs e) { D1 = 1; opciones(); } private void button_D1_OFF_Click(object sender, RoutedEventArgs e) { D1 = 0; opciones(); } private void button_D2_ON_Click(object sender, RoutedEventArgs e) { D2 = 1; opciones(); } private void button_D2_OFF_Click(object sender, RoutedEventArgs e) { D2 = 0; opciones(); } private void button_D3_ON_Click(object sender, RoutedEventArgs e) { D3 = 1; opciones(); } private void button_D3_OFF_Click(object sender, RoutedEventArgs e) { D3 = 0; opciones(); } private void button_D4_ON_Click(object sender, RoutedEventArgs e) { D4 = 1; opciones(); } private void button_D4_OFF_Click(object sender, RoutedEventArgs e) { D4 = 0; opciones(); } private void button_D5_ON_Click(object sender, RoutedEventArgs e) { D5 = 1; opciones(); } private void button_D5_OFF_Click(object sender, RoutedEventArgs e) { D5 = 0; opciones(); } private void button_D6_ON_Click(object sender, RoutedEventArgs e) { D6 = 1; opciones(); } private void button_D6_OFF_Click(object sender, RoutedEventArgs e) { D6 = 0; opciones(); } private void button_D7_ON_Click(object sender, RoutedEventArgs e) { D7 = 1; opciones(); } private void button_D7_OFF_Click(object sender, RoutedEventArgs e) { D7 = 0; opciones(); } #endregion } }