从函数/sub的表单上的参考控件



我强烈怀疑我想做的是不可能的,但是我可以使用确认。

我有一个我创建的类库来处理一些常见的subs&我经常使用的功能(某种形式或方式)。

其中一些subs&功能可能需要很长时间(通常在通过以某种方式处理记录的情况下)。在这些情况下,我通常具有该函数更新进度窗口(文本和步进进度栏)。

现在,我始终将它们放入班级库中,我显然无法期待特定的表格或控制在那里。但是我想保留功能。因此,我希望做的是为RichTextbox&创建可选的输入变量。将要更新的ProgressBar,以便我可以通过用于状态的控件的引用。

这可能吗?如果是这样,怎么样?当我尝试将任何输入定义为Windows.Forms.<anything> IntelliSense掉落时(强烈暗示我无法将它们输入为控件)。

谢谢!

更新:我正在尝试将引用添加到以下内容,指示System.Windows.Forms.<X>

指示错误
Public Function ResOut(ByVal D As DataTable, ByVal epath As String, ByVal SAName As String, ByVal Parent As String, ByRef PBar As System.Windows.Forms.ProgressBar, _
                       ByRef RTB As System.Windows.Forms.RichTextBox) As String
    '
    Dim res As String = ""
    Dim E As New Microsoft.Office.Interop.Excel.Application
    Dim wb As Microsoft.Office.Interop.Excel.Workbook = Nothing
    Dim ws As Microsoft.Office.Interop.Excel.Worksheet = Nothing
    Dim x As Long = 0
    Dim f As Long = 1
    Dim s As New JMLib.Status
    Dim Rng As Microsoft.Office.Interop.Excel.Range
    'Define the range
    Rng = ws.Range("A1:" & ColNumToStr(D.Columns.Count, epath) & D.Rows.Count)
    'Create the array
    Dim OArr(D.Rows.Count, x) As Object
    'Create a workbook for the data and capture the workbook and sheet for ease of reference
    Try
        wb = E.Workbooks.Add
        ws = wb.Worksheets(1)
    Catch ex As Exception
        res = "Encountered an error while creating the new workbook to export the results to. No data can be returned."
        EL.AddErr(res & " ResOut was called by " & Parent & ". Error Details: " & ex.Message, epath)
    End Try
    'Fill in headers
    If res = "" Then
        Try
            For Each c As DataColumn In D.Columns
                ws.Range("A1").Offset(0, x).Value = c.ColumnName
                x = x + 1
            Next
        Catch ex As Exception
            res = "Encountered an error while filling in the column headers. This will prevent any data from being returned."
            EL.AddErr(res & " ResOut was called by " & Parent & ". Error Details: " & ex.Message, epath)
        End Try
    End If
    'Setup the step & frequency for the Step Progress bar
    'Dim t() As Long = s.StatSetup(QR.Rows.Count, 58, "Query RunnerResOut" & QName, Replace(My.Settings.EPath, "<user>", Environment.UserName) & DStamp() & " Query Scheduler Log.txt")
    'f = t(0)
    'SProg.Step = t(1)
    'Convert the datatable to a 2D array
    If res = "" Then
        Try
            'Fill it
            x = 0
            For r As Long = 0 To D.Rows.Count - 1 Step 1
                Dim dr As DataRow = D.Rows(r)
                For c As Integer = 0 To D.Columns.Count - 1 Step 1
                    OArr(r, c) = dr.Item(c)
                Next
                x = x + 1
            Next
        Catch ex As Exception
            res = "Encountered an error while outputing the " & x + 1 & "-th record of " & D.Rows.Count & ". No data will be output."
            EL.AddErr(res & " ResOut was called by " & Parent & ". Error Details: " & ex.Message, epath)
        End Try
    End If
    'output the array to the target range
    If res = "" Then
        Try
            Rng.Value = OArr
            'Save the workbook
            wb.SaveAs(SAName)
            wb.Close(SaveChanges:=False)
        Catch ex As Exception
            res = "Encountered an error during the export of the results. Some data may have been exported. Review the contents of the Excel workbook that will be visible following this message for more" _
                    & " details."
            E.Visible = True
            wb.Activate()
            EL.AddErr(res & " ResOut was called by " & Parent & ". Error Details: " & ex.Message, epath)
        End Try
    Else
        'Close the workbook without saving
        wb.Close(SaveChanges:=False)
    End If
    'Cleanup the application
    Try
        E.Quit()
        System.Runtime.InteropServices.Marshal.ReleaseComObject(E)
        E = Nothing
        wb = Nothing
        ws = Nothing
        s = Nothing
        Rng = Nothing
        OArr = Nothing
        f = Nothing
        x = Nothing
    Catch ex As Exception
        EL.AddErr("Encountered an error while cleaning up the resources used in JMLibResOut. ResOut was called by " & Parent & ". Error Details: " & ex.Message, epath)
    End Try
    Return res
End Function

我是通过将参考引用到"进度栏/文本"框中的。

当类调用时,您可以设置参考。

在类中,如果参考文献没有任何内容,我什么都没有更新进度栏/文本框。


在用户书面类中没有什么具体的 - 这是一些库代码的示例:

Sub DisplayParcels(aAPNs() As String,...., Optional ProgBar As ProgressBar = Nothing)
...
    If ProgBar IsNot Nothing Then
        ProgBar.Maximum = aAPNs.Length
        ProgBar.Value = 0
        ProgBar.Visible = True
    End If
...
    For Each sAPN In aAPNs
...
         If ProgBar IsNot Nothing Then ProgBar.Value = iCnt
   Next
...
    If ProgBar IsNot Nothing Then ProgBar.Visible = False
End Sub

最新更新