Deprecated: Assigning the return value of new by reference is deprecated in /home/controlz/public_html/blog/wp-settings.php on line 472

Deprecated: Assigning the return value of new by reference is deprecated in /home/controlz/public_html/blog/wp-settings.php on line 487

Deprecated: Assigning the return value of new by reference is deprecated in /home/controlz/public_html/blog/wp-settings.php on line 494

Deprecated: Assigning the return value of new by reference is deprecated in /home/controlz/public_html/blog/wp-settings.php on line 530

Strict Standards: Declaration of Walker_Page::start_lvl() should be compatible with Walker::start_lvl(&$output) in /home/controlz/public_html/blog/wp-includes/classes.php on line 594

Strict Standards: Declaration of Walker_Page::end_lvl() should be compatible with Walker::end_lvl(&$output) in /home/controlz/public_html/blog/wp-includes/classes.php on line 594

Strict Standards: Declaration of Walker_Page::start_el() should be compatible with Walker::start_el(&$output) in /home/controlz/public_html/blog/wp-includes/classes.php on line 594

Strict Standards: Declaration of Walker_Page::end_el() should be compatible with Walker::end_el(&$output) in /home/controlz/public_html/blog/wp-includes/classes.php on line 594

Strict Standards: Declaration of Walker_PageDropdown::start_el() should be compatible with Walker::start_el(&$output) in /home/controlz/public_html/blog/wp-includes/classes.php on line 611

Strict Standards: Declaration of Walker_Category::start_lvl() should be compatible with Walker::start_lvl(&$output) in /home/controlz/public_html/blog/wp-includes/classes.php on line 705

Strict Standards: Declaration of Walker_Category::end_lvl() should be compatible with Walker::end_lvl(&$output) in /home/controlz/public_html/blog/wp-includes/classes.php on line 705

Strict Standards: Declaration of Walker_Category::start_el() should be compatible with Walker::start_el(&$output) in /home/controlz/public_html/blog/wp-includes/classes.php on line 705

Strict Standards: Declaration of Walker_Category::end_el() should be compatible with Walker::end_el(&$output) in /home/controlz/public_html/blog/wp-includes/classes.php on line 705

Strict Standards: Declaration of Walker_CategoryDropdown::start_el() should be compatible with Walker::start_el(&$output) in /home/controlz/public_html/blog/wp-includes/classes.php on line 728

Strict Standards: Redefining already defined constructor for class wpdb in /home/controlz/public_html/blog/wp-includes/wp-db.php on line 306

Deprecated: Assigning the return value of new by reference is deprecated in /home/controlz/public_html/blog/wp-includes/cache.php on line 103

Strict Standards: Redefining already defined constructor for class WP_Object_Cache in /home/controlz/public_html/blog/wp-includes/cache.php on line 425

Deprecated: Assigning the return value of new by reference is deprecated in /home/controlz/public_html/blog/wp-includes/query.php on line 21

Deprecated: Assigning the return value of new by reference is deprecated in /home/controlz/public_html/blog/wp-includes/theme.php on line 623

Strict Standards: Redefining already defined constructor for class WP_Dependencies in /home/controlz/public_html/blog/wp-includes/class.wp-dependencies.php on line 15

Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /home/controlz/public_html/blog/wp-settings.php:472) in /home/controlz/public_html/blog/wp-content/plugins/si-captcha-for-wordpress/si-captcha.php on line 31

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/controlz/public_html/blog/wp-settings.php:472) in /home/controlz/public_html/blog/wp-content/plugins/si-captcha-for-wordpress/si-captcha.php on line 31

Strict Standards: call_user_func_array() expects parameter 1 to be a valid callback, non-static method GoogleSitemapGeneratorLoader::Enable() should not be called statically in /home/controlz/public_html/blog/wp-includes/plugin.php on line 311
Graficos | formatic.cat

Entradas con la etiqueta ‘graficos’

GDI+, Gráficos en Visual Basic 2005 .NET

Miércoles, 1 de Octubre de 2008

GDI + es la forma de dibujar formas, fuentes, imágenes o cualquier tipo de gráficos en general, en Visual Basic NET.

Primero vamos a crear un nuevo Panel. Ya sabéis, en modo diseño:

 Cuadro de Herramientas->Contenedores->Panel.

También haremos doble click sobre el nuevo Panel creado para que nos haga una declaracion del procedimiento que vamos a utilizar. Que será este:

Sub Panel1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint

‘aquí el código

End Sub

Bien, lo primero que nos toca hacer es crear las variables que nos permitan ‘dibujar’ en el Panel, vamos a utilizar Graphics, Pen y Point.

Dim grafico As Graphics = e.Graphics
Dim p1 As Point
Dim p2 As Point
Dim punta As Pen

Para dibujar una linea en un plano, Visual Basic 2005 .NET necesita saber donde empieza, donde acaba, y como dibujarla.
Eso lo conseguimos con las variables del tipo Point y Pen.Ahora que ya sabemos esto, vamos a inicializar dichas variables: 

 

punta = New Pen(Color.Aqua,1) ‘un ‘lapiz’ del color Aqua
p1 = New Point(0, 1) ‘Point(x,y)
p2 = New Point(10, 11) ‘Point(x,y)

 Al lado, en comentario, he puesto lo que seria el contructor necesario. En los Point no hay mucho misterio, se crean dos puntos, P1(inicio) y P2(final), en un plano, que sera la traza que hara la linea, y se inicializa la variable punta con un Pen del tipo Aqua, que sera azul cian de 1 pixel de grosor.

 Con todo esto solo nos quedaria trazar la linea sobre el Panel.

grafico.DrawLine(punta, p1, p2) ‘ drawline(Pens.Azure,x1,y1,x2,y2)

 

grafico.DrawLine(punta, p1, p2) ‘ drawline(Pens.Azure,x1,y1,x2,y2)

 

Grafico es la variable que hemos declarado e igualado a e.Graphics, recordad que la variable ‘e’ viene siendo algo asi como las propiedades del Panel.
Sobre la clase Graphics hay una serie de métodos para dibujar, en este caso una línea, a la cual le pasamos las variables que antes he comentado, la variable ‘punta’ que contiene el grosor y tipo de pincel, y los puntos p1 y p2, inicio y fin de la linea. En comentarios teneis la declaracion sin tanta variable de por medio, los dos metodos son buenos.