2012-07-06 6 views
0

17 가지 옵션이있는 응용 프로그램에 콤보 상자가 있습니다. 내 코드에는 17 가지 옵션 모두에 대해 if 문이 있습니다. 내가 콤보 상자에 즉 블랙이나 다크 블루를 선택 무엇을 인쇄 할 수 있었다콤보 상자의 각 항목에 문자열 할당

int colorchoice = colorSelect.SelectedIndex; 
if (colorchoice == 0) 
{ 
textBox1.AppendText("the color is black"); 
} 
if (colorchoice == 1) 
{ 
textBox1.AppendText("the color is dark blue"); 
} 
and so on... 

그러나, 나는 공백이나 캡이없는 것으로 인쇄 무엇을해야합니다.

if (colorchoice == 0) 
{ 
textBox1.AppendText("the color is " + colorSelect.SelectedText); 
} 

결과는 검은 색이거나 진한 파란색이어야합니다. 내 콤보 상자의 대문자와 공백을 변경하지 않고 어떻게하면이 작업을 수행 할 수 있습니까? 그래도 여전히 멋져 보이지만 필요한 것은 인쇄 할 것입니다.

내 아이디어는 각각 17 개의 옵션에 문자열을 할당하는 것이지만 어떻게해야 할지를 파악하지 못했습니다.

도움을 주시면 감사하겠습니다. 감사!

답변

4

Q1however, I need what is printed to have no spaces or caps.

Ans1

textBox1.AppendText("the color is " 
     + colorSelect.SelectedText.ToLower().Replace(" ", "")); 

Q2 : 위의 코드가 콤보 상자에 영향을주지 않습니다 :How could I do this without changing the caps and spaces in my combo box so it still looks nice but will print out what I need?

Ans By의 2.

Q3 :My idea was to assign a string to each of the 17 options, but I have not been able to figure out how to do this.

Ans3 :가 왜 그런

string[] myarray = new string[]{ "Black", "Dark Blue" , ....}; 

같은 항목의 배열을 만들

textBox1.AppendText("the color is " + 
    myarr[colorSelect.SelectedIndex].ToLower().Replace(" ", "")); 
로 사용하지 마십시오
관련 문제