用参数C#winform到dll

时间:2014-04-25 08:12:55

标签: c# .net winforms

在VB.Net中将Windows窗体编译为DLL。 DLL接受参数值和参数,而不调用DLL值。并希望在C#win形式中相同。 有可能吗?怎么样?

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

1 个答案:

答案 0 :(得分:0)

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

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

<强>更新

根据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;
    }
}
相关问题