(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;即可。
方便吧?