- GUI呈現為表單輸入。
- 配合不同編譯版本,表單上的輸入控制項有一些需要被隱藏起來。
問題與解決方法:
- 同一份程式碼,要有不同編譯版本,採用Predefined macro(#if、#define、#elif……)。
- C#的GUI排版有FlowLayoutPanel和TableLayoutPanel。為了讓GUI呈現表單的整齊格式,採用TableLayoutPanel來排版。
- 要隱藏控制項,因為表單上的控制項是已知,所以要被隱藏的控制項設定狀態為Hide,包含相關的Label也要一併隱藏。
public delegate void PrintDelegate(string message);
public void PrintFuction(string str){
if(textBox.InvokeRequired){
this.Invoke(new PrintDelegate(str), new object[] { str });
}else{
textBox.Text += str;
}
}
public class ExecuteClass{
public void PrintFuction(string str){
Console.Write(str); //輸出字串
}
}
public class CallClass{
public delegate void PrintDelegate(string message); //宣告委派型別
public event PrintDelegate PrintEvent; //宣告事件
public void CallFuction(string message){
PrintEvent(message); //呼叫委派方法
}
}
public class MainClass{
public static void main(){
ExecuteClass execute = new ExecuteClass();
CallClass call = new CallClass();
call.PrintEvent += execute.PrintFuction; //對事件註冊方法
call.CallFuction("呼叫成功!");
}
}