1 回答

TA貢獻(xiàn)1765條經(jīng)驗(yàn) 獲得超5個(gè)贊
為了使您的控件可供類的其他成員訪問(wèn),您需要在類級(jí)別定義它們。Form_Load然后您可以在構(gòu)造函數(shù)或事件(或任何您想要的地方)中初始化它們,并可以從其他類方法訪問(wèn)它們:
public partial class Form1 : Form
{
// Declare your controls at the class level so all methods can access them
private TextBox dbName;
private Button create;
private void Form1_Load(object sender, EventArgs e)
{
dbName = new TextBox
{
BorderStyle = BorderStyle.Fixed3D,
Location = new Point(236, 81)
};
Controls.Add(dbName);
create = new Button
{
FlatStyle = FlatStyle.Flat,
Location = new Point(261, 115),
Text = "Create",
};
create.FlatAppearance.BorderSize = 0;
create.Click += create_Click;
Controls.Add(create);
}
private void create_Click(object sender , EventArgs e)
{
var sfd = new SaveFileDialog
{
Filter = "Housam Printing |*.HP",
InitialDirectory = AppDomain.CurrentDomain.BaseDirectory,
FileName = dbName.Text,
Title = "Database location"
};
}
}
- 1 回答
- 0 關(guān)注
- 207 瀏覽
添加回答
舉報(bào)