这个问题有两个部分。
-
每个对象有一个特定于事件的函数,还是合并对象事件更好?如果是这样,
-
我的事件功能:
private void GeneralEventHandler(object sender, EventArgs e){
var senderHash = sender.GetHashCode();
if (senderHash == tbDatabase.GetHashCode())
Settings.DB.Default.Database = tbDatabase.Text;
else if (senderHash == tbSchema.GetHashCode())
Settings.DB.Default.Schema = tbSchema.Text;
}
我的对象定义:
// tbDatabase
/
this.tbDatabase.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right)));
this.tbDatabase.Location = new System.Drawing.Point(62, 3);
this.tbDatabase.Name = "tbDatabase";
this.tbDatabase.Size = new System.Drawing.Size(210, 20);
this.tbDatabase.TabIndex = 0;
this.tbDatabase.LostFocus += new System.EventHandler(this.GeneralEventHandler);
//
// tbSchema
//
this.tbSchema.Location = new System.Drawing.Point(55, 3);
this.tbSchema.Name = "tbSchema";
this.tbSchema.Size = new System.Drawing.Size(217, 20);
this.tbSchema.TabIndex = 1;
this.tbSchema.LostFocus += new System.EventHandler(this.GeneralEventHandler);
我主要是用它来动态更新用户设置。我在退出时保存设置文件。