elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Recuerda que debes registrarte en el foro para poder participar (preguntar y responder)


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  Cambiar imagen con botones
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Cambiar imagen con botones  (Leído 1,693 veces)
Meta


Desconectado Desconectado

Mensajes: 3.438



Ver Perfil WWW
Cambiar imagen con botones
« en: 15 Junio 2010, 13:00 pm »

Buenas:

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
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using System.Windows.Data;
  8. using System.Windows.Documents;
  9. using System.Windows.Input;
  10. using System.Windows.Media;
  11. using System.Windows.Media.Imaging;
  12. using System.Windows.Navigation;
  13. using System.Windows.Shapes;
  14.  
  15. using PicParallel_WPF.Properties; // No olvidar.
  16.  
  17. // http://social.msdn.microsoft.com/Forums/es-ES/wpfes/thread/924e79ae-3c84-4f28-bb6d-f97022942717/
  18. // http://social.msdn.microsoft.com/Forums/es-ES/wpfes/thread/3a647448-313e-4da1-84d1-d3f25504309e#f22663da-6251-484f-ae4e-4eccb00bbef2
  19.  
  20. namespace PicParallel_WPF
  21. {
  22.  /// <summary>
  23.  /// Interaction logic for MainWindow.xaml
  24.  /// </summary>
  25.  public partial class MainWindow : Window
  26.  {
  27.    // No olvidar estas variables.
  28.    public int i = 0, j = 0, adress = 888;
  29.    public int D7, D6, D5, D4, D3, D2, D1, D0;
  30.  
  31.    public MainWindow()
  32.    {
  33.      InitializeComponent();
  34.    }
  35.  
  36.    private void Reset_LEDs() // Resetea todos los Led al iniciar el programa.
  37.    {
  38.      try
  39.      {
  40.        PicParallel_WPF.PortInterop.Output(adress, 0);
  41.        PicParallel_WPF.PortInterop.Input(adress);
  42.      }
  43.      catch (DllNotFoundException)
  44.      {
  45.        Alerta_1();
  46.      }
  47.      //Reset_LEDs();
  48.      image_D0.Source = new BitmapImage() { UriSource = new Uri(@"/img/off.gif", UriKind.Relative) };
  49.      image_D1.Source = new BitmapImage() { UriSource = new Uri(@"/img/off.gif", UriKind.Relative) };
  50.      image_D2.Source = new BitmapImage() { UriSource = new Uri(@"/img/off.gif", UriKind.Relative) };
  51.      image_D3.Source = new BitmapImage() { UriSource = new Uri(@"/img/off.gif", UriKind.Relative) };
  52.      image_D4.Source = new BitmapImage() { UriSource = new Uri(@"/img/off.gif", UriKind.Relative) };
  53.      image_D5.Source = new BitmapImage() { UriSource = new Uri(@"/img/off.gif", UriKind.Relative) };
  54.      image_D6.Source = new BitmapImage() { UriSource = new Uri(@"/img/off.gif", UriKind.Relative) };
  55.      image_D7.Source = new BitmapImage() { UriSource = new Uri(@"/img/off.gif", UriKind.Relative) };
  56.    }
  57.  
  58.    #region Opciones
  59.    public void opciones()
  60.    {
  61.      int value = 0;
  62.  
  63.      if (D0 == 1)
  64.      {
  65.        value += (int)Math.Pow(2, 0);
  66.        LoadNewPict_D0();
  67.      }
  68.      else
  69.        LoadOldPict_D0();
  70.      value += 0;
  71.  
  72.      if (D1 == 1)
  73.      {
  74.        value += (int)Math.Pow(2, 1);
  75.        LoadNewPict_D1();
  76.      }
  77.      else
  78.        LoadOldPict_D1();
  79.      value += 0;
  80.  
  81.      if (D2 == 1)
  82.      {
  83.        value += (int)Math.Pow(2, 2);
  84.        LoadNewPict_D2();
  85.      }
  86.      else
  87.        LoadOldPict_D2();
  88.      value += 0;
  89.  
  90.      if (D3 == 1)
  91.      {
  92.        value += (int)Math.Pow(2, 3);
  93.        LoadNewPict_D3();
  94.      }
  95.      else
  96.        LoadOldPict_D3();
  97.      value += 0;
  98.  
  99.      if (D4 == 1)
  100.      {
  101.        value += (int)Math.Pow(2, 4);
  102.        LoadNewPict_D4();
  103.      }
  104.      else
  105.        LoadOldPict_D4();
  106.      value += 0;
  107.  
  108.      if (D5 == 1)
  109.      {
  110.        value += (int)Math.Pow(2, 5);
  111.        LoadNewPict_D5();
  112.      }
  113.      else
  114.        LoadOldPict_D5();
  115.      value += 0;
  116.  
  117.      if (D6 == 1)
  118.      {
  119.        value += (int)Math.Pow(2, 6);
  120.        LoadNewPict_D6();
  121.      }
  122.      else
  123.        LoadOldPict_D6();
  124.      value += 0;
  125.  
  126.      if (D7 == 1)
  127.      {
  128.        value += (int)Math.Pow(2, 7);
  129.        LoadNewPict_D7();
  130.      }
  131.      else
  132.        LoadOldPict_D7();
  133.      value += 0;
  134.  
  135.      try
  136.      {
  137.         PicParallel_WPF.PortInterop.Output(adress, value);
  138.      }
  139.      catch (DllNotFoundException)
  140.      {
  141.        Alerta_1();
  142.      }
  143.  
  144.    }
  145.  
  146.    #endregion
  147.  
  148.    static void Alerta_1()
  149.    {
  150.      MessageBox.Show(@"No se escuentra la dll especificada.
  151.  
  152. Asegúrate que la dll 'inpout32.dl' esté al lado del ejecutable principal.
  153. La reinstalación puede resolver el problema.", "Aviso:",
  154.    MessageBoxButton.OK, MessageBoxImage.Stop);
  155.    }
  156.  
  157.    #region Cargando los Led de la imagen.
  158.  
  159.    private void LoadNewPict_D0()
  160.    {
  161.      image_D0.Source = new BitmapImage() { UriSource = new Uri("/img/on.gif", UriKind.Relative) };
  162.    }
  163.  
  164.    private void LoadNewPict_D1()
  165.    {
  166.      image_D1.Source = new BitmapImage() { UriSource = new Uri("/img/on.gif", UriKind.Relative) };
  167.    }
  168.  
  169.    private void LoadNewPict_D2()
  170.    {
  171.      image_D2.Source = new BitmapImage() { UriSource = new Uri("/img/on.gif", UriKind.Relative) };
  172.    }
  173.  
  174.    private void LoadNewPict_D3()
  175.    {
  176.      image_D3.Source = new BitmapImage() { UriSource = new Uri("/img/on.gif", UriKind.Relative) };
  177.    }
  178.  
  179.    private void LoadNewPict_D4()
  180.    {
  181.      image_D4.Source = new BitmapImage() { UriSource = new Uri("/img/on.gif", UriKind.Relative) };
  182.    }
  183.  
  184.    private void LoadNewPict_D5()
  185.    {
  186.      image_D5.Source = new BitmapImage() { UriSource = new Uri("/img/on.gif", UriKind.Relative) };
  187.    }
  188.  
  189.    private void LoadNewPict_D6()
  190.    {
  191.      image_D6.Source = new BitmapImage() { UriSource = new Uri("/img/on.gif", UriKind.Relative) };
  192.    }
  193.  
  194.    private void LoadNewPict_D7()
  195.    {
  196.      image_D0.Source = new BitmapImage() { UriSource = new Uri("/img/on.gif", UriKind.Relative) };
  197.    }
  198.  
  199.  
  200.    private void LoadOldPict_D0()
  201.    {
  202.      image_D0.Source = new BitmapImage() { UriSource = new Uri("/img/off.gif", UriKind.Relative) };
  203.    }
  204.  
  205.    private void LoadOldPict_D1()
  206.    {
  207.      image_D1.Source = new BitmapImage() { UriSource = new Uri("/img/off.gif", UriKind.Relative) };
  208.    }
  209.  
  210.    private void LoadOldPict_D2()
  211.    {
  212.      image_D2.Source = new BitmapImage() { UriSource = new Uri("/img/off.gif", UriKind.Relative) };
  213.    }
  214.  
  215.    private void LoadOldPict_D3()
  216.    {
  217.      image_D3.Source = new BitmapImage() { UriSource = new Uri("/img/off.gif", UriKind.Relative) };
  218.    }
  219.  
  220.    private void LoadOldPict_D4()
  221.    {
  222.      image_D4.Source = new BitmapImage() { UriSource = new Uri("/img/off.gif", UriKind.Relative) };
  223.    }
  224.  
  225.    private void LoadOldPict_D5()
  226.    {
  227.      image_D5.Source = new BitmapImage() { UriSource = new Uri("/img/off.gif", UriKind.Relative) };
  228.    }
  229.  
  230.    private void LoadOldPict_D6()
  231.    {
  232.      image_D6.Source = new BitmapImage() { UriSource = new Uri("/img/off.gif", UriKind.Relative) };
  233.    }
  234.  
  235.    private void LoadOldPict_D7()
  236.    {
  237.      image_D7.Source = new BitmapImage() { UriSource = new Uri("/img/off.gif", UriKind.Relative) };
  238.    }
  239.    #endregion */
  240.  
  241.    private void button_Enviar_Click(object sender, RoutedEventArgs e)
  242.    {
  243.      try
  244.      {
  245.        PicParallel_WPF.PortInterop.Output(adress, Int32.Parse(textBox_byte.Text));
  246.      }
  247.      catch (DllNotFoundException)
  248.      {
  249.        Alerta_1();
  250.      }
  251.    }
  252.  
  253.    private void button_Address_Click(object sender, RoutedEventArgs e)
  254.    {
  255.      if (textBox_port_adress.Text == "378")
  256.      {
  257.        adress = 888;
  258.      }
  259.      else
  260.      {
  261.        adress = 632;
  262.      }
  263.    }
  264.  
  265.    private void button_Reset_Leds_Click(object sender, RoutedEventArgs e)
  266.    {
  267.      j = 0; i = 0;
  268.      Reset_LEDs();
  269.      D7 = 0;
  270.      D6 = 0;
  271.      D5 = 0;
  272.      D4 = 0;
  273.      D3 = 0;
  274.      D2 = 0;
  275.      D1 = 0;
  276.      D0 = 0;
  277.    }
  278.  
  279.    #region Bontones de control.
  280.    private void button_D0_ON_Click(object sender, RoutedEventArgs e)
  281.    {
  282.      D0 = 1;
  283.      opciones();
  284.    }
  285.  
  286.    private void button_D0_OFF_Click(object sender, RoutedEventArgs e)
  287.    {
  288.      D0 = 0;
  289.      opciones();
  290.    }
  291.  
  292.    private void button_D1_ON_Click(object sender, RoutedEventArgs e)
  293.    {
  294.      D1 = 1;
  295.      opciones();
  296.    }
  297.  
  298.    private void button_D1_OFF_Click(object sender, RoutedEventArgs e)
  299.    {
  300.      D1 = 0;
  301.      opciones();
  302.    }
  303.  
  304.    private void button_D2_ON_Click(object sender, RoutedEventArgs e)
  305.    {
  306.      D2 = 1;
  307.      opciones();
  308.    }
  309.  
  310.    private void button_D2_OFF_Click(object sender, RoutedEventArgs e)
  311.    {
  312.      D2 = 0;
  313.      opciones();
  314.    }
  315.  
  316.    private void button_D3_ON_Click(object sender, RoutedEventArgs e)
  317.    {
  318.      D3 = 1;
  319.      opciones();
  320.    }
  321.  
  322.    private void button_D3_OFF_Click(object sender, RoutedEventArgs e)
  323.    {
  324.      D3 = 0;
  325.      opciones();
  326.    }
  327.  
  328.    private void button_D4_ON_Click(object sender, RoutedEventArgs e)
  329.    {
  330.      D4 = 1;
  331.      opciones();
  332.    }
  333.  
  334.    private void button_D4_OFF_Click(object sender, RoutedEventArgs e)
  335.    {
  336.      D4 = 0;
  337.      opciones();
  338.    }
  339.  
  340.    private void button_D5_ON_Click(object sender, RoutedEventArgs e)
  341.    {
  342.      D5 = 1;
  343.      opciones();
  344.    }
  345.  
  346.    private void button_D5_OFF_Click(object sender, RoutedEventArgs e)
  347.    {
  348.      D5 = 0;
  349.      opciones();
  350.    }
  351.  
  352.    private void button_D6_ON_Click(object sender, RoutedEventArgs e)
  353.    {
  354.      D6 = 1;
  355.      opciones();
  356.    }
  357.  
  358.    private void button_D6_OFF_Click(object sender, RoutedEventArgs e)
  359.    {
  360.      D6 = 0;
  361.      opciones();
  362.    }
  363.  
  364.    private void button_D7_ON_Click(object sender, RoutedEventArgs e)
  365.    {
  366.      D7 = 1;
  367.      opciones();
  368.    }
  369.  
  370.    private void button_D7_OFF_Click(object sender, RoutedEventArgs e)
  371.    {
  372.      D7 = 0;
  373.      opciones();
  374.    }
  375.    #endregion
  376.  }
  377. }
  378.  
  379.  


En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Cambiar de color un textarea con botones
Desarrollo Web
Ori-chan 1 1,912 Último mensaje 30 Septiembre 2013, 06:51 am
por #!drvy
Stream Deck Mini: análisis, seis botones pueden cambiar tu mundo
Noticias
wolfbcn 0 1,068 Último mensaje 31 Octubre 2018, 03:12 am
por wolfbcn
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines