Beantwortet new browser in C#

  • Dienstag, 24. Mai 2005 08:45
     
     
    Hi,

    I just started learning how to use Visual C# and I am having trouble creating a new web browser from a button. I currently have a button that I want to click to open a new web browser window, which will go to my homepage. I can't find anything on how to open a new window. The closest I have is webBrowser.NewWindow, but it doesn't seem to do anything. Any help is appreciated. Thanks

    edit: wait wait, there's more! I also have a combobox and I want to be able to type in new items and have it add to the item collection. When I run it, the Item.Add in my program works and I can see the new additions in the combobox, but after I close the program and rerun it, the new additions are no longer there anymore. How do I save them? Thanks again

Alle Antworten

  • Dienstag, 24. Mai 2005 09:11
    Moderator
     
     Beantwortet
    Here are some very good links for Tutorials on using the the Web Browser control from .NET

    C#
    http://www.codeproject.com/csharp/webbrowser.asp

    The sample is in VB, but explains the stuff well.
    http://www.vbwm.com/articles/builder/viewer.asp?ArticleID=31

    Regards,
    Vikram
  • Dienstag, 24. Mai 2005 14:38
     
     Beantwortet

    Here is an attempt at launching an Internet Explorer window (>= IE4 only):
    http://www.c-sharpcorner.com/Code/2002/Dec/IEInstance.asp

    For your second question; I would probably store the collection in a database.  What DBMS are you comfortable using?

    This is a decent article on C# data access:
    http://www.devarticles.com/c/a/ADO.NET/Data-Access-in-.NET-using-C-sharp-Part-1/1/

    Chad

  • Freitag, 27. Mai 2005 14:40
     
     
    In regard to saving entries in a combobox or any other similar control, you can save the data to a file (via the various file and XML serialization classes) or you could save it to the registry using the Registry classes. For a combobox the registry may be an appropriate place to store the data assuming we're talking about a relatively small amount of data. For example, to store all the entries in a combobox called cbo1 into the registry key HKCU\Software\MyProg, do the following:

    using Microsoft.Win32; //Contains the Registry class

    RegistryKey pRegKey = Registry.CurrentUser;
    pRegKey = pRegKey.CreateSubKey(
    @"software\MyProg");
    int i = 0;
    foreach (string s in cbo1.Items)
    {
       pRegKey.SetValue(
    "item" + i, s);
       i++;
    }

    You may need to put this in a Try block and so forth but this is the basic idea. To read the entries back and use them to repopulate your combobox you could do something like this:

    RegistryKey pRegKey = Registry.CurrentUser;
    pRegKey = pRegKey.OpenSubKey(
    @"software\MyProg");
    for (int i = 0; i < pRegKey.ValueCount; i++)
    {
       cbo1.Items.Add(pRegKey.GetValue(
    "item" + i));
    }

    Your data will show up in the registry like this:
    \\HKEY_CURRENT_USER\Software\MyProg\item0
    \\HKEY_CURRENT_USER\Software\MyProg\item1 ... etc.

  • Samstag, 11. Juni 2005 20:00
     
     
    Hello i have another idea

    maybe this help you so:


    System.Diagnostics.Process.Start("iexplore.exe", "http://www.msdn.com");


     



    it opens a ie and goes through the MSDN web site.

    sincerely
    Bidel.