PDA

View Full Version : فراخوانی کنترلها از یک فرم دیگر



Future
چهارشنبه 12 اردیبهشت 1386, 10:53 صبح
سلام دوستان، من یک فرم دارم که یک bottun,combobox روی آن قرار دارد.با کلیک کردن بر روی این button یک usercontrol نمایش داده میشه.در این usercontrol نیز یک bottunقرار داره. حالا می خوام با کلیک کردن بر روی این دکمه محتویاتی که در کامبو باکس در فرم1 قرار داره نمایش داده بشه.ولی من هر کاری می کنم commobox در فرم 1 را نمی شناسه.ممنون میشم اگه راهنمایی کنید
با تشکر

ghafoori
چهارشنبه 12 اردیبهشت 1386, 13:29 عصر
دوست عزیز خاصیت modifiers کنترل فرم 1 را برابر public قرار دهید

Sorenaa_s
چهارشنبه 12 اردیبهشت 1386, 17:46 عصر
public class MyUserControl: UserControl
{
public ComboBox comboBox;
private Button Button1 = new Button();
public MyUserControl()
{
this.Controls.Add( Button1 );
this.Button1.Click = new EventHandler( Button1_Click );
}


private void Button1_Click( object Sender, EventArgs e )
{
comboBox.Items.Clear();
}


}


public class Form1: Form
{
private ComboBox ComboBox1 = new ComboBox();
private Button Button1 = new Button();


public Form1()
{
this.Controls.Add( ComboBox1 );
this.Controls.Add( Button1 );
this.Button1.Click = new EventHandler( Button1_Click );
}


private void Button1_Click( object Sender, EventArgs e )
{
MyUserControl control = new MyUserControl();
control.comboBox = this.ComboBox1;
this.Controls.Add( control );
}
}