Visual Basic Help - Phone-Book
Microsoft Visual Basic 6.0 help and Tutorials
MS-Visual Basic 6.0 & MS-Access 2003 - Crystal Reports to create a desktop software professionally
Custom Search
(3) Visual Basic 6.0 codes for design

    • In this part we will take a look on how to make our personal application more interactive and responsive to the mouse and the surrounding environment which is of course the windows desktop, i.e we will get to know :
      • How to move the application from any place of the form
        How to use drag and drop to load pictures in the Image control
        How to set the location of the BackGround picture of the form using the code
        How to create a graphical effect on the form while closing
        How to prevent the application from opening twice in the same time

    We will not execute codes for database in this part #3, we should know first [How does it work - Part #4] how the data will transfer from/into the database to/from the Visual Basic project, this is called the application logic, this is the base of coding, this is Coding.

    • I assume now you've already (Created and designed your project - Created and designed your Database - put them both in the same folder) as instructed in the previous 2 parts, and you tried executing some of the codes I provided, but your application project's code window now must be empty and ready for coding. We will start coding to execute the above mentioned tips.

How to move the application from any place of the form

- First we open our project and copy the code from below into the code window of the the [MainFrm] form, and try run the application by pressing [F5] from keyboard to test it, try to move the form using the mouse from any part of the form.

How to use Drag/Drop to load pictures in the Image control

- We need to create a new Module, we will call it [evry1falls], we will use this module to write the code which we need to use globally in the application, meaning (Any code we write there as Global will affect at any area of the application). We create new module by going to the (Project panel then right click then choose Add then Module), don't forget to save it as (evry1falls) in your main vb6 project (\PhoneBook) folder


first line we write there will be :

- PicNm is a string we will use to store the picture path which we will be assigned to our friends, also the string variable PicNm will hold the path of the picture in the Image control (Timg) everytime we want to use it, as in DragDrop method we will use below in the next step.

- We have an [Image] control called [Timg] and we use a [CommonDialog] object to load pictures of our friends in it. We can also use Drag/Drop event to accomplish this task, notice that using Drag/Drop pictures from our hard drive to the visual basic 6 IDE form is not so hard, you just need to understand that we will use OleDrop event of the Image control (Timg) , using this code below :

Save the application and run it using (F5) to test it, try both methods (Cdl , Drag&Drop) to display a picture from your hard drive into the Image Control (Timg), see how error is generated if we tried to drop any file that is not a picture in the (Timg) control.

How to set location of the form's BackGround photo using code

- You can choose a picture as a form's backgroud from [Property Panel] and you can do this using the code [Me.Picture="Path/Picture.Jpg"], but the picture will be always in the top-left corner of the form. Another way to draw a picture on the form's background at a pre-defined location using the code in the [Form_Paint()] events is by using the code below :

How to create an effect on the form while closing

- Using visual basic 6 logical codes to create a nice close effect like sliding or shaking .... etc. We don't need any tool or control, we can do this by ourselves using the Module we will create a public sub that makes the form slides on the Exit button click even using the code below :

How to prevent the program from opening twice in the same time

- If the program is already running, we will need a code to prevent us or any other user to run it again while it is already running, this is a good way to control working with an application that is based on a database file because you get to connect to the database file using one connection, so it won't make sense if we run the same application twice at the same time, we can do so by creating a new sub in the Module section and call it (Main) then change the settings of the application from (Project, MyPhoneBook Properties, StartUp Object, then we choose Sub Main), code below creates a Sub Main:

Part (4) - How does it work ?

Thanx for reading, please feel free to leave a suggestion.

Labels :

Visual Basic, learning visual basic, visual basic training, visual basic for dummies, learn visual basic 2010, visual basic classes, visual basic coding, learn visual basic programming, learn visual basic online, visual basic programmer, visual basic help, help with visual basic, visual basic programming help, visual basic 2010 help, microsoft visual basic help, microsoft visual basic 6.0 help, vb programmers, Visual Basic 6.0, visual basic 6.0 software, visual basic 6.0 training, learn visual basic 6.0, ms visual basic 6.0, visual basic 6.0 pro, visual basic 6.0 learning edition, software of visual basic 6.0, how to learn visual basic 6.0, learning visual basic 6.0, visual basic 6.0 price.

Free Web Hosting