Advertisement
Renzott

picturebox_Paint

Dec 13th, 2019
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.11 KB | None | 0 0
  1. using System.Drawing;
  2. using System.Windows.Forms;
  3.  
  4. namespace WindowsFormsApp2
  5. {
  6.     public partial class Form1 : Form
  7.     {
  8.  
  9.         //Instancio el string
  10.         string text;
  11.  
  12.         //Creacion del Form
  13.         public Form1()
  14.         {
  15.  
  16.             //Doy Valor al string antes de visualizar todo el form
  17.             text = "Domire";
  18.  
  19.             InitializeComponent();
  20.         }
  21.  
  22.         private void picturebox_Paint(object sender, PaintEventArgs e)
  23.         {
  24.             // Creo un Font de base para el Texto
  25.             using (Font myFont = new Font("Arial Black", 34))
  26.             {
  27.  
  28.                 // Agarro el Width y Height de la imagen
  29.  
  30.                 int width = e.ClipRectangle.Width;
  31.                 int height = e.ClipRectangle.Height;
  32.  
  33.                 // Creo un Graphics para calcular el Width y Height del texto
  34.                 SizeF size = CreateGraphics().MeasureString(text,myFont);
  35.  
  36.                 // Doy los valores a la imagen
  37.                 e.Graphics.DrawString(text, myFont, Brushes.White, (width-size.Width)/2,height- size.Height);
  38.             }
  39.         }
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement