儲存程式配置到註冊表裡

來源:互聯網
上載者:User
準備: 
    手動或用代碼在註冊表 HKEY_LOCAL_MACHINE/SOFTWARE/ 在建立的 "XXX"  項下添加需要的變數,例如添加

名:Text  值:    

名:R       值:255 
名:G       值:255 
名:B       值:255        的字串值

用以下代碼也可實現添加;
        private void buildreg()
        {
            Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.LocalMachine;
            Microsoft.Win32.RegistryKey softwareXXX = key.CreateSubKey("software//XXX");
            softwareXXX.SetValue("Text", "");
            softwareXXX.SetValue("R", "255");
            softwareXXX.SetValue("G", "255");
            softwareXXX.SetValue("B", "255");
        }

讀取方法: 
        private void Form1_Activated(object sender, EventArgs e)
        {
            Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.LocalMachine;
            Microsoft.Win32.RegistryKey softwareXXX = key.OpenSubKey("software//XXX");
            textBox1.Text = softwareXXX.GetValue("Text").ToString();
            int R = int.Parse(softwareXXX.GetValue("R").ToString());
            int G = int.Parse(softwareXXX.GetValue("G").ToString());
            int B = int.Parse(softwareXXX.GetValue("B").ToString());
            textBox1.BackColor = Color.FromArgb(R, G, B);
        } 

儲存方法:
        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.LocalMachine;
            Microsoft.Win32.RegistryKey softwareXXX = key.CreateSubKey("software//XXX");
            softwareXXX.SetValue("Text", textBox1.Text );
            softwareXXX.SetValue("R", textBox1.BackColor.R.ToString());
            softwareXXX.SetValue("G", textBox1.BackColor.G.ToString());
            softwareXXX.SetValue("B", textBox1.BackColor.B.ToString());
        }

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.