Bueno, les comento mi duda.
Necesito imprimir el contenido de un PictureBox, pero... lo que hay dentro no es una imagen. Simplemente uso el PictureBox como contenedor.
Lo que necesito imprimir es lo que dibujo dentro de el.
Con este codigo dibujo el grafico:
Private Sub Pic_Graf1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Pic_Graf1.Paint
Dim Superficie As Graphics
Dim Lapiz As Pen
Dim RectanguloSuperior As Rectangle
Dim RectanguloInferior As Rectangle
Dim RectanguloRelleno As Rectangle
Dim Relleno As SolidBrush
Dim Fuente As Font
If ActivateGraph_1 = False Then
Pic_Graf1.Image = My.Resources._50px_error
Me.Refresh()
Exit Sub
Else
Pic_Graf1.Image = Nothing
End If
Superficie = e.Graphics
Lapiz = New Pen(Color.Black, 2)
Relleno = New SolidBrush(Color.Gray)
Fuente = New Font("Arial", 12, FontStyle.Bold)
RectanguloSuperior = New Rectangle(5, 5, 100, 50)
RectanguloInferior = New Rectangle(5, 15, 100, 50)
RectanguloRelleno = New Rectangle(10, 30, 95, 15)
Superficie.FillRectangle(Relleno, RectanguloRelleno)
Superficie.FillEllipse(Relleno, RectanguloInferior)
Dim Valor1 As Integer = iPorcent_1_1
Dim Valor2 As Integer = iPorcent_1_2
Dim Valor3 As Integer = iPorcent_1_3
Dim Valor4 As Integer = iPorcent_1_4
Dim Porcent1 As Integer
Dim Porcent2 As Integer
Dim Porcent3 As Integer
Dim Porcent4 As Integer
Porcent1 = (Valor1 * 360) / 100
Porcent2 = ((Valor2 * 360) / 100)
Porcent3 = ((Valor3 * 360) / 100)
Porcent4 = ((Valor4 * 360) / 100)
'Rellena las secciones con diferentes colores
Relleno.Color = pic_ref1.BackColor
Superficie.FillPie(Relleno, RectanguloSuperior, 0, Porcent1)
Relleno.Color = pic_ref2.BackColor
Superficie.FillPie(Relleno, RectanguloSuperior, Porcent1, Porcent2)
Relleno.Color = pic_ref3.BackColor
Superficie.FillPie(Relleno, RectanguloSuperior, Porcent1 + Porcent2, Porcent3)
Relleno.Color = pic_ref4.BackColor
Superficie.FillPie(Relleno, RectanguloSuperior, Porcent1 + Porcent2 + Porcent3, Porcent4)
End Sub
Y ahora... lo que yo me pregunto... es como imprimo el grafico resultante?
Saludos.
hola, es sencillo de hacer:
Lo que tenes que imprimir esta dibujado sobre el objeto Graphics del PictureBox, (que obtienes de e.Graphics) para tu caso se llama Supercifie, lo que hay que hacer entonces es asignar ese Graphics a la Imagen del PictureBox Como BitMap para obtener lo dibujado sobre la PictureBox ASI:
//Lo pongo en c# ya tu lo traduces.
//Aqui obtengo una bitmap tan grande como el PictureBox.
Bitmap Imagen = new BitMap(Pic_Graf1.Width,Pic_Graf1.Height);
//Le Asigno a la PictureBox el BitMap.
Pic_Graf1.Image = Imagen
//Obtenemos el objeto graphics del bitmap como se encuentra asociado a la picturebox sera equivalente a pintar sobre la picturebox.
Graphics g = Graphics.FromImage(Imagen);
//Pintas lo que sea sobre la picturebox( Aqui Estaria el Resto de Tu Logica).
Rectangle Rec = new Rectangle(0, 0, 100, 100);
Brush Lapiz = Brushes.Gold;
g.FillRectangle(Lapiz, Rec);
//Aqui Es Donde se Imprime.
//Debes Hacer Referencia a System.Drawing.Printing;
PrintDocument Doc = new PrintDocument();
//Suscribimos un Evento de Impresion.
Doc.PrintPage += new PrintPageEventHandler(Doc_PrintPage);
//Lanzamos el cuadro de impresoras.
PrintDialog Cuadro = new PrintDialog();
if(Cuadro.ShowDialog() == DialogResult.OK)
{
//Asignamos al documento los Settings Seleccionados En el cuadro de impresion (Como Impresora,Tamaño ETC).
Documento.PrinterSettings = Cuadro.PrinterSettings;
//Ahora Imprimimos el bitmap, este metodo desencadenara el anterior evento
Documento.Print();
}
--- este es el evento.
private void Doc_PrintPage(object sender, PrintPageEventArgs e)
{
//Aqui le decimos que imprima el BitMap que creamos arriba (Ojo por lo cual el BitMap debe ser Accesible desde Aqui).
e.Graphics.DrawImage(Imagen, 0, 0);
}
//Listo, si no quieres mostrar el cuadro de impresion, llama directamente a Doc.Print() y quita todo lo del if, sera impreso en la impresora predeterminada con los valores predeterminados.
Espero te sirva, el code no le he sacado de ningun lado asi que lo puedes usar con toda libertad.
PD: Si tienes problemas, postea.
Atentamente,
Juan Manuel Lombana
Medellín - Colombia