Draw right justified text : Text Justify : Graphics C# Source Code


Custom Search

C# Source Code » Graphics » Text Justify »

 

Draw right justified text









    

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

public class Form1 : System.Windows.Forms.Form{
  public Form1()
  {
        InitializeComponent();
        SetStyle(ControlStyles.Opaque, true);
        Bounds = new Rectangle(0, 0, 500, 300);
  }

    protected override void OnPaint(PaintEventArgs e) {
         Graphics g = e.Graphics;
   
         g.FillRectangle(Brushes.White, ClientRectangle);


         // Draw right justified text
         Font aFont = new Font("Arial", 16, FontStyle.Bold | FontStyle.Italic);
         Rectangle rect = new Rectangle(0, 0, 400, aFont.Height);
         g.DrawRectangle(Pens.Blue, rect);
         
         StringFormat sf = new StringFormat();
         sf.Alignment = StringAlignment.Far;
         g.DrawString("www.navioo.com", aFont, Brushes.Blue,
            rect, sf);

      }

    private void InitializeComponent()
    {
      this.Size = new System.Drawing.Size(300,300);
      this.Text = "Form1";
    }
    static void Main() 
    {
      Application.Run(new Form1());
    }
}



           
       
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Graphics
» Text Justify