带有参数的C#winform到dll

本文关键字:dll C#winform 参数 | 更新日期: 2023-09-27 17:59:56

在VB.Net中编译为DLL的Windows窗体。DLL接受参数值和不带值的参数DLL未调用。并希望以C#获胜的形式取得同样的成绩。这可能吗?那么怎么做呢?

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

带有参数的C#winform到dll

如果我理解正确,你想在构造函数中创建一个没有任何参数的表单实例吗?如果是这样的话,只需在下面添加额外的构造函数,就可以完成

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

更新

基于OP添加的claraficasions,上面的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;
    }
}