C sharp - control para dibujar graficos

 
Vista:

control para dibujar graficos

Publicado por Marcelo Arguello (4 intervenciones) el 14/11/2012 15:49:49
Hola necesito poner en un form un control que me permita dibujar.

En java heredo de Jcomponent,
Que tengo que hacer en csharp, heredar de System.Windows.Forms.Control

Alguien tiene un ejemplo
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

control para dibujar graficos

Publicado por Marcelo Arguello (4 intervenciones) el 18/11/2012 23:54:04
Me contesto a mi mismo:

Efectivamente se hereda de Control

public class Lienzo : Control

y para dibujar se hace:

1
2
3
4
5
6
7
8
9
public void DrawLine(int Ax,int Ay,int Bx, int By)
		 {
				Pen myPen = new Pen(System.Drawing.Color.Red);
				Graphics CompGraphics;
				CompGraphics = this.CreateGraphics();
				CompGraphics.DrawLine(myPen, Ax, Ay, Bx, By);
				myPen.Dispose();
				CompGraphics.Dispose();
	        }


tambien podemos dibujar en un bitmap y luego mostrarlo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
public void PaintEffect()
	  {
				Bitmap myBitmap  = new Bitmap(Width,Height);
				//Bitmap myBitmap  = new Bitmap(200, 200);//Creo una imagen y luego creo un manejador de la parte grafica
				Graphics flagGraphics = Graphics.FromImage(myBitmap ); //manejador de la parte grafica del bitmap
				int red = 0;
				int white = 11;
					while (white <= 100) {
						flagGraphics.FillRectangle(Brushes.Red, 0, red, 200,10);
						flagGraphics.FillRectangle(Brushes.White, 0, white, 200, 10);
						red += 20;white += 20;
					}
 
				Graphics CompGraphics = this.CreateGraphics();
			    CompGraphics.DrawImage(myBitmap,0,0); 	// Draw image to bitmap		
			    CompGraphics.Dispose();
				flagGraphics.Dispose();


espero que les sirva
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar