Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Button controls and using methods to make a simple web browser

942 views

Published on

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Button controls and using methods to make a simple web browser

  1. 1. ComputingLesson 2 – Properties and Methods
  2. 2. Quick revision quiz1. What type of Visual Basic program creates a standard Windows application?2. What window is used to change the properties (eg size, name,text) of a form or object?3. How do you access the code of a control/object?4. Which property of a picture box do you set to display an image?5. What is the default action/event for a button (control)?
  3. 3. Answer time1. Windows Form Application2. The PROPERTIES window3. Double click!4. The IMAGE property5. Click!
  4. 4. Lesson Objectives1. Use controls to modify the appearance of a Windows Form Application2. Describe what a METHOD is3. Use a Method in a code example
  5. 5. Revision – what is a control?Anything that you can use in a program / application to trigger an event or call a procedure
  6. 6. Practical Revision Time!1. Go to Visual Studio2. (if you haven’t already) check your: Tools>Options>Projects & Solutions settings3. File > Open > Picture Box/Viewer
  7. 7. Let’s do our usual admin!• Check the toolbox is pinned to the left• Check the properties window is sorted A-Z• Click once on the Form in the middle
  8. 8. Add a button with the properties: Name btnEnlarge Location 338,261 Size 21,23 Text +NOTE!!!! If you changed the sizes/locations of your form/controls last lesson, you will need to adjust the properties shown on this slide to match your form!!!!!!
  9. 9. Add ANOTHER button with the properties: Name btnShrink Location 359,261 Size 21,23 Text - NOTE!!!! If you changed the sizes/locations of your form/controls last lesson, you will need to adjust the properties shown on this slide to match your form!!!!!!
  10. 10. Double click on the ‘+’ buttonAdd the following code (no pressing the enterkey yet): Me.Notice what happens when you type in the .Scroll down to ‘Width’ and then press the TABkey to auto select it!
  11. 11. Let’s keep typing…You should now have: Me.WidthKeep typing so that you end up with: Me.Width = Me.Width + 100 Me.Height = Me.Height + 100 (Making sure to press the Enter key after each line)
  12. 12. Double click on the ‘-’ buttonType in this code: Me.Width = Me.Width - 100 Me.Height = Me.Height - 100 (Making sure to press the Enter key after each line)
  13. 13. Try running your program1. Click the + button on your form2. Click the – button on your form3. Get it to a size you are happy with4. Try opening an image using the “Select Picture’ button5. Now resize the window using the buttons to see what happens!6. Save it and then File > Close
  14. 14. Understanding MethodsOBJECT METHODS BarkDOG Wag Tail Eat
  15. 15. To put it simply Invoking / triggering a method, code is executed or, in English…A method makes something happen in your program
  16. 16. How do I tell the difference between properties and methods?A method looks like: AlbumForm.ShowDialog() or Me.Close()A property change looks like: Me.Width = Me.Width + 100
  17. 17. Win Form App 2 – Web Browser‘Title’ Property This button will invoke amethod to load a web page from the internet! ‘TextBox.Text’ Property will be the address of our web page
  18. 18. Web Browser – Create New ProjectFile > New > Project > Windows Form ApplicationName - SimpleWebBrowser
  19. 19. Web Browser – Add Controls (Web Browser) 1. Add WebBrowser from ToolBox 2. Click on the Smart Tag arrow as shown 3. Select ‘Unlock in Parent Container’ 4. Adjust the size so that there is some space at the bottom for the other parts
  20. 20. Web Browser – Add Controls (Text Box)1. Add TextBox from Common Controls2. Move it to the bottom left3. Edit its properties to be: 1. Name – TextBox1 2. Text – (leave blank)
  21. 21. Web Browser – Add Controls (Button)1. Add a Button from Common Controls2. Move it to the bottom right3. Edit its properties to be: 1. Name – TextBox1 2. Text – ‘Show’
  22. 22. Web Browser – Check layout1. Your form should look like this with: 1. Web Browser 2. ‘Show’ button 3. Text Box
  23. 23. Double Click on the buttonType in the following code: WebBrowser1.Navigate(TextBox1.Text)Your code should look like (the green bit is anoptional comment):
  24. 24. How does this work?The WebBrowser Control uses the Navigate() method to navigate to the Text Property ofthe textbox (which just happens to be the website address that you typed in)
  25. 25. Summary• A method makes something happen in code• A property changes how something looks• Properties and Methods work together in programs
  26. 26. Quiz Time!1. An attribute that changes the state of an object is called a …………?2. To change the value of a property, the property is referenced on which side of the =?3. Visual Basic 2010 is known as am object- oriented language – true or false?
  27. 27. Quiz Time!1. Property2. Left3. True!
  28. 28. Done! Questions?

×