【问题标题】:How do I call the void on another page when I click on the button?当我单击按钮时,如何在另一个页面上调用 void?
【发布时间】:2020-01-28 14:56:01
【问题描述】:

我有一个 Module.cs,我想在单击按钮时运行模块内部的 void。我怎么称呼虚无?

模块.cs:

public void CreateInventorApplication()
{
    // İnventorün Yüklenmesini Bekle
    while (!InvApp.Ready)
    {
        System.Windows.Forms.Application.DoEvents();
    }

    DefaultCaption = InvApp.Caption;
    InvApp.Visible = true;
    WatchTimer.Enabled = true;

    StatusType = StatusTypeEnum.Online;
    StatusMessage = "InventorPreparing";

}

Form1.cs:

private void button1_Click(object sender, EventArgs e)
{

}

【问题讨论】:

  • 您想从您的表单按钮单击处理程序中调用 CreateInventorApplication 方法吗?你的问题不清楚。同时提供 Module.cs 中的代码
  • 是的,我想调用 CreateInventorApplication 方法

标签: c# .net methods


【解决方案1】:

您的措辞有些含糊,但我假设您希望在单击按钮时运行“CreateInventorApplication”。

您的点击事件方法需要引用您的 Module 类的实例。您将需要创建一个 Module 实例,使该实例可用于您的 button1_Click 方法,然后调用它。你可以这样做。

private void button1_Click(object sender, EventArgs e)
{
    // Create an instance of the Module class that the button click event can access.
    Module myModule = new Module();
    // Call the void function using the instance we just created.
    myModule.CreateInventorApplication();
}

【讨论】:

    【解决方案2】:

    您的 void 需要公开,否则其他类和文件无法访问。

    public void button1_Click(object sender, EventArgs e)
    {
    }
    

    【讨论】:

      猜你喜欢
      • 2014-06-28
      • 1970-01-01
      • 2015-11-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-28
      相关资源
      最近更新 更多