如何在另一个类中调用C#中的另一个方法

时间:2016-11-28 10:29:17

标签: c#

  1. 我想使用C#develop autocad并构建一个新的Windows窗体项目并在其上添加一个按钮,我将把参数放在窗体中。
  2. 问题是:我想在点击按钮下面编写代码来调用另一个类中的方法

    private void guocheng1_Click(object sender, EventArgs e)
    {
        MyCommands myMyCommands = new MyCommands();
    
        MyCommands.Myds = new Myds() ;
    }
    
    
    public void Myds() // This method can have any name
    {
        // Put your command code here
        Document doc = Application.DocumentManager.MdiActiveDocument;
        Database db = doc.Database;
        Editor ed = doc.Editor;
        ed.WriteMessage("\r\nThis   is  an  Initialization  Startup text.");   
    }
    
  3. 我不知道出了什么问题。

1 个答案:

答案 0 :(得分:1)

 private void guocheng1_Click(object sender, EventArgs e)
    {
        MyCommands myMyCommands = new MyCommands();

        myMyCommands.Myds() ; //this, its not a static method. Also, this is how you call a method. 
     }

public void Myds() // This method can have any name
{
    // Put your command code here
    Document doc = Application.DocumentManager.MdiActiveDocument;
    Database db = doc.Database;
    Editor ed = doc.Editor;
    ed.WriteMessage("\r\nThis   is  an  Initialization  Startup text.");

}