Thursday, 29 September 2011

Picture Viewer using C#

Here I am trying to create a picture viewer application using C# in Visual studio 2008.Through this application we can view and  can convert images from one type to another.

Create a windows application and name it as PictureViewer.Then add openFileDialog, saveFileDialog,panel, pictureBox,menuStrip and three buttons to the form and name it as I did.Add three menu items and name as Open,Save As and Exit.Then our UI will look like this.


Open
When we click Open in File menu, an openFileDialog will come and we can select the image we want to  open.For this add following code to the click event of Open.


OpenImage() function is shown below.

















Save As
Add the following code to the click event of Save As

Function SaveImage() is shown below.


Function for SaveAsType() is shown below.

Rotate clockwise and anticlockwise
The following is the function for rotating an image.
Add the following code to click event of  Rotate clockwise button.



Add the following code to click event of  Rotate Anticlockwise button.

   
Next
To view the next image in the folder,add the following code to the click event of Next button.
Our project is finished and run the code by pressing F5 and open an image.then our application wil looks like this.




Thursday, 1 September 2011

Validating a textbox control


In this application I’m validating a textbox by allowing only number to enter.
Create a windows application with a textbox control as shown in fig below.







Here what we do is add some code in keyPress event of the textbox control, which  will show a message when we enter a wrong data.Add the following code in the keyPress event of the textbox control









ValidateNumber(e.KeyChar) function is shown below


















Run the project and enter an alphabet,it will show a message box as shown below