ARTICLE

Buton Viewer: View Images

Posted by Mahesh Chand Articles | Windows Forms C# February 27, 2001
Well, In .NET, the Image class is a wonderful class to view images. No matter what control you have, you just set the Image property of that control to an image and the control will display the image. Neat?
Reader Level:
Download Files:
 

Description:

You must be wondering what the hell is this ButtonViewer? Well, In .NET, the Image class is a wonderful class to view images. No matter what control you have, you just set the Image property of that control to an image and the control will display the image. Neat?

In this sample, the Browse button let you browse the the dir to pick an image (It won't display any thing else but an image, so don't try text or other files).



Source Code:

Setting Image property of a button displays an image.

protected void button1_Click_1 (object sender, System.EventArgs e)
{
OpenFileDialog fdlg =
new OpenFileDialog();
fdlg.Title = "C# Corner Open File Dialog" ;
fdlg.InitialDirectory = @"c:\" ;
fdlg.Filter = "All files (*.*)|*.*|All files (*.*)|*.*" ;
fdlg.FilterIndex = 2 ;
fdlg.RestoreDirectory =
true ;
if(fdlg.ShowDialog() == DialogResult.OK)
{
button2.Image = Image.FromFile(fdlg.FileName) ;
}
Invalidate();
}

Login to add your contents and source code to this article
post comment
     
COMMENT USING
PREMIUM SPONSORS
DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and add new content to existing PDF documents from within your applications.
Join a Chapter
SPONSORED BY
  • PDF reports have never been easier to create. With our included WYSIWYG Designer, you can layout your reports, set up your data source and let DynamicPDF ReportWriter do the rest.