当前位置 : 主页 > 网络编程 > 其它编程 >

简单的浏览器(C#)

来源:互联网 收集:自由互联 发布时间:2023-07-02
在网上找了一些代码运行不起来就自己慢慢改了改现在拿开给分享下。IE在regedit(注册表)里面都有些什么内容。因为regeidt 在网上找了一些代码运行不起来就自己慢慢改了改现在拿开给分
在网上找了一些代码运行不起来就自己慢慢改了改现在拿开给分享下。IE在regedit(注册表)里面都有些什么内容。因为regeidt

在网上找了一些代码运行不起来就自己慢慢改了改现在拿开给分享下。

IE在regedit(注册表)里面都有些什么内容。因为regeidt是Windows里面一个非常不错的数据库它可以把整台机子相关的一些东西都存放在里面。在regedit里面与IE相关的内容有这些 我们要的是“softwaremicrosoftinternet explorertypedurls”的数据记录的网址都在里面 如图

 

控件代码

using System; using System.Collections.Generic; using System.Text; using System.Windows.Forms;

using Microsoft.Win32;  //记得引用命名空间

using System.ComponentModel;

namespace ControlSet.URLControl {     public class URLComboBox : ComboBox     {         ///

         /// Member variable which stores the autocomplete flags

         ///

         private AutoCompleteFlags _flags AutoCompleteFlags.FileSystem | AutoCompleteFlags.URLHistory | AutoCompleteFlags.URLMRU;

         ///

         /// Member variable which stores the mru key

         ///

         private string _mruKey "softwaremicrosoftinternet explorertypedurls/";

         ///

         /// Member variable which stores the mru key hive

         ///

         private MRUKeyHive _mruKeyHive MRUKeyHive.CurrentUser;

 

 

        ///         /// Initilaizes a new instance of URLComboBox         ///

        public URLComboBox() : base() { }

        ///

         /// Gets the registry key where MRU URLs are stored

         ///

         /// Indicates whether to get the key so that it values written to it

         /// RegistryKey object for the MRU registry key or null if none exists

         private RegistryKey GetMRUKey(bool writable)

         {

              if (_mruKey.Length 0)

                   return null;

 

              RegistryKey ret null;

             

              switch(_mruKeyHive)

              {

                   case MRUKeyHive.LocalMachine:

                        ret Registry.LocalMachine.OpenSubKey(_mruKey, writable);

                       break;

                   case MRUKeyHive.CurrentUser:

                       ret Registry.CurrentUser.OpenSubKey(_mruKey, writable);

                       break;

              }

 

              return ret;

         }

        

         ///         /// Writes information about any ignored exception to the trace.

         ///

         /// The exception which is being ignored

         private void TraceIgnoredError(Exception e)

         {

              //It/s ok if there is any error

              System.Diagnostics.Trace.WriteLine(e.Message);

              System.Diagnostics.Trace.WriteLine(e.StackTrace);

         }

        

         ///

         /// Utility function to fill the combob box most recently typed URLs read from registry.

         ///

         private void MRUFill()

         {

              if (DesignMode)

                   return;

 

              RegistryKey mruKey null;

 

              try

              {

                int i 1;

 

                   string strFormat "url{0}";

                   object defaultValue String.Empty;

                   object url;

                  

                   mruKey GetMRUKey(false);

                  

                   if (mruKey ! null)

                   {

                       while((url mruKey.GetValue(String.Format(strFormat, i), defaultValue)) ! defaultValue)

                       {

                            Items.Add(url);

                            i;

                       }

                   }

              }

              catch(Exception e)

              {

                   TraceIgnoredError(e);

              }

              finally

              {

                   if (mruKey ! null)

                       mruKey.Close();

              }               }

 

         ///

         /// Gets or sets the auto complete flags

         ///

         [Description("Gets or sets the auto complete flags")]

         public AutoCompleteFlags Flags

         {

              get

              {

                   return _flags;

              }

              set

              {

                   _flags value;

              }

         }

        

         ///

         /// Gets or sets the registry key name where the combo box maintains MRU list.

         ///

         [DescriptionAttribute("The registry key name where the combo box maintains MRU list")]

         public string MRUKey

         {

              get

              {

                   return _mruKey;

              }

              set

              {

                   _mruKey value;

              }

         }

        

         ///

         /// Gets or sets the registry key hive for the MRUKey property.

         ///

         [DescriptionAttribute("The registry hive where the combo box maintains MRU list")]

         public MRUKeyHive MRUKeyHive

         {

              get

              {

                   return _mruKeyHive;

              }

              set

              {

                   _mruKeyHive value;

              }

         }

 

         ///

         /// Writes the recntly typed URL to the registry if it is not already there

         ///

         ///

         protected override void OnValidated(System.EventArgs e)

         {

              if (DesignMode)

                   return;              if ((Text.Length ! 0) -1))

              {

                   Items.Add(Text);

                  

                   RegistryKey mruKey null;

 

                   //Finally add it to the registry

                   try

                   {

                       mruKey GetMRUKey(true);

                      

                       if (mruKey ! null)

                            mruKey.SetValue(String.Format("url{0}", Items.Count), Text);

                   }

                   catch(Exception ex)

                   {

                       TraceIgnoredError(ex);

                   }

                   finally

                   {

                       if (mruKey ! null)

                            mruKey.Close();

                   }

              }

    

              base.OnValidated(e);

         }

        

         ///

         /// Finds the handle to the edit control and calls SHAutoComplete on it.

         /// Also fills the combobox from the values read from the registry

         ///

         /// Ignored

         protected override void OnHandleCreated(System.EventArgs e)

         {

              base.OnHandleCreated(e);

              if (DesignMode)

                   return;

              //This is the right place do auto completion

              ComboBoxInfo info new ComboBoxInfo();

              info.cbSize System.Runtime.InteropServices.Marshal.SizeOf(info);

 

              if (UnManagedMethods.GetComboBoxInfo(Handle, ref info))

              {

                   UnManagedMethods.SHAutoComplete(info.hwndEdit, (IntPtr)_flags);

              }

             

              MRUFill();

         }     }

    ///

    /// A simple enumeration that wraps various auto complete flags of SHAutoComplete.

    /// See documenation of SHAutoComplete for details

    ///

    [Flags]

    public enum AutoCompleteFlags : int     {

        ///

        /// This includes the File System as well as the rest of the shell (Desktop//My Computer//Control Panel//)

        ///

        FileSystem 0x00000001,

        ///

        /// URLs in the User/s History

        ///

        URLHistory 0x00000002,

        ///

        /// URLs in the User/s Recently Used list.

        ///

        URLMRU 0x00000004,

        ///

        /// Use the tab to move thru the autocomplete possibilities instead of to the next dialog/window control.

        ///

        UseTab 0x00000008,

        ///

        /// This includes the File System

        ///

        FileSystemOnly 0x00000010,

        ///

        /// Same as FileSystemOnly except it only includes directories, UNC servers, and UNC server shares.

        ///

        FileSystemDirs 0x00000020,

        ///

        /// Ignore the registry default and force the auto suggest feature on.

        ///

        AutoSuggestForceOn 0x10000000,

        ///

        /// Ignore the registry default and force the auto suggest feature off

        ///

        AutoSuggestForceOff 0x20000000,

        ///

        /// Ignore the registry default and force the auto append on.

        ///

        AutoAppendForceOn 0x40000000,

        ///

        /// Ignore the registry default and force auto append off.

        ///

        AutoAppendForceOff -2147483648

    }

 

    ///

    /// Enumeration for possible types of registry base keys for storing most recntly typed URLs

    ///

    public enum MRUKeyHive : int     {

        ///

        /// Value that indicates HKEY_CURRENT_USER should be used for MRUKey property

        ///

        CurrentUser 1,

        ///         /// Value that indicates HKEY_LOCAL_MACHINE should be used for MRUKey property

        ///

        LocalMachine 2,

    } }  

测试下

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms;

namespace TestAutoUrl {     public partial class Form1 : Form     {         public Form1()         {             InitializeComponent();         }

        private void button1_Click(object sender, EventArgs e)         {             Cursor currentcursor Cursor.Current;

            try             {

                Cursor.Current Cursors.WaitCursor;

                webBrowser1.Navigate(urlComboBox1.Text);              

            }catch(Exception ex)             {                         }             finally             {

                Cursor.Current currentcursor;

            }

        }     } }

 

好了基本上就这些了。不好的地方请多见谅 呵呵

上一篇:一步一步学springboot
下一篇:没有了
网友评论