我在運行時動態創建按鈕。 但當我關閉並重新打開這些按鈕將消失。 它如何永久存儲動態創建的按鈕和其他控件。在運行時動態創建按鈕並存儲,在C中進行檢索#
動態創建控制按鈕的代碼是:
int loc=150;
private void Button1_Click(object sender, EventArgs e){
CreateDynamicButton();
}
private void CreateDynamicButton()
{
// Create a Button object
Button dynamicButton = new Button();
// Set Button properties
dynamicButton.Height = 40;
dynamicButton.Width = 300;
dynamicButton.BackColor = Color.Red;
dynamicButton.ForeColor = Color.Blue;
dynamicButton.Location = new Point(20, loc);
loc=loc+50;
dynamicButton.Text = "I am Dynamic Button";
dynamicButton.Name = "DynamicButton";
dynamicButton.Font = new Font("Georgia", 16);
// Add a Button Click Event handler
dynamicButton.Click += new EventHandler(DynamicButton_Click);
// Add Button to the Form. Placement of the Button
// will be based on the Location and Size of button
Controls.Add(dynamicButton);
}
/// <summary>
/// Button click event handler
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void DynamicButton_Click(object sender, EventArgs e)
{
MessageBox.Show("Dynamic button is clicked");
propertyGrid1.SelectedObject=sender;
*****and i change it some color fontsize in propertyGrid1 it will be changed
*****how do i save permanently
}
請幫助我如何存儲所有永久控制(控制顏色,位置,名稱...)
在此先感謝。
這只是一個樣本,但我存儲佈局和所有控件的屬性。請任何可能的方式編輯使用獲取當前屬性使用propertygrid保存並加載permenantlly。 –