2016-11-27 20 views
0

小白程序員在這裏很抱歉,如果我失去了一些東西很簡單的使用,這裏是我的代碼:非可調用成員「System.Windows.Forms.Control.Text」不能等的方法

namespace Programming_Assignment_2 
{ 
    public partial class Form1 : Form 
    { 
    string combination; 
    const int MinLength = 6; 

    bool CombinationCheck(string combination) 
    { 
     if (combination.Length > 5) 
      return true; 
     else 
      return false; 
    } 

    public Form1() 
    { 
     InitializeComponent(); 
    } 

    private void Form1_Load(object sender, EventArgs e) 
    { 
    } 

    private void btn_SetComb_Click(object sender, EventArgs e) 
    { 
     combination = My_Dialogs.InputBox("Please enter a password longer than 5 characters: "); 
     if (combination.Length < MinLength) 
      My_Dialogs.InputBox("Error! Please make sure password is longer than 5 characters: "); 
     else 
     { 
      MessageBox.Show("Thank you, password saved."); 
     } 
    } 

    private void label1_Click(object sender, EventArgs e) 
    { 
    } 

    private void text_SafeStatus_TextChanged(object sender, EventArgs e) 
    {      
     bool CombinationCheck; 
     if (
     text_SafeStatus.Text("Combination Set")); 
     else (
     text_SafeStatus.Text("Combination Not Set")); 
    } 
    } 
} 

所以底部的文本返回標題中的錯誤,我在這裏和那裏還有幾個小錯誤,例如

只有賦值,調用,增量,遞減,等待和新對象表達式可以用作聲明

之後的其他支架..

什麼可能是一個noob問題,但我似乎無法找到答案,即專門幫我

編輯1再次抱歉:

所以文本錯誤是固定的,我感謝,但我有一個問題這是試圖從一個布爾真/假值,並用它來確定哪些文本框中顯示..

if bool CombinationCheck; 
if CombinationCheck true; 
text_SafeStatus.Text = "Combination Set"; 
else 
text_SafeStatus.Text = "Combination Not Set"; 

這就是我現在有,我不知道如何使這項工作。

+0

如果(combinationCheck){text_SafeStatus.Text = 「組合套裝」}其他{...} –

+0

@JeroenHeier怎麼樣'CombinationCheck? text_SafeStatus.Text =「組合集」:text_SafeStatus.Text =「組合未設置」;' – devRicher

+0

@CameronFairbun,你應該接受解決你的_original_問題的答案併發布_new_問題的新問題 – user3598756

回答

0

您需要指定TextBox文本屬性,因爲沒有這種方法稱爲Text(),所以請使用賦值運算符=來分配值。

text_SafeStatus.Text = "Combination Set"; 

如果你需要檢查Textbox的值,使用==比較運算,不作比較使用單=,按照例如=以上是賦值運算符,只用於分配的值。

if (text_SafeStatus.Text == "Combination Set") 
    // do something // 

編輯

CombinationCheck返回true或false取決於字符串的長度,你傳遞給方法。

將此代碼段從text_SafeStatus_TextChanged移至btn_SetComb_Click事件。將其粘貼到現有代碼下方。

private void btn_SetComb_Click(object sender, EventArgs e) 
{ 
    // .. existing codes .. // 

    if (CombinationCheck(combination)) 
     text_SafeStatus.Text = "Combination set"; 
    else 
     text_SafeStatus.Text = "Combination not set"; 
} 
+0

嘿,謝謝你的快速回復,那修正了那個錯誤。我有另一個問題是如何使用bool的值..如果這樣bool CombinationCheck; 如果CombinationCheck true; text_SafeStatus.Text =「組合集」; else text_SafeStatus.Text =「組合未設置」; –

+0

也解釋如何解決'只有分配,調用,增量,減量,等待和新的對象表達式可以用作行48中的語句錯誤。 – devRicher

+0

@CameronFairburn你試過更新後的代碼嗎? – abdul

相關問題