open new form, load a .html file?

Discussion in 'Programming General' started by hampe-92, Oct 11, 2008.

open new form, load a .html file?
  1. Unread #1 - Oct 11, 2008 at 6:33 PM
  2. hampe-92
    Joined:
    Jul 10, 2008
    Posts:
    328
    Referrals:
    0
    Sythe Gold:
    0

    hampe-92 Forum Addict

    open new form, load a .html file?

    Hi
    I need some help, I want that when I click a button my form2 with a webbrowser opens, but i want the web browser to open a html file that I have made... how should one go about doing that?
    thx in advance!
     
  3. Unread #2 - Oct 11, 2008 at 8:05 PM
  4. Swan
    Joined:
    Jan 23, 2007
    Posts:
    4,957
    Referrals:
    0
    Sythe Gold:
    0
    Sythe's 10th Anniversary Member of the Month Winner

    Swan When They Cry...
    Retired Global Moderator

    open new form, load a .html file?

    Just navigate to the HTML file.

    i.e.
    Code:
    webBrowser1.Navigate(@"C:\index.html");
    If you wanted something in the same directory as your browser application,
    Code:
    webBrowser1.Navigate(Application.StartupPath + @"\index.html");
    The '@' simply denotes that it is a path, so escape characters are ignored, and backslashes are used to separate the directories. You can always use forward slash, I guess it depends on your coding habits.
     
  5. Unread #3 - Oct 11, 2008 at 9:19 PM
  6. Govind
    Joined:
    Apr 22, 2005
    Posts:
    7,825
    Referrals:
    13
    Sythe Gold:
    23
    Prove it! Trole Tier 1 Prizebox Tortoise Penis Le Monkey UWotM8? Wait, do you not have an Archer rank? Potamus

    Govind The One Musketeer
    Mudkips Highly Respected Retired Administrator

    open new form, load a .html file?

    Backslashes are better since that's what Windows uses, (though it accepts forward slashes for filepaths as well.)
     
  7. Unread #4 - Oct 12, 2008 at 2:59 AM
  8. hampe-92
    Joined:
    Jul 10, 2008
    Posts:
    328
    Referrals:
    0
    Sythe Gold:
    0

    hampe-92 Forum Addict

    open new form, load a .html file?

    So if i have a html file inside my prjoject e.g;
    (here is the Solution explorer)
    WindowsFormsApplication1
    +Properties
    +References
    +Form1
    +Form2
    +Folder
    > myFile.html
    > myFile_LinksToThis.html
    Program.cs

    and whant that webBrowser1 should navigate to myFile.html
    then I should write like this?

    public void form1_Load(object sender, System.EventArgs e)
    {
    webBrowser1.Navigate(Application.StartupPath + @"\Folder\myFile.html");
    }


    sorry, I haven't got time to test it atm...
    and thx very much for your help :)
     
  9. Unread #5 - Oct 12, 2008 at 3:58 AM
  10. Swan
    Joined:
    Jan 23, 2007
    Posts:
    4,957
    Referrals:
    0
    Sythe Gold:
    0
    Sythe's 10th Anniversary Member of the Month Winner

    Swan When They Cry...
    Retired Global Moderator

    open new form, load a .html file?

    I think the WebBrowser control actually has a property called "Url" which you can set, and the browser loads the page at "Url" on startup.
     
  11. Unread #6 - Oct 12, 2008 at 6:33 AM
  12. hampe-92
    Joined:
    Jul 10, 2008
    Posts:
    328
    Referrals:
    0
    Sythe Gold:
    0

    hampe-92 Forum Addict

    open new form, load a .html file?

    yeah that's right, it has a url property, but I have tried to add the path but it doesn't work :/
     
  13. Unread #7 - Oct 13, 2008 at 2:50 PM
  14. hampe-92
    Joined:
    Jul 10, 2008
    Posts:
    328
    Referrals:
    0
    Sythe Gold:
    0

    hampe-92 Forum Addict

    open new form, load a .html file?

    ok.. this code works, but I have to have a folder with all the htlm files in at the same place as the .exe file... what I wanted was to have the thml files build in to the exe file... I don't know if that is possible but if someone finds out how to do it please post here or pm me :)

    Code:
    webBrowser1.Navigate(Application.StartupPath + @"\index.html");
     
  15. Unread #8 - Oct 13, 2008 at 5:29 PM
  16. Swan
    Joined:
    Jan 23, 2007
    Posts:
    4,957
    Referrals:
    0
    Sythe Gold:
    0
    Sythe's 10th Anniversary Member of the Month Winner

    Swan When They Cry...
    Retired Global Moderator

    open new form, load a .html file?

    You could store the entire HTML file in to a hardcoded string, then create a temporary file from that string and navigate to it.
     
  17. Unread #9 - Oct 13, 2008 at 6:12 PM
  18. hampe-92
    Joined:
    Jul 10, 2008
    Posts:
    328
    Referrals:
    0
    Sythe Gold:
    0

    hampe-92 Forum Addict

    open new form, load a .html file?

    what do you mean with "Hardcoded string"? what is it, could you please explain a little more?
     
  19. Unread #10 - Oct 14, 2008 at 2:30 AM
  20. Swan
    Joined:
    Jan 23, 2007
    Posts:
    4,957
    Referrals:
    0
    Sythe Gold:
    0
    Sythe's 10th Anniversary Member of the Month Winner

    Swan When They Cry...
    Retired Global Moderator

    open new form, load a .html file?

    What I mean is, create a string, and store the entire HTML file in that string. Any block of text is a string, so just store the HTML file in there, and create a temporary one upon execution.
     
  21. Unread #11 - Oct 14, 2008 at 11:41 AM
  22. hampe-92
    Joined:
    Jul 10, 2008
    Posts:
    328
    Referrals:
    0
    Sythe Gold:
    0

    hampe-92 Forum Addict

    open new form, load a .html file?

    hmm.. I'm not sure that I get it right... Do you mean that I should store the whole html code in a string?? and if that's right, how do I create a temp html file from that?
     
  23. Unread #12 - Oct 18, 2008 at 9:23 PM
  24. Swan
    Joined:
    Jan 23, 2007
    Posts:
    4,957
    Referrals:
    0
    Sythe Gold:
    0
    Sythe's 10th Anniversary Member of the Month Winner

    Swan When They Cry...
    Retired Global Moderator

    open new form, load a .html file?

    You would use file I/O classes in the System.IO namespace (or something similar).

    e.g.

    Code:
    StreamWriter sw = new StreamWriter(Application.StartupPath + "/page.html");
    
    sw.Write(data);
    
    sw.Close();
    
    WebBrowser.Navigate(Application.StartupPath + "/page.html");
    Not sure if that will work - I just typed it up in the reply box.
     
  25. Unread #13 - Oct 21, 2008 at 4:55 PM
  26. hampe-92
    Joined:
    Jul 10, 2008
    Posts:
    328
    Referrals:
    0
    Sythe Gold:
    0

    hampe-92 Forum Addict

    open new form, load a .html file?

    ok thx for the help... I'll take a look at that later.. don't have time atm and I don't work very much on that project anymore but maybe I'll later... anyway, it's good to know how to do that, so as I said, I will take a look later;)
     
< [tut] Calculating average (not GUI) | What's the difference between... >

Users viewing this thread
1 guest


 
 
Adblock breaks this site