Initializing form (dialog)

  • Thread starter Thread starter Alex
  • Start date Start date
A

Alex

Hello everybody,

I'm just starting C#. I'm working on forms based application. The
parent form has some buttons. If I click the button, some child form
must pop-up. My question is - is there in C# something analogous to
OnInitDialog from C++? So I'm able to initialize controls in the
child form based on the info from the parent?

I have:

private void btSomeButton_Click(object sender, EventArgs e)
{
SomeChildDlg dlg = new SomeChildDlg();

dlg.m_strValueForControl1 = "aaaaaa";
dlg.m_strValueForControl2 = "xxxxxx";

if (dlg.ShowDialog() == DialogResult.OK)
.......................................................
...............................


But how at the very beginning can I populate controls in my
SomeChildDlg form (put string "aaaaaa" in one text box on child form
and assing "xxxxxx" to another text box) ? Do I have to call
someother function in between constructor and dlg.ShowDialog()?

Thanks,
Alex
 
Alex said:
Hello everybody,

I'm just starting C#. I'm working on forms based application. The
parent form has some buttons. If I click the button, some child form
must pop-up. My question is - is there in C# something analogous to
OnInitDialog from C++? So I'm able to initialize controls in the
child form based on the info from the parent?

I have:

private void btSomeButton_Click(object sender, EventArgs e)
{
SomeChildDlg dlg = new SomeChildDlg();

dlg.m_strValueForControl1 = "aaaaaa";
dlg.m_strValueForControl2 = "xxxxxx";

if (dlg.ShowDialog() == DialogResult.OK)
......................................................
..............................


But how at the very beginning can I populate controls in my
SomeChildDlg form (put string "aaaaaa" in one text box on child form
and assing "xxxxxx" to another text box) ? Do I have to call
someother function in between constructor and dlg.ShowDialog()?

Thanks,
Alex
Alex,
If you are just going to be populating controls with some value you
could create a constructor that takes them as a parameter of some sort.
DH
 
DH, thanks for the reply. But the example I gave is very simple, in
reality I have much more controls. To have a constructor with twenty
parameters seems a little bit odd to me. So there is nothing like
OnInitDialog() indeed?

Thanks again,
Alex
 
Alex said:
DH, thanks for the reply. But the example I gave is very simple, in
reality I have much more controls. To have a constructor with twenty
parameters seems a little bit odd to me. So there is nothing like
OnInitDialog() indeed?

Thanks again,
Alex
Alex,
I havnt done C++ programming like this. But you could pass it as a class
of some type to the constructor i would imagine and just enumerate the
properties.
I'm doing something similar but my requirements are very tight and the
data i need is written to a XML each time and I just pass it the XML data.
 
Thanks again to everybody who answered this post. I repeat that I'm
just starting to do some applications in C# and wanted to do it right
from the very beginning. Obviously sometimes I'll have to take
different (from C++) approach. What I need is to set some values in
certain controls of my child dialog (from parent dialog), then based
on this values, populate other controls of this child dialog. In this
case, as I understand the best way for me would be to initialize
required child controls first (trough the public members or like Peter
suggested through the properties) and then to have some MyInitDialog()
public method, which I will call from parent dialog after initializing
child controls, but BEFORE dlg.ShowDialog(). In this MyInitDialog
I'll be able to work on other controls depending on controls which
have been initialized already. And only then I'll call dlg.ShowDialog
()

Best regards,
Alex
 
Back
Top