【问题标题】:C# winform to dll with parameterC# winform 到带参数的 dll
【发布时间】:2014-04-25 08:12:55
【问题描述】:

在 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

【问题讨论】:

  • 你能更好地解释一下你在这里想要实现的目标吗? :)

标签: c# .net winforms


【解决方案1】:

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

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;
    }
}

【讨论】:

  • 使用 c# 创建一个新项目并按照建议进行更改,但错误消息 - “在声明类型 'WinFormC.Form1' 时缺少部分修饰符;此类型的另一个部分声明存在”
  • 将“public class Form1”行更改为“public partial class Form1”
  • program.cs 中显示错误——“XXX 不包含采用 0 个参数的构造函数”
  • 好的修复,试试更新的代码。还请尝试阅读错误内容,您发布的所有错误的答案都可以轻松解决,我不介意提供帮助,但我不会为您做所有事情。
  • 感谢您的指导,但我们仍然不能强迫您提供参数,因为在解决方案中,公共 Form1 都处于超载状态。
猜你喜欢
  • 1970-01-01
  • 2013-07-14
  • 2020-12-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-02-26
  • 2018-07-12
相关资源
最近更新 更多