我有一个带有进度条的主窗体,我想从名为“Logic”的外部类更新进度条...但是,主窗体上已经引用了 Logic。如果我尝试引用逻辑中的主窗体来更新进度条,我只会遇到堆栈溢出。
在四处搜索时,我遇到了很多有关BackgroundWorker的主题......但这不是我想要使用的。我在 Logic 类中有一些特定的位置,我想通过使用 Progressbar.PerformStep() 来更新主窗体上的进度条。我尝试在主窗体上创建一个方法来更新进度栏并从 Logic 类中调用该方法,但它再次缺少引用......而且我不能只使用 MainForm frm1 = new MainForm() 而不导致其他地方都有错误。我在这里感到很困惑。
[编辑]
这是带有解决方案的代码(谢谢你们)----
主要形式:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Natural_Language_Processor
{
public partial class frm_Main : Form
{
Logic logic = new Logic();
public frm_Main()
{
InitializeComponent();
}
private void frm_Main_Load(object sender, EventArgs e)
{
Timer.Start();
}
private void btn_Enter_Click(object sender, EventArgs e)
{
logic.Progress += new Logic.ProgressDelegate(DisplayProgess);
logic.RaiseProgress(0);
logic.str_Input = txt_Input.Text; …Run Code Online (Sandbox Code Playgroud)