说明:propertyGrid的使用 ,其中涉及到一个复制到粘贴版功能
1:先建立UI界面
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Data.SqlClient; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace 数据库连接字符串生成 { public partial class Form2 : Form { public Form2() { InitializeComponent(); SqlConnectionStringBuilder scsb = new SqlConnectionStringBuilder(); scsb.UserID = "sa"; scsb.DataSource = "."; this.propertyGrid1.SelectedObject = scsb; } private void button1_Click(object sender, EventArgs e) { string str = this.propertyGrid1.SelectedObject.ToString(); //粘贴板 Clipboard.Clear(); Clipboard.SetText(str); MessageBox.Show(str); } } }
2:运行结果