2. 如何在子窗体中调用主窗体中的某某方法;
//Define two delegate methods to get or set textbox value in main form
public delegate void SetTextValue( string TextValue );
public delegate string GetTextValue( );// In sub-form class
// Handler for methods from main form
private SetTextValue SetText = null;
private GetTextValue GetText = null; // Call methods as follows
string strValue = GetText();
SetText( strValue + DateTime.Now.ToString() ); 除了如上一些操作外,还需要修改子窗体的构造函数,来接收这两个delegate方法,这里就不多说了。 至于主窗体,首先要为这两个委托来实现对应函数,例如:
private string GetValue()
{
return yourTextBox.Text;
} private void SetValue( string sValue )
{
yourTextBox.Text = sValue;
} 那么调用子窗体的时候就比较简单了。
// Create subform and show it
yourSubForm myForm = new yourSubForm(
new SetTextValue( SetValue ),
new GetTextValue( GetValue ) );
myForm.ShowDialog();
//Define two delegate methods to get or set textbox value in main form
public delegate void SetTextValue( string TextValue );
public delegate string GetTextValue( );// In sub-form class
// Handler for methods from main form
private SetTextValue SetText = null;
private GetTextValue GetText = null; // Call methods as follows
string strValue = GetText();
SetText( strValue + DateTime.Now.ToString() ); 除了如上一些操作外,还需要修改子窗体的构造函数,来接收这两个delegate方法,这里就不多说了。 至于主窗体,首先要为这两个委托来实现对应函数,例如:
private string GetValue()
{
return yourTextBox.Text;
} private void SetValue( string sValue )
{
yourTextBox.Text = sValue;
} 那么调用子窗体的时候就比较简单了。
// Create subform and show it
yourSubForm myForm = new yourSubForm(
new SetTextValue( SetValue ),
new GetTextValue( GetValue ) );
myForm.ShowDialog();
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货