小技巧集錦(1)[陸續貼上,網友也可以加喲]

來源:互聯網
上載者:User

(1)怎樣將電腦裡有可用字型加入WINFORM中的ComboBox中:
一句話搞定:comboBox1.Items.AddRange (FontFamily.Families);

(2)取得所有可用顏色並填充到asp.net的下拉式功能表中:
   PropertyInfo[]   properties;
   ArrayList        colors;
   Color            color;
//   SolidBrush       brush;
   properties = typeof (Color).GetProperties (BindingFlags.Public | BindingFlags.Static);
   colors = new ArrayList ();
   foreach (PropertyInfo prop in properties)
   {
    // get the value of this static property
    color = (Color) prop.GetValue (null, null);
    // skip colors that are not interesting
    if (color == Color.Transparent) continue;
    if (color == Color.Empty) continue;   
    try
    {
     ddlList.Items.Add(prop.Name);   
    }
    catch
    { 
    }
    // create a solid brush of this color
    //brush = new SolidBrush (color);
    //colors.Add (brush);
   }

(3)怎樣取得資料庫的連接字串?
A. 建立一個文字檔,檔案名稱使用*.udl(比如:myDB.udl),此時發現表徵圖變成資料庫連接的表徵圖了。
B. 雙擊此檔案,彈出資料連線屬性的對話方塊,此時你可以進行設定了。一般地,我們首先選擇“提供者”的選項卡,進行設定之後,再設定“串連”選項卡的相關屬性,其他的我就不說了。設定好之後,最後按“確定”。可能會有相應的提示,你自己看著辦吧。
C. 用記事本開啟你剛才的這個檔案。裡面有類似這樣的字串:
Provider=SQLOLEDB.1;Password=123456sa;Persist Security Info=True;User ID=sa;Initial Catalog=ZPWeb;Data Source=MyServerName
如果使用SQLSERVER資料庫,將Provider=SQLOLEDB.1;改為:Server=localhost;即可。
方便吧?

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.