Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> Creating A Simple Image Viewer, Using Visual Basic 2005 Express Edition
rvalkass
post Mar 11 2006, 06:48 PM
Post #1


apt-get moo
Group Icon

Group: [MODERATOR]
Posts: 2,053
Joined: 28-May 05
From: Hertfordshire, England
Member No.: 7,593
Spam Patrol



I downloaded Microsoft's Visual Studio Express suite a few months ago, but only recently got around to installing it. I have been practising with Visual Basic and making some rather basic programs and utilities, but they contain most of the basic concepts. This tutorial will explain how to create a basic image viewer, and I will try to explain each step from beginning to end as clear as I can.
To start you will need:
  • Microsoft Visual Studio
  • About 10-20 minutes free time

OK, first open up the Visual Basic part of the Studio. I am using the 2005 Express version, so some features may differ between versions, but most stuff should be relatively similar. Once it's loaded click File > New Project (or press Ctrl + N) to get the New Project dialog. Make sure you have Windows Application selected, and give the project a sensible name, then click OK.

IPB Image

Now the screen will show you a blank form. This is the basis of your application where all of your controls, buttons etc will be placed, and represents exactly what your end user will see. Click on the Toolbox button on the left hand side of the screen, and make sure you are viewing the All Windows Forms section. This pane lists all of the possible controls you can put into your application. Drag the one called PictureBox onto your form, and position it in the top left hand corner, like this:

IPB Image

Also drag a Button onto the form, and position it near the bottom border, roughly in the middle. Finally, drag on an OpenFileDialog, and position it anywhere on your form. You will notice that it doesn't appear in your application, but in a separate pane at the bottom of the screen. This pane contains all of the elements of your form that are not visible until you call them, or are permanently invisible, such as counters and timers. You now have all of the elements for your application, so you just need the code.

Double click on the button you dragged on earlier. The view switches to the programming view, as opposed to the designer view. A command is created that will be run when the button is clicked, and your cursor positioned ready to type the code. Copy or type the code below where the cursor is:

CODE

OpenFileDialog1.ShowDialog()


This will cause your dialog box to display when the button is clicked. Now we need the picture box to display your chosen image.

Right click in the code view, and select View Designer. Then double click the OpenFileDialog1 button at the bottom of the screen, and put this code where the cursor is.

CODE

path = New Bitmap(OpenFileDialog1.FileName)
PictureBox1.Image = path


We have now defined path as the filename chosen in the dialog box, and have set the picture box to display that image.
Notice that the word path has been underlined in blue? This is similar to the spelling and grammar mistakes in Word, and shows that you have failed to define something or have spelt something wrong. This is because we haven't defined path.

At the top of the code view you will notice the following line:
CODE

Public Class Form1


Below it, add this line:
CODE

Private path As Bitmap


We have now created a bitmap ready to display your image, and the blue underlines should disappear. Your project will now work, but if you click the little green Start Debugging 'play' button on the toolbar, and click your button to load an image you will notice a number of faults. Firstly, your Picture Box is far too small to display an image. Secondly the button is labelled Button1 and finally, the application is titled Form1. This shall all be fixed, along with a few extras.

Close your application, or click the Stop button, and then flick back to design view and click on the button we added earlier. Make sure you can see the Properties window, which is normally a panel on the right hand side. If not, push F4 and it should appear.

IPB Image

This Properties pane shows all of the settings and choices you can make concerning your button. If you scroll towards the bottom of the list you should see a property called Text. With virtually all of the controls you can add, Text is the text displayed on it, so with your button change this property so it says something like Load Image... and push enter. Click on the title bar of your form and change the text property again to something more logical than Form1, perhaps Image Viewer.

Now, to get your images to display properly within your picture box, we need to change some other settings. I will just list them here, but you can read up about them in more detail in the help section if you wish.
  • Anchor: Top, Left, Bottom, Right
  • BorderStyle: Fixed3D
  • SizeMode: Zoom

Finally we just need some positioning. Click on the picture box and drag it so it fills most of your form, leaving space at the bottom for the button. Then click on your button and resize it so that it displays all of your text, then click Format > Center In Form > Horizontally . Finally set the Anchor property of the button to Bottom.

Now click the Start Debugging button and there should be a vast improvement biggrin.gif To turn your application into a working, distributable .exe file, click on Build in the toolbar at the top, and then Build (Your Project Name). You have now created a .exe file, which can normally be found at the following path:

QUOTE

C:\Documents and Settings\Your Username\My Documents\Visual Studio 2005\Projects\Your Project Name\Your Project Name\bin\Release


Here is my finished product:

IPB Image
Go to the top of the page
 
+Quote Post
Cena_54
post Mar 12 2006, 02:01 PM
Post #2


Newbie [Level 3]
***

Group: Members
Posts: 48
Joined: 12-March 06
Member No.: 19,909



Thanks for this man, I have created a viewr using Delphi 7, and it is a very similar way in which you have performed this. I will post my tutorial also for Delphi users when I have the time to install Delphi again. Is it easy to transfer from Delphi to Visual Basic, as I want to learn how to code in VB?
Thanks.
Go to the top of the page
 
+Quote Post
Dawiss
post Mar 12 2006, 08:03 PM
Post #3


Super Member
*********

Group: Members
Posts: 286
Joined: 4-December 05
From: Latvia, Riga
Member No.: 15,337



Nice thing.. but only problem I have in this tutorial I don't have such program called Microsoft Visual Studio sad.gif.. Is there any way to download it for free.. because maybe some computers alredy have this program in but mine is pretty old junk* biggrin.gif..

But nice tutorial and useful thing that could help out a lot biggrin.gif.. GooD JoB.. keep it up wink.gif..
Go to the top of the page
 
+Quote Post
Mortanis
post Mar 14 2006, 11:30 PM
Post #4


Newbie [Level 1]
*

Group: Members
Posts: 18
Joined: 11-March 06
From: Winterpeg
Member No.: 19,841



Yeah the version he/she (I'm not sure) is using is free from microsoft.com (or at least it was for me biggrin.gif

And nice tut biggrin.gif . It's so rare to find one for express edition mad.gif
Go to the top of the page
 
+Quote Post
iGuest
post Oct 5 2007, 01:51 PM
Post #5


Trap Double Mocha Member
***************

Group: Members
Posts: 2,360
Joined: 21-September 07
Member No.: 50,369



Very helpful page indeed :) Thanx

-Deepak Ramdas
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. [tutorial] Visual Basic 6(2)
  2. A Guide To Css And Creating A Stylesheet(15)
  3. A Little Introduction To 3d Studio Max(9)
  4. Creating Your Own Icon(23)
  5. Image Preloader With Progress Bar Status(22)
  6. Simple Login In Visual Basic 6(5)
  7. Image Rollovers In Javascript(11)
  8. How To Stop Image Hot Linking(17)
  9. Delete Files And Directories Using Php(7)
  10. Remove Outlook Express Splash Screen(3)
  11. Getting Started With Amfphp And Rias(0)
  12. How To Make A Web Browser(48)
  13. Image Shack Mod(2)
  14. Creating A Timer Program(8)
  15. How To Make Image To Highlight When It`s Mouseovered(8)
  1. Tutorial: Creating Custom Icons For Devices(0)
  2. Image Gallery Tutorial Using Hoverbox(14)
  3. A Simple Php Captcha - Image Validation(21)
  4. Math Captcha Image Validation(1)
  5. Programming In Glut (lesson 1)(0)
  6. Programming In Glut (lesson 4)(0)
  7. Creating A Resume(1)
  8. Image Rotator Script (another One)(0)
  9. Background Image Swap Script(15)
  10. Creating Navigation For Html Websites(12)
  11. Ftp In Visual Basic 6.0(0)
  12. Getting Started With Mysql(2)
  13. Get Back Lots Of Disk Space(7)


 



- Lo-Fi Version Time is now: 25th July 2008 - 09:35 AM