简体   繁体   English

C# winform 到 dll 带参数

[英]C# winform to dll with parameter

In VB.Net Windows Forms compiled to DLL.在 VB.Net Windows 窗体中编译为 DLL。 DLL accepts a parameter value and parameter without value DLL not called. DLL 接受一个参数值和没有值的参数 DLL 不被调用。 And want same in C# win form.并希望在 C# win 形式中相同。 Can it be possible?有可能吗? then how?那怎么办?

Public Class Form1
    Public gl_Permission As New DataTable
    Public gl_FomCode As String
    Public gl_FormName As String
    Public gl_dtServer As DateTime

    Public Sub New(ByVal Permission As DataTable, ByVal FormCode As String, ByVal FormName As String, ByVal dtServer As DateTime)

        ' This call is required by the designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        gl_Permission = Permission
        gl_FomCode = FormCode
        gl_FormName = FormName
        gl_dtServer = dtServer
    End Sub

    Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        Label2.Text = gl_FomCode
        Label3.Text = gl_FormName
    End Sub

End Class

If I understand this correctly you want to create an instance of the form without any parameters in the constructor?如果我理解正确,您想在构造函数中创建一个没有任何参数的表单实例吗? If so just add the extra constructor below and that should do the trick如果是这样,只需在下面添加额外的构造函数就可以了

Public Sub New()
    ' This call is required by the designer.
    InitializeComponent()
    ' Any other code you need should be placed here
End Sub

Update更新

Based on clarafications added by OP, the VB code above needs to be converted to C#根据OP添加的说明,上面的VB代码需要转换成C#

using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;

public partial class Form1
{
    private DataTable gl_Permission = new DataTable();
    private string gl_FomCode;
    private string gl_FormName;
    private DateTime gl_dtServer;

    public Form1()
    {
        InitializeComponent();            
    }

    public Form1(DataTable Permission, string FormCode, string FormName, DateTime dtServer)
    {
        InitializeComponent();            
       // Add any initialization after the InitializeComponent() call.
        gl_Permission = Permission;
        gl_FomCode = FormCode;
        gl_FormName = FormName;
        gl_dtServer = dtServer;
    }

    private void Form1_Load(object sender, System.EventArgs e)
    {
        Label2.Text = gl_FomCode;
        Label3.Text = gl_FormName;
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM