如果方法在另一个类文件中,如何调用方法来填充主文件中的表单控件?(How to call method to populate form controls in the main file if th

编程入门 行业动态 更新时间:2024-10-11 23:22:50
如果方法在另一个类文件中,如何调用方法来填充主文件中的表单控件?(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>); }

更多推荐

本文发布于:2023-08-05 16:42:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1437176.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:主文   表单   方法来   控件   文件

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!