如果方法在另一个类文件中,如何调用方法来填充主文件中的表单控件?(How to call method to populate form controls in the main file if the method is in another class file? [closed])
因此,在我的主要工作中,我对文件进行了一些处理,在处理完文件后,我在变量中保存了一些值。
在我的showResults类文件中,我有一个Results方法,它看起来像这样:
class ShowResults : Main { public void Results(string item, int counterL, int counterS, int counterB, long tick, int miss) { if (item == "Fbubble") { loadBubble.Text = counterL.ToString(); storeBubble.Text = counterS.ToString(); branchBubble.Text = counterB.ToString(); ticksBubble.Text = tick.ToString(); icMissInstrBubble.Text = miss.ToString(); } } }如何在我的主窗体类中调用它,以便填充必要的字段?
So in my main for I do some work with files and after processing them I save some values in variables.
In my showResults class file I have the Results method which looks something like this:
class ShowResults : Main { public void Results(string item, int counterL, int counterS, int counterB, long tick, int miss) { if (item == "Fbubble") { loadBubble.Text = counterL.ToString(); storeBubble.Text = counterS.ToString(); branchBubble.Text = counterB.ToString(); ticksBubble.Text = tick.ToString(); icMissInstrBubble.Text = miss.ToString(); } } }How do I call this in my main form class so it will populate the necessary fields?
最满意答案
我不知道你为什么要这样做,但如果你必须,我建议让它静止:
public static class ShowResults : Main { public static void Results(string item, int counterL, int counterS, int counterB, long tick, int miss) { if (item == "Fbubble") { loadBubble.Text = counterL.ToString(); storeBubble.Text = counterS.ToString(); branchBubble.Text = counterB.ToString(); ticksBubble.Text = tick.ToString(); icMissInstrBubble.Text = miss.ToString(); } } }用法可能是这样的:
button1_Click(object sender, EventArgs e) { ShowResults.Results(<String>, <Int32>, <Int32>, <Int32>, <long>, <Int32>); }I have no idea why you would want to do it this way, but if you must, I suggest making it static:
public static class ShowResults : Main { public static void Results(string item, int counterL, int counterS, int counterB, long tick, int miss) { if (item == "Fbubble") { loadBubble.Text = counterL.ToString(); storeBubble.Text = counterS.ToString(); branchBubble.Text = counterB.ToString(); ticksBubble.Text = tick.ToString(); icMissInstrBubble.Text = miss.ToString(); } } }Usage could be something like this:
button1_Click(object sender, EventArgs e) { ShowResults.Results(<String>, <Int32>, <Int32>, <Int32>, <long>, <Int32>); }更多推荐
发布评论