I created a class
public static class Prompt
{
public static Form showCategoryDialog()
{
Form addCategoryDialog = new Form()
{
Width = 500,
Height = 150,
FormBorderStyle = FormBorderStyle.FixedDialog,
Text = "caption",
StartPosition = FormStartPosition.CenterScreen
};
Label textLabel = new Label() { Left = 50, Top = 20, Text = "asd" };
TextBox textBox = new TextBox() { Left = 50, Top = 50, Width = 400 };
Button confirmation = new Button() { Text = "Ok", Left = 350, Width = 100, Top = 70, DialogResult = DialogResult.OK };
confirmation.Click += (sender, e) => { addCategoryDialog.Close(); };
addCategoryDialog.Controls.Add(textBox);
addCategoryDialog.Controls.Add(confirmation);
addCategoryDialog.Controls.Add(textLabel);
addCategoryDialog.AcceptButton = confirmation;
return addCategoryDialog;
}
}
now in the form's button click event
private void addCateogoryClick(object sender, EventArgs e)
{
Form a = new Form();
a = Prompt.showCategoryDialog();
a.ShowDialog();
}
There, a textBox, button and label is created in a form and that form is assigned to the form 'a'. Since Form 'a' also has textBox, button and label, i want to call them like
if(a.textbox.text == string.empty)
{
//do this
}
AND access it's button_click event also, like
a.button_click
{
if(button.text == "ok")
//do this
}
Summing it up: I dont know how to access a form's control(textbox, button etc) and also i dont know how to use events in this situation.