코드 편집기에서 작업 중이며 줄을 void 반환 메서드 내에서 keyargs 이벤트로 호출하려고합니다.다른 메소드에서 메소드를 호출하는 방법은 무엇입니까?
입력 키를 누르면 출력이 이루어져야하며 ComboBox에서 선택된 목록은 RichTextBox에있는 텍스트에 추가되어야합니다.
은 이제을 충족하기 위해,이 메소드를 호출하는 방법을 물어 싶습니다void Parse()
{
String inputLanguage =
"using System;\n" + "\n" +
"public class Stuff : Form { \n" +
" public static void Main(String args) {\n" +
"\n" + "\n" +
" }\n" +
"}\n";
// Foreach line in input,
// identify key words and format them when adding to the rich text box.
Regex r = new Regex("\\n");
String[] lines = r.Split(inputLanguage);
foreach (string l in lines)
{
ParseLine(l);
}
}
void ParseLine(string line)
{
Regex r = new Regex("([ \\t{}();])");
String[] tokens = r.Split(line);
foreach (string token in tokens)
{
// Set the token's default color and font.
rtb.SelectionColor = Color.Black;
rtb.SelectionFont = new Font("Courier New", 10, FontStyle.Regular);
// Check for a comment.
if (token == "//" || token.StartsWith("//"))
{
// Find the start of the comment and then extract the whole comment.
int index = line.IndexOf("//");
rtb.SelectedText = comment;
break;
}
// Check whether the token is a keyword.
var keywordsDef = new KeyWord();
String[] keywords = keywordsDef.keywords;
for (int i = 0; i < keywords.Length; i++)
{
if (keywords[i] == token)
{
// Apply alternative color and font to highlight keyword.
HighlighType.keywordsType(rtb);
break;
}
}
rtb.SelectedText = token;
}
rtb.SelectedText = "\n";
}
을이 하나 내에서 :
void lb_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Escape)
{
lb.Visible = false;
lb.Items.Clear();
}
if (e.KeyCode == Keys.Enter)
{
//ParseLine(string line);
Parse();
string comment = line.Substring(index, line.Length - index);
rtb.SelectedText = comment + " " + lb.SelectedIndex.ToString();
}
}
정말 도움이 필요합니다. 미리 큰 감사드립니다!
주석 처리 된 라인의 문제점은 무엇입니까? 나는// ParseLine (string line);을 의미합니다. –
3 개의 오류가 나타납니다. 유효하지 않은 표현식 'string', 유효하지 않은 표현식 ')'; 예상 –
처음 알지 못했습니다. 'ParseLine (line);'메소드 호출시 타입을 지정할 필요가 없습니다. –