Making a Delphi[7] Web Browser - by joewnn

Discussion in 'Archives' started by Six, May 12, 2007.

Making a Delphi[7] Web Browser - by joewnn
  1. Unread #1 - May 12, 2007 at 11:32 AM
  2. Six
    Joined:
    Jan 21, 2007
    Posts:
    1,482
    Referrals:
    4
    Sythe Gold:
    12

    Six Guru

    Making a Delphi[7] Web Browser - by joewnn

    First, open up a new form. Add a webbrowser (look in the tab under internet) and make it a pretty good size. We will get to resizing in a bit. Now add all the standard buttons like back, refresh, forward, stop, and go. Add a textbox or combobox for the url.

    Name the back button "backbutton" and the forward button "forbutton".

    Now open up the backbutton's onclick code (double click it). Add this line.


    Code:
    webbrowser1.goback;

    And add this to forbutton's onclick code.


    Code:
    webbrowser1.goforward;

    Now you have your back and forward buttons working. Now we will get the basic navigation finished.

    If you didn't add a textbox yet, add one. If you are using tedit, like I am in this tutorial, then you won't have to change any names.

    Clear all text in Edit1. Now go to your go button and go to it's onclick code.
    Add this.

    Code:
    webbrowser1.Navigate(edit1.text);
    This tells the webbrowser to navigate to whatever url is in the textbox.

    Now you have the basics done.

    You will notice that when you first open the webbrowser and do not go to any sites and you hit forward or back, you will get an error. This is because there is no data to go back or forward to. To correct this, first set backbutton and forbutton's enabled setting to false. (if they are not enabled, the text on them should be grayed out)

    Now click on the webbrowser this time. In your toolbar, look for the events tab. Click on it and go to the CommandStateChange event. Double click it to bring up the code.

    Add this to it.


    Code:
    case Command of
                CSC_NAVIGATEBACK :
                begin
                   backbutton.Enabled := Enable;
                end;
    
                CSC_NAVIGATEFORWARD :
                begin
                   forbutton.Enabled := Enable;
                end;
             end;
    This gets the command, and sets the enabled value to whatever is sent by the webbrowser. If there is not page to navigate back too, enabled is set to false. If there is, it is true.

    Now for a refresh button, if you have added one, add one. Go to it's onclick event and add this code.

    Code:
    webbrowser1.refresh;

    And add this to the stop buttons onclick code.


    Code:
    webbrowser1.stop;


    For resizing go to the form's resize event and add something like this-

    Code:
    webbrowser1.width := form1.Width - 10;
    webbrowser1.Height := form1.height - 75;
    webbrowser1.Top := 40
    Play around with the numbers a bit, because you may have things in different places.
     
< The AFK Script | Firecapeing! >

Users viewing this thread
1 guest


 
 
Adblock breaks this site