最佳解答者
請教一下該如何變更其他表單中元件的內容?

問題
解答
-
HI K SIR:
下面的程式碼 給你 參考 ︿︿
程式碼區塊private void FormB_Click(object sender, EventArgs e)
{
foreach (Form A in Application.OpenForms)
{
if (A is FormA)
{
foreach (Control i in A.Controls)
{
if ((i is TextBox) && (i.Name=="textBox1"))
{
TextBox t= i as TextBox;
t.Text="YA! 我找到你了 ^^";
break;
}
}
}}
} -
Demo 用 Form1 去控制 Form2 的 Title
public class Form2:WindowForm{
public string TitleString{
get{
retrun this.Title.Text;
}
set{
this.Title.Text=value;
}
}
}
public class Form1:WindowForm{
private void SendMessageToForm2(string message){
Form2 form2=new Form2();
form2.TitleString="This is Form Two";
form2.Show();
}
}
-
HI K Sir:
下面程式碼給你參考 ︿︿
程式碼區塊
static TextBox ErrMsgBox;public Form1()
{
InitializeComponent();
ErrMsgBox = this.textBox1;
}
public static void GettkConnstr_SMTP()
{
try
{
}
catch (Exception )
{
if (ErrMsgBox != null)
{
ErrMsgBox.Text = "如果程式發生錯誤時,希望可以在FORM中的textBox上留下訊息!";
}
}}
所有回覆
-
HI K SIR:
下面的程式碼 給你 參考 ︿︿
程式碼區塊private void FormB_Click(object sender, EventArgs e)
{
foreach (Form A in Application.OpenForms)
{
if (A is FormA)
{
foreach (Control i in A.Controls)
{
if ((i is TextBox) && (i.Name=="textBox1"))
{
TextBox t= i as TextBox;
t.Text="YA! 我找到你了 ^^";
break;
}
}
}}
} -
Demo 用 Form1 去控制 Form2 的 Title
public class Form2:WindowForm{
public string TitleString{
get{
retrun this.Title.Text;
}
set{
this.Title.Text=value;
}
}
}
public class Form1:WindowForm{
private void SendMessageToForm2(string message){
Form2 form2=new Form2();
form2.TitleString="This is Form Two";
form2.Show();
}
}
-
暈倒!!,怎麼會有這種問題! 還是Demo一下,我做一張銷售訂單,上面放Lable,我們稱 lbSalesOrderNo
public class SalesOrderForm:WindowForm{
private void SetInitialVaule(){
this.lbSalesOrderNo.Text="SO20071026001"; //這裡就可以設了.
}
}
而你那一題我會這樣解
public static class SMTP{
private static string connection="xxxxxxxx";
public static string Connection{
retrun connection;
}
public class SalesOrderForm:WindowForm{
private void SetInitialVaule(){
this.lbSalesOrderNo.Text=SMTP.Connection;
}
}
}
-
HI K Sir:
下面程式碼給你參考 ︿︿
程式碼區塊
static TextBox ErrMsgBox;public Form1()
{
InitializeComponent();
ErrMsgBox = this.textBox1;
}
public static void GettkConnstr_SMTP()
{
try
{
}
catch (Exception )
{
if (ErrMsgBox != null)
{
ErrMsgBox.Text = "如果程式發生錯誤時,希望可以在FORM中的textBox上留下訊息!";
}
}}
-
你越來越過份,越來越過火了!,越來越難符合你的需求了,其實你的問題只是一般的需求,但要在這討論區裡這樣一問一答不知要寫到何年何月,我這邊給你一個方案,我以前用過的(我現在用的是WPF),你照裡面的學,你就能做出專家的的Windows程式,還有一些OO,跟Interface的應用.
http://msdn2.microsoft.com/en-us/library/aa480450.aspx