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

 

 


Tema destacado: Usando Git para manipular el directorio de trabajo, el índice y commits (segunda parte)


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP) (Moderador: kub0x)
| | | |-+  Información en int, hex y bin dentro de un Form
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Información en int, hex y bin dentro de un Form  (Leído 2,611 veces)
Meta


Desconectado Desconectado

Mensajes: 3.438



Ver Perfil WWW
Información en int, hex y bin dentro de un Form
« en: 20 Agosto 2014, 09:14 am »

Añado tres label en el Form, como indica en la imagen de abajo en cuadro rojo.
 Según pinche en los píxeles que en realidad cada cuadrado es un pictureBoxse vaya actualizando los datos int, hex y binario.
 
 El código que he hecho hasta ahora es este, pero no he puesto aún los label.

Código
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. namespace LCD_HD44780
  12. {
  13.    public partial class Form1 : Form
  14.    {
  15.        public Form1()
  16.        {
  17.            InitializeComponent();
  18.        }
  19.  
  20.        private void button_5x8_Rellenar_Click(object sender, EventArgs e)
  21.        {
  22.            pictureBox1.BackColor = Color.Black;
  23.            pictureBox2.BackColor = Color.Black;
  24.            pictureBox3.BackColor = Color.Black;
  25.            pictureBox4.BackColor = Color.Black;
  26.            pictureBox5.BackColor = Color.Black;
  27.            pictureBox6.BackColor = Color.Black;
  28.            pictureBox7.BackColor = Color.Black;
  29.            pictureBox8.BackColor = Color.Black;
  30.            pictureBox9.BackColor = Color.Black;
  31.            pictureBox10.BackColor = Color.Black;
  32.            pictureBox11.BackColor = Color.Black;
  33.            pictureBox12.BackColor = Color.Black;
  34.            pictureBox13.BackColor = Color.Black;
  35.            pictureBox14.BackColor = Color.Black;
  36.            pictureBox15.BackColor = Color.Black;
  37.            pictureBox16.BackColor = Color.Black;
  38.            pictureBox17.BackColor = Color.Black;
  39.            pictureBox18.BackColor = Color.Black;
  40.            pictureBox19.BackColor = Color.Black;
  41.            pictureBox20.BackColor = Color.Black;
  42.            pictureBox21.BackColor = Color.Black;
  43.            pictureBox22.BackColor = Color.Black;
  44.            pictureBox23.BackColor = Color.Black;
  45.            pictureBox24.BackColor = Color.Black;
  46.            pictureBox25.BackColor = Color.Black;
  47.            pictureBox26.BackColor = Color.Black;
  48.            pictureBox27.BackColor = Color.Black;
  49.            pictureBox28.BackColor = Color.Black;
  50.            pictureBox29.BackColor = Color.Black;
  51.            pictureBox30.BackColor = Color.Black;
  52.            pictureBox31.BackColor = Color.Black;
  53.            pictureBox32.BackColor = Color.Black;
  54.            pictureBox33.BackColor = Color.Black;
  55.            pictureBox34.BackColor = Color.Black;
  56.            pictureBox35.BackColor = Color.Black;
  57.        }
  58.  
  59.        private void button_5x7_Limpiar_Click(object sender, EventArgs e)
  60.        {
  61.            pictureBox1.BackColor = Color.Lime;
  62.            pictureBox2.BackColor = Color.Lime;
  63.            pictureBox3.BackColor = Color.Lime;
  64.            pictureBox4.BackColor = Color.Lime;
  65.            pictureBox5.BackColor = Color.Lime;
  66.            pictureBox6.BackColor = Color.Lime;
  67.            pictureBox7.BackColor = Color.Lime;
  68.            pictureBox8.BackColor = Color.Lime;
  69.            pictureBox9.BackColor = Color.Lime;
  70.            pictureBox10.BackColor = Color.Lime;
  71.            pictureBox11.BackColor = Color.Lime;
  72.            pictureBox12.BackColor = Color.Lime;
  73.            pictureBox13.BackColor = Color.Lime;
  74.            pictureBox14.BackColor = Color.Lime;
  75.            pictureBox15.BackColor = Color.Lime;
  76.            pictureBox16.BackColor = Color.Lime;
  77.            pictureBox17.BackColor = Color.Lime;
  78.            pictureBox18.BackColor = Color.Lime;
  79.            pictureBox19.BackColor = Color.Lime;
  80.            pictureBox20.BackColor = Color.Lime;
  81.            pictureBox21.BackColor = Color.Lime;
  82.            pictureBox22.BackColor = Color.Lime;
  83.            pictureBox23.BackColor = Color.Lime;
  84.            pictureBox24.BackColor = Color.Lime;
  85.            pictureBox25.BackColor = Color.Lime;
  86.            pictureBox26.BackColor = Color.Lime;
  87.            pictureBox27.BackColor = Color.Lime;
  88.            pictureBox28.BackColor = Color.Lime;
  89.            pictureBox29.BackColor = Color.Lime;
  90.            pictureBox30.BackColor = Color.Lime;
  91.            pictureBox31.BackColor = Color.Lime;
  92.            pictureBox32.BackColor = Color.Lime;
  93.            pictureBox33.BackColor = Color.Lime;
  94.            pictureBox34.BackColor = Color.Lime;
  95.            pictureBox35.BackColor = Color.Lime;
  96.        }
  97.  
  98.        private void pictureBox1_Click(object sender, EventArgs e)
  99.        {
  100.            if (pictureBox1.BackColor == Color.Black)
  101.            {
  102.                pictureBox1.BackColor = Color.Lime;
  103.            }
  104.  
  105.            else
  106.            {
  107.                pictureBox1.BackColor = Color.Black;
  108.            }
  109.        }
  110.  
  111.        private void pictureBox2_Click(object sender, EventArgs e)
  112.        {
  113.            if (pictureBox2.BackColor == Color.Black)
  114.            {
  115.                pictureBox2.BackColor = Color.Lime;
  116.            }
  117.  
  118.            else
  119.            {
  120.                pictureBox2.BackColor = Color.Black;
  121.            }
  122.        }
  123.  
  124.        private void pictureBox3_Click(object sender, EventArgs e)
  125.        {
  126.            if (pictureBox3.BackColor == Color.Black)
  127.            {
  128.                pictureBox3.BackColor = Color.Lime;
  129.            }
  130.  
  131.            else
  132.            {
  133.                pictureBox3.BackColor = Color.Black;
  134.            }
  135.        }
  136.  
  137.        private void pictureBox4_Click(object sender, EventArgs e)
  138.        {
  139.            if (pictureBox4.BackColor == Color.Black)
  140.            {
  141.                pictureBox4.BackColor = Color.Lime;
  142.            }
  143.  
  144.            else
  145.            {
  146.                pictureBox4.BackColor = Color.Black;
  147.            }
  148.        }
  149.  
  150.        private void pictureBox5_Click(object sender, EventArgs e)
  151.        {
  152.            if (pictureBox5.BackColor == Color.Black)
  153.            {
  154.                pictureBox5.BackColor = Color.Lime;
  155.            }
  156.  
  157.            else
  158.            {
  159.                pictureBox5.BackColor = Color.Black;
  160.            }
  161.        }
  162.  
  163.        private void pictureBox6_Click(object sender, EventArgs e)
  164.        {
  165.            if (pictureBox6.BackColor == Color.Black)
  166.            {
  167.                pictureBox6.BackColor = Color.Lime;
  168.            }
  169.  
  170.            else
  171.            {
  172.                pictureBox6.BackColor = Color.Black;
  173.            }
  174.        }
  175.  
  176.        private void pictureBox7_Click(object sender, EventArgs e)
  177.        {
  178.            if (pictureBox7.BackColor == Color.Black)
  179.            {
  180.                pictureBox7.BackColor = Color.Lime;
  181.            }
  182.  
  183.            else
  184.            {
  185.                pictureBox7.BackColor = Color.Black;
  186.            }
  187.        }
  188.  
  189.        private void pictureBox8_Click(object sender, EventArgs e)
  190.        {
  191.            if (pictureBox8.BackColor == Color.Black)
  192.            {
  193.                pictureBox8.BackColor = Color.Lime;
  194.            }
  195.  
  196.            else
  197.            {
  198.                pictureBox8.BackColor = Color.Black;
  199.            }
  200.        }
  201.  
  202.        private void pictureBox9_Click(object sender, EventArgs e)
  203.        {
  204.            if (pictureBox9.BackColor == Color.Black)
  205.            {
  206.                pictureBox9.BackColor = Color.Lime;
  207.            }
  208.  
  209.            else
  210.            {
  211.                pictureBox9.BackColor = Color.Black;
  212.            }
  213.        }
  214.  
  215.        private void pictureBox10_Click(object sender, EventArgs e)
  216.        {
  217.            if (pictureBox10.BackColor == Color.Black)
  218.            {
  219.                pictureBox10.BackColor = Color.Lime;
  220.            }
  221.  
  222.            else
  223.            {
  224.                pictureBox10.BackColor = Color.Black;
  225.            }
  226.        }
  227.  
  228.        private void pictureBox11_Click(object sender, EventArgs e)
  229.        {
  230.            if (pictureBox11.BackColor == Color.Black)
  231.            {
  232.                pictureBox11.BackColor = Color.Lime;
  233.            }
  234.  
  235.            else
  236.            {
  237.                pictureBox11.BackColor = Color.Black;
  238.            }
  239.        }
  240.  
  241.        private void pictureBox12_Click(object sender, EventArgs e)
  242.        {
  243.            if (pictureBox12.BackColor == Color.Black)
  244.            {
  245.                pictureBox12.BackColor = Color.Lime;
  246.            }
  247.  
  248.            else
  249.            {
  250.                pictureBox12.BackColor = Color.Black;
  251.            }
  252.        }
  253.  
  254.        private void pictureBox13_Click(object sender, EventArgs e)
  255.        {
  256.            if (pictureBox13.BackColor == Color.Black)
  257.            {
  258.                pictureBox13.BackColor = Color.Lime;
  259.            }
  260.  
  261.            else
  262.            {
  263.                pictureBox13.BackColor = Color.Black;
  264.            }
  265.        }
  266.  
  267.        private void pictureBox14_Click(object sender, EventArgs e)
  268.        {
  269.            if (pictureBox14.BackColor == Color.Black)
  270.            {
  271.                pictureBox14.BackColor = Color.Lime;
  272.            }
  273.  
  274.            else
  275.            {
  276.                pictureBox14.BackColor = Color.Black;
  277.            }
  278.        }
  279.  
  280.        private void pictureBox15_Click(object sender, EventArgs e)
  281.        {
  282.            if (pictureBox15.BackColor == Color.Black)
  283.            {
  284.                pictureBox15.BackColor = Color.Lime;
  285.            }
  286.  
  287.            else
  288.            {
  289.                pictureBox15.BackColor = Color.Black;
  290.            }
  291.        }
  292.  
  293.        private void pictureBox16_Click(object sender, EventArgs e)
  294.        {
  295.            if (pictureBox16.BackColor == Color.Black)
  296.            {
  297.                pictureBox16.BackColor = Color.Lime;
  298.            }
  299.  
  300.            else
  301.            {
  302.                pictureBox16.BackColor = Color.Black;
  303.            }
  304.        }
  305.  
  306.        private void pictureBox17_Click(object sender, EventArgs e)
  307.        {
  308.            if (pictureBox17.BackColor == Color.Black)
  309.            {
  310.                pictureBox17.BackColor = Color.Lime;
  311.            }
  312.  
  313.            else
  314.            {
  315.                pictureBox17.BackColor = Color.Black;
  316.            }
  317.        }
  318.  
  319.        private void pictureBox18_Click(object sender, EventArgs e)
  320.        {
  321.            if (pictureBox18.BackColor == Color.Black)
  322.            {
  323.                pictureBox18.BackColor = Color.Lime;
  324.            }
  325.  
  326.            else
  327.            {
  328.                pictureBox18.BackColor = Color.Black;
  329.            }
  330.        }
  331.  
  332.        private void pictureBox19_Click(object sender, EventArgs e)
  333.        {
  334.            if (pictureBox19.BackColor == Color.Black)
  335.            {
  336.                pictureBox19.BackColor = Color.Lime;
  337.            }
  338.  
  339.            else
  340.            {
  341.                pictureBox19.BackColor = Color.Black;
  342.            }
  343.        }
  344.  
  345.        private void pictureBox20_Click(object sender, EventArgs e)
  346.        {
  347.            if (pictureBox20.BackColor == Color.Black)
  348.            {
  349.                pictureBox20.BackColor = Color.Lime;
  350.            }
  351.  
  352.            else
  353.            {
  354.                pictureBox20.BackColor = Color.Black;
  355.            }
  356.        }
  357.  
  358.        private void pictureBox21_Click(object sender, EventArgs e)
  359.        {
  360.            if (pictureBox21.BackColor == Color.Black)
  361.            {
  362.                pictureBox21.BackColor = Color.Lime;
  363.            }
  364.  
  365.            else
  366.            {
  367.                pictureBox21.BackColor = Color.Black;
  368.            }
  369.        }
  370.  
  371.        private void pictureBox22_Click(object sender, EventArgs e)
  372.        {
  373.            if (pictureBox22.BackColor == Color.Black)
  374.            {
  375.                pictureBox22.BackColor = Color.Lime;
  376.            }
  377.  
  378.            else
  379.            {
  380.                pictureBox22.BackColor = Color.Black;
  381.            }
  382.        }
  383.  
  384.        private void pictureBox23_Click(object sender, EventArgs e)
  385.        {
  386.            if (pictureBox23.BackColor == Color.Black)
  387.            {
  388.                pictureBox23.BackColor = Color.Lime;
  389.            }
  390.  
  391.            else
  392.            {
  393.                pictureBox23.BackColor = Color.Black;
  394.            }
  395.        }
  396.  
  397.        private void pictureBox24_Click(object sender, EventArgs e)
  398.        {
  399.            if (pictureBox24.BackColor == Color.Black)
  400.            {
  401.                pictureBox24.BackColor = Color.Lime;
  402.            }
  403.  
  404.            else
  405.            {
  406.                pictureBox24.BackColor = Color.Black;
  407.            }
  408.        }
  409.  
  410.        private void pictureBox25_Click(object sender, EventArgs e)
  411.        {
  412.            if (pictureBox25.BackColor == Color.Black)
  413.            {
  414.                pictureBox25.BackColor = Color.Lime;
  415.            }
  416.  
  417.            else
  418.            {
  419.                pictureBox25.BackColor = Color.Black;
  420.            }
  421.        }
  422.  
  423.        private void pictureBox26_Click(object sender, EventArgs e)
  424.        {
  425.            if (pictureBox26.BackColor == Color.Black)
  426.            {
  427.                pictureBox26.BackColor = Color.Lime;
  428.            }
  429.  
  430.            else
  431.            {
  432.                pictureBox26.BackColor = Color.Black;
  433.            }
  434.        }
  435.  
  436.        private void pictureBox27_Click(object sender, EventArgs e)
  437.        {
  438.            if (pictureBox27.BackColor == Color.Black)
  439.            {
  440.                pictureBox27.BackColor = Color.Lime;
  441.            }
  442.  
  443.            else
  444.            {
  445.                pictureBox27.BackColor = Color.Black;
  446.            }
  447.        }
  448.  
  449.        private void pictureBox28_Click(object sender, EventArgs e)
  450.        {
  451.            if (pictureBox28.BackColor == Color.Black)
  452.            {
  453.                pictureBox28.BackColor = Color.Lime;
  454.            }
  455.  
  456.            else
  457.            {
  458.                pictureBox28.BackColor = Color.Black;
  459.            }
  460.        }
  461.  
  462.        private void pictureBox29_Click(object sender, EventArgs e)
  463.        {
  464.            if (pictureBox29.BackColor == Color.Black)
  465.            {
  466.                pictureBox29.BackColor = Color.Lime;
  467.            }
  468.  
  469.            else
  470.            {
  471.                pictureBox29.BackColor = Color.Black;
  472.            }
  473.        }
  474.  
  475.        private void pictureBox30_Click(object sender, EventArgs e)
  476.        {
  477.            if (pictureBox30.BackColor == Color.Black)
  478.            {
  479.                pictureBox30.BackColor = Color.Lime;
  480.            }
  481.  
  482.            else
  483.            {
  484.                pictureBox30.BackColor = Color.Black;
  485.            }
  486.        }
  487.  
  488.        private void pictureBox31_Click(object sender, EventArgs e)
  489.        {
  490.            if (pictureBox31.BackColor == Color.Black)
  491.            {
  492.                pictureBox31.BackColor = Color.Lime;
  493.            }
  494.  
  495.            else
  496.            {
  497.                pictureBox31.BackColor = Color.Black;
  498.            }
  499.        }
  500.  
  501.        private void pictureBox32_Click(object sender, EventArgs e)
  502.        {
  503.            if (pictureBox32.BackColor == Color.Black)
  504.            {
  505.                pictureBox32.BackColor = Color.Lime;
  506.            }
  507.  
  508.            else
  509.            {
  510.                pictureBox32.BackColor = Color.Black;
  511.            }
  512.        }
  513.  
  514.        private void pictureBox33_Click(object sender, EventArgs e)
  515.        {
  516.            if (pictureBox33.BackColor == Color.Black)
  517.            {
  518.                pictureBox33.BackColor = Color.Lime;
  519.            }
  520.  
  521.            else
  522.            {
  523.                pictureBox33.BackColor = Color.Black;
  524.            }
  525.        }
  526.  
  527.        private void pictureBox34_Click(object sender, EventArgs e)
  528.        {
  529.            if (pictureBox34.BackColor == Color.Black)
  530.            {
  531.                pictureBox34.BackColor = Color.Lime;
  532.            }
  533.  
  534.            else
  535.            {
  536.                pictureBox34.BackColor = Color.Black;
  537.            }
  538.        }
  539.  
  540.        private void pictureBox35_Click(object sender, EventArgs e)
  541.        {
  542.            if (pictureBox35.BackColor == Color.Black)
  543.            {
  544.                pictureBox35.BackColor = Color.Lime;
  545.            }
  546.  
  547.            else
  548.            {
  549.                pictureBox35.BackColor = Color.Black;
  550.            }
  551.        }
  552.    }
  553. }
  554.  
  555.  

¿Cuál es la mejor forma de codearlo?


Saludo.


En línea

seba123neo


Desconectado Desconectado

Mensajes: 3.621



Ver Perfil WWW
Re: Información en int, hex y bin dentro de un Form
« Respuesta #1 en: 20 Agosto 2014, 20:31 pm »

la mejor forma es hacer todo dinamico en tiempo de ejecucion.

o sea crear los controles "al vuelo" y asignarle sus eventos, sino te queda un monton de codigo.

creas los picturebox con un simple bucle for de 1 a 50 o lo que sea, ahi vas creandolos y posicionando en el form, luego le creas un addhandler para el evento click de cada uno, y todos los clicks van a entrar por el mismo manejador del evento.

te quedaria un codigo de no mas de 20 lineas para todo y el dia que quieras agregar mas controles no te va a afectar en nada.

la segunda opcion y mas "profesional" digamos es hacerlo "sin controles en absoluto", tendrias que "pintar" los cuadrados en el form, y el evento mousemove y click del form se encargaria de reconocer el color, etc.. te quedaria mas chico el codigo todavia y sin obejetos.

cualquiera de las 2 opciones es facil.

saludos.


En línea

Meta


Desconectado Desconectado

Mensajes: 3.438



Ver Perfil WWW
Re: Información en int, hex y bin dentro de un Form
« Respuesta #2 en: 20 Agosto 2014, 23:27 pm »

Hola:

Gracias por responder, pero las opciones se me escapa de mis conocimientos. Voy haber si lo pillo. Quiero crear 35 pictureBox, me imagino que con un for se podrá hacer.
Código
  1.        for (int i = 1; i <= 5; i++)
  2.        {
  3.            Console.WriteLine(i);
  4.        }

Por ahora, el como lo tengo hecho a pesar de tener mucho código, no me importa, pensando bien. Quiero continuar una cosa que no me sale.



Fijándome justo la imagen de arriba, al pinchar los pictureBox quiero que aparezcan en tiempo real los resultados en Decimales, Hexadecimales y Binarios. El tiempo real quiero decir, que desde que pulse un pictureBox, se actualiza los datos dentro de los textBox inficado arriba. Con usar timer de 0.1 segundo funciona en vez de usar un botón para actualizar.

Espero que se entienda lo que quiero hacer. Esta parte si que no me sale.

Saludo.
En línea

Eleкtro
Ex-Staff
*
Conectado Conectado

Mensajes: 9.813



Ver Perfil
Re: Información en int, hex y bin dentro de un Form
« Respuesta #3 en: 21 Agosto 2014, 09:42 am »

¿Cuál es la mejor forma de codearlo?[/b]

Pues hombre... agregar 35 controles y usar 35 event-handlers para suscribirte al mismo evento desde luego que no es lo más eficiente, se puede reducir mucho el código para que sea siendo dinámico como dijo el compañero seba123neo, pero seguiría habiendo 35 controles en la UI, hay otras formas de hacerlo de forma dinámica (como también te explicó seba123neo).

Mi consejo:

1. Utiliza solo 1 picturebox de fondo, y para todo lo demás utiliza las classes de GDI+.

2. Dibuja una rejilla del tamaño deseado sobre el picturebox, con las columnas y filas deseadas, en el evento Paint del picturebox.

3. Crea 1 Rectangle por cada sector de la rejilla, y así ya tienes una referencia de cada sector de la rejilla con su respectiva localización y tamaño a la que puedes acceder en cualquier momento.

4. En este punto ya se supone que deberías haber obtenido una coleción de los sectores de la rejilla( te sugiero añadirlos a una List(Of Rectangle) ),
    así que solo tienes que suscribirte a los eventos del Mouse (MouseMove y MouseClick) del PictureBox donde harás las operaciones necesarias (como por ejemplo especificar en que sector de la rejilla se hizo click, y el color despues de hacer click, etc), fin del problema.


Te muestro un ejemplo:



En ese ejemplo solo utilicé 1 picturebox con el fondo negro (aunque un picturebox tampoco es totalmente necesario pero facilita un poco la tarea), dibujé la rejilla con Pens, y para todo lo demás utilicé Rectangle, siguiendo los pasos que te he explicado.





No voy a mostrar todo el trabajo porque la idea es que aprendas a hacerlo pro ti mismo, y además, yo lo hice en VB.NET, peor te dejo una ayudita por si te sirve (lo puedes traducir a C# en convertidores online):

Este método lo escribí para dibujar los márgenes del grid (lo debes utilizar en el evento Paint):

Código
  1.    ' Draw Grid
  2.    ' By Elektro
  3.    '
  4.    ''' <summary>
  5.    ''' Draws a grid in the specified <see cref="System.Drawing.Graphics"/> space.
  6.    ''' </summary>
  7.    ''' <param name="g">Indicates the <see cref="System.Drawing.Graphics"/> object.</param>
  8.    ''' <param name="GridSize">Indicates the size of the grid.</param>
  9.    ''' <param name="Columns">Indicates the amount of columns to draw.</param>
  10.    ''' <param name="Rows">Indicates the amount of rows to draw.</param>
  11.    ''' <param name="ColorColumns">Indicates the columns color.</param>
  12.    ''' <param name="ColorRows">Indicates the rows color.</param>
  13.    ''' <param name="DrawBorder">If set to <c>true</c>, a border is drawn on the grid edges.</param>
  14.    ''' <param name="ColorBorder">Indicates the border color. Default value is the same color as <param ref="ColorColumns"/></param>
  15.    ''' <param name="ColorStyle">Indicates the colors <see cref="System.Drawing.Drawing2D.DashStyle"/>.</param>
  16.    ''' <exception cref="System.ArgumentException">
  17.    ''' GridSize.Width is not divisible by the specified number of columns.
  18.    ''' or
  19.    ''' GridSize.Height is not divisible by the specified number of rows.
  20.    ''' </exception>
  21.    Private Sub DrawGrid(ByVal g As Graphics,
  22.                         ByVal GridSize As Size,
  23.                         ByVal Columns As Integer,
  24.                         ByVal Rows As Integer,
  25.                         ByVal ColorColumns As Color,
  26.                         ByVal ColorRows As Color,
  27.                         Optional ByVal DrawBorder As Boolean = True,
  28.                         Optional ByVal ColorBorder As Color = Nothing,
  29.                         Optional ByVal ColorStyle As Drawing2D.DashStyle = Drawing2D.DashStyle.Solid)
  30.  
  31.        If Not (GridSize.Width Mod Columns = 0I) Then
  32.            Throw New ArgumentException(
  33.                "GridSize.Width is not divisible by the specified number of columns.",
  34.                "GridSize")
  35.            Exit Sub
  36.  
  37.        ElseIf Not (GridSize.Height Mod Rows = 0I) Then
  38.            Throw New ArgumentException(
  39.                "GridSize.Height is not divisible by the specified number of rows.",
  40.                "GridSize")
  41.            Exit Sub
  42.  
  43.        End If
  44.  
  45.        Dim SectorWidth As Integer = (GridSize.Width \ Columns)
  46.        Dim SectorHeight As Integer = (GridSize.Height \ Rows)
  47.  
  48.        Using PenRow As New Pen(ColorRows) With {.DashStyle = ColorStyle}
  49.  
  50.            Using PenCol As New Pen(ColorColumns) With {.DashStyle = ColorStyle}
  51.  
  52.                For row As Integer = 0I To GridSize.Height - 1 Step (SectorHeight)
  53.  
  54.                    For col As Integer = 0I To GridSize.Width - 1 Step SectorWidth
  55.  
  56.                        ' Draw the vertical grid-lines.
  57.                        g.DrawLine(PenCol,
  58.                                   New Point(x:=col - 1, y:=0I),
  59.                                   New Point(x:=col - 1, y:=GridSize.Height))
  60.  
  61.                    Next col
  62.  
  63.                    ' Draw the horizontal grid-lines.
  64.                    g.DrawLine(PenRow,
  65.                               New Point(x:=0I, y:=row - 1),
  66.                               New Point(x:=GridSize.Width, y:=row - 1))
  67.  
  68.                Next row
  69.  
  70.                If DrawBorder Then
  71.  
  72.                    Using PenBorder As New Pen(If(ColorBorder = Nothing, ColorColumns, ColorBorder)) With {.DashStyle = ColorStyle}
  73.  
  74.                        ' Draw the vertical left grid-line.
  75.                        g.DrawLine(PenBorder,
  76.                                   New Point(x:=0, y:=0I),
  77.                                   New Point(x:=0, y:=GridSize.Height))
  78.  
  79.                        ' Draw the vertical right grid-line.
  80.                        g.DrawLine(PenBorder,
  81.                                   New Point(x:=(GridSize.Width - 1I), y:=0I),
  82.                                   New Point(x:=(GridSize.Width - 1I), y:=GridSize.Height))
  83.  
  84.                        ' Draw the horizontal top grid-line.
  85.                        g.DrawLine(PenBorder,
  86.                                   New Point(x:=0I, y:=0I),
  87.                                   New Point(x:=GridSize.Width, y:=0I))
  88.  
  89.                        ' Draw the horizontal bottom grid-line.
  90.                        g.DrawLine(PenBorder,
  91.                                   New Point(x:=0I, y:=(GridSize.Height - 1I)),
  92.                                   New Point(x:=GridSize.Width, y:=(GridSize.Height - 1I)))
  93.                    End Using ' PenBorder
  94.  
  95.                End If ' DrawBorder
  96.  
  97.            End Using '  PenCol
  98.  
  99.        End Using ' PenRow
  100.  
  101.    End Sub


Y este método lo escribí para obtener los rectangles de la rejilla:

Código
  1.    ' Get Grid
  2.    ' By Elektro
  3.    '
  4.    ''' <summary>
  5.    ''' Calculates the drawing of a grid with the specified size,
  6.    ''' and returns a<see cref="List(Of Rectangle)"/> that contains the grid-sector specifications.
  7.    ''' </summary>
  8.    ''' <param name="GridSize">Indicates the grid size.</param>
  9.    ''' <param name="Columns">Indicates the amount of columns.</param>
  10.    ''' <param name="Rows">Indicates the amount of rows.</param>
  11.    ''' <returns>A <see cref="List(Of Rectangle)"/> that contains the grid-sector specifications.</returns>
  12.    ''' <exception cref="System.ArgumentException">
  13.    ''' GridSize.Width is not divisible by the specified number of columns.
  14.    ''' or
  15.    ''' GridSize.Height is not divisible by the specified number of rows.
  16.    ''' </exception>
  17.    Private Function GetGrid(ByVal GridSize As Size,
  18.                             ByVal Columns As Integer,
  19.                             ByVal Rows As Integer) As List(Of Rectangle)
  20.  
  21.        If Not (GridSize.Width Mod Columns = 0I) Then
  22.            Throw New ArgumentException(
  23.                "GridSize.Width is not divisible by the specified number of columns.",
  24.                "GridSize")
  25.            Return Nothing
  26.  
  27.        ElseIf Not (GridSize.Height Mod Rows = 0I) Then
  28.            Throw New ArgumentException(
  29.                "GridSize.Height is not divisible by the specified number of rows.",
  30.                "GridSize")
  31.            Return Nothing
  32.  
  33.        End If
  34.  
  35.        Dim Sectors As New List(Of Rectangle)
  36.        Dim SectorWidth As Integer = GridSize.Width \ Columns
  37.        Dim SectorHeight As Integer = GridSize.Height \ Rows
  38.  
  39.        For row As Integer = 0I To GridSize.Height - 1 Step (SectorHeight)
  40.  
  41.            For col As Integer = 0I To GridSize.Width - 1 Step SectorWidth
  42.  
  43.                Sectors.Add(New Rectangle(col, row, SectorWidth, SectorHeight))
  44.  
  45.            Next col
  46.  
  47.        Next row
  48.  
  49.        Return Sectors
  50.  
  51.    End Function


EDITO2:

bueno voy a mostrate el resto del código porque total lo hice para ayudarte con el problema y ya no me sirve para nada esto así que antes de tirarlo te lo enseño xD, espero que te sirva.

( esta parte del code lo desarrollé en poco tiempo, está bastante sucio el código y se puede mejorar mucho, pero sirve para hacerse una idea )

Código
  1.    Public Property currentsector As Integer = 0
  2.    Public Property currentcolor As Color = Color.Gray
  3.  
  4.    Public ReadOnly Property GridSectors As List(Of Rectangle)
  5.        Get
  6.            Return Me.GetGrid(GridSize:=PictureBox1.ClientRectangle.Size, Columns:=5, Rows:=5)
  7.        End Get
  8.    End Property
  9.  
  10.    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Shown
  11.  
  12.        Label1.Text = "Sectors: " & GridSectors.Count
  13.  
  14.    End Sub
  15.  
  16.    Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As PaintEventArgs) _
  17.    Handles PictureBox1.Paint
  18.  
  19.  
  20.        Me.DrawGrid(g:=e.Graphics,
  21.                    GridSize:=sender.ClientRectangle.Size,
  22.                    Columns:=5,
  23.                    Rows:=5,
  24.                    ColorColumns:=Color.YellowGreen,
  25.                    ColorRows:=Color.YellowGreen,
  26.                    DrawBorder:=True,
  27.                    ColorBorder:=Nothing,
  28.                    ColorStyle:=Drawing2D.DashStyle.Solid)
  29.  
  30.    End Sub
  31.  
  32.    Private Sub PictureBox1_MouseMove(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseMove
  33.  
  34.        Dim Sectors As List(Of Rectangle) = Me.GridSectors
  35.  
  36.        For X As Integer = 0I To (Sectors.Count - 1I)
  37.  
  38.            If Sectors(X).Contains(sender.PointToClient(MousePosition)) Then
  39.  
  40.                Dim myBrush As New SolidBrush(currentcolor)
  41.  
  42.                Using formGraphics As Graphics = sender.CreateGraphics()
  43.  
  44.                    formGraphics.FillRectangle(myBrush, New Rectangle(Sectors(X).X + 1, Sectors(X).Y + 1, Sectors(X).Width - 2, Sectors(X).Height - 2))
  45.                    myBrush.Dispose()
  46.  
  47.                End Using ' formGraphics
  48.                currentsector = X + 1
  49.                Label2.Text = "Current sector: " & currentsector
  50.  
  51.            Else
  52.                Dim myBrush As New SolidBrush(Color.Black)
  53.  
  54.                Using formGraphics As Graphics = sender.CreateGraphics()
  55.  
  56.                    formGraphics.FillRectangle(myBrush, New Rectangle(Sectors(X).X + 1, Sectors(X).Y + 1, Sectors(X).Width - 2, Sectors(X).Height - 2))
  57.                    myBrush.Dispose()
  58.  
  59.                End Using ' formGraphics
  60.            End If ' Sectors(X).Contains(...)
  61.  
  62.        Next X
  63.  
  64.    End Sub
  65.  
  66.    Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.MouseDown
  67.  
  68.        Label3.Text = "Last Sector Clicked: " & currentsector
  69.  
  70.        '  Dim sector As Rectangle = Me.GridSectors(currentsector - 1)
  71.        currentcolor = Color.Red
  72.        PictureBox1.Cursor = Cursors.Hand
  73.        PictureBox1.Update()
  74.  
  75.        'Dim myBrush As New SolidBrush(Color.Red)
  76.  
  77.        'Using formGraphics As Graphics = PictureBox1.CreateGraphics()
  78.  
  79.        '    formGraphics.FillRectangle(myBrush, New Rectangle(sector.X + 1, sector.Y + 1, sector.Width - 2, sector.Height - 2))
  80.        '    myBrush.Dispose()
  81.  
  82.        'End Using ' formGraphics
  83.  
  84.    End Sub
  85.  
  86.    Private Sub PictureBox1_Clic(sender As Object, e As EventArgs) Handles PictureBox1.MouseUp
  87.        Label3.Text = "Last Sector Clicked: " & currentsector
  88.  
  89.        '  Dim sector As Rectangle = Me.GridSectors(currentsector - 1)
  90.        currentcolor = Color.Gray
  91.        PictureBox1.Cursor = Cursors.Default
  92.        PictureBox1.Update()
  93.  
  94.        'Dim myBrush As New SolidBrush(Color.Red)
  95.  
  96.        'Using formGraphics As Graphics = PictureBox1.CreateGraphics()
  97.  
  98.        '    formGraphics.FillRectangle(myBrush, New Rectangle(sector.X + 1, sector.Y + 1, sector.Width - 2, sector.Height - 2))
  99.        '    myBrush.Dispose()
  100.  
  101.        'End Using ' formGraphics
  102.  
  103.    End Sub




EDITO1:


Fijándome justo la imagen de arriba, al pinchar los pictureBox quiero que aparezcan en tiempo real los resultados en Decimales, Hexadecimales y Binarios.

El tiempo real quiero decir, que desde que pulse un pictureBox, se actualiza los datos dentro de los textBox inficado arriba.

Con usar timer de 0.1 segundo funciona en vez de usar un botón para actualizar.

Espero que se entienda lo que quiero hacer. Esta parte si que no me sale.

Lo siento creo que no te entendí muy bien, ¿que problema tienes actualmente a la hora de actualizar los valores de cada control?.

Si vas a utilizar tropecientos pictureboxes entonces deberías suscribirte al evento Click como te explicó seba123neo, y una vez pulses cualquier picturebox actualizaríass los valores (de forma interna) y los imprimirías en los textboxes, ¿cual es el problema?

Saludos
« Última modificación: 21 Agosto 2014, 10:28 am por Eleкtro » En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Abrir Soft dentro de mi Form..
Programación Visual Basic
Pitoniso 7 4,786 Último mensaje 24 Noviembre 2006, 06:01 am
por -POLACO-
Redimensionar componente dentro de form
.NET (C#, VB.NET, ASP)
NetJava 2 2,890 Último mensaje 17 Noviembre 2011, 10:21 am
por NetJava
Mostrar error de Login dentro de Form
PHP
KeyPy HH 7 14,255 Último mensaje 24 Septiembre 2012, 06:00 am
por jdc
Hacer Form visible dentro de dll. « 1 2 »
.NET (C#, VB.NET, ASP)
70N1 12 7,155 Último mensaje 7 Diciembre 2012, 15:23 pm
por 70N1
Abrir Chrome dentro de un form
Programación Visual Basic
NsTeam 4 8,572 Último mensaje 3 Febrero 2015, 13:49 pm
por okik
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines