Load Image from an image file with Exception handler : Image : Graphics C# Source Code


Custom Search

C# Source Code » Graphics » Image »

 

Load Image from an image file with Exception handler








    
 


using System;
using System.Drawing;
using System.Windows.Forms;
   
class BetterImageFromFile:Form
{
     Image image;
   
     public static void Main()
     {
          Application.Run(new BetterImageFromFile());
          
     }
     protected override void OnPaint(PaintEventArgs pea)
     {
          DoPage(pea.Graphics, ForeColor,ClientSize.Width, ClientSize.Height);
     }     
     public BetterImageFromFile()
     {
          string strFileName = "Color.jpg";
          ResizeRedraw = true; 
          try
          {
               image = Image.FromFile(strFileName);
          }catch {
               MessageBox.Show("Cannot find file " + strFileName + "!",
                         Text, MessageBoxButtons.OK, MessageBoxIcon.Hand);
          }
     }
     protected void DoPage(Graphics grfx, Color clr, int cx, int cy)
     {
          if (image == null)
               return;
   
          grfx.DrawImage(image, 0, 0);
     }
}

 
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Graphics
» Image