如何将窗体引用从EXE应用程序传递到DLL程序集
我有一个vb.net Windows应用程序.它具有一个带有状态栏的表单,用于向用户提供处理状态(例如"x的处理记录x").
我想调用一个被引用的DLL项目,并将进行所有处理.我希望DLL将处理状态(例如正在处理x的x")传递回Windows应用程序表单状态栏.
但是,我不知道如何将窗体名称作为对Dll项目的引用.
我已经试过了:
Window应用程序:
returnvalue = MyProcess.Start(Me)
DLL项目:
类名是MyProcess
公共函数开始(以表格形式表示)为布尔值
但是,在dll项目中无法识别表格.我尝试添加Imports.Windows.System.Form-但除非实际添加表单,否则无法这样做.
需要帮助. thanx
I have a vb.net windows application. It has a form with a Status Bar that is used to provide the user with processing status (e.g. "processing record x of x").
I want to call a DLL project that is referenced and will do all the processing. I want the DLL to pass back to the Windows Application Form Status Bar the processing status (e.g. "processing x of x").
However, I do not know how to pass the Forms Name as a reference to the Dll Project.
I''ve tried this:
Window App:
returnvalue = MyProcess.Start(Me)
DLL Project:
Class Name is MyProcess
Public Function Start(frm as Form) as Boolean
However, in the dll project Form is not recognized. I''ve tried adding Imports.Windows.System.Form - but can''t do that unless I actually add a form.
Help needed. thanx
BTW,您是否在DLL项目中添加了对Windows.System.Form的引用? [快速猜测,需要在您的问题中添加更多详细信息]
BTW, have you added reference to Windows.System.Form in your DLL project?!
[Just a quick guess, more details required to be put in your question]
正如我在第一篇文章中所说的那样-我在DLL项目中添加了Imports.Windows.System.Form .实际上,.net不允许我添加Imports.Windows.System.Form,除非我实际上向dll项目中添加了一个表单-最终我只是为了通过该步骤而完成.
为了简单地尝试使之工作,我将Windows App中的控件从状态栏更改为文本框.完整的代码现在显示为:
Windows应用程序:
ReturnValue = MyProcess.Start(me)
Dll项目:
类名是MyProcess
Imports.Windows.System.Form
``我实际上必须添加一个表格才能输入此Imports
公共函数开始(以表格形式表示)为布尔值
对于x = 1到1000
frm.TextBox1.Text = x
下一个X
开始=真实
最终功能
在DLL项目中-intellisense强调TextBox1为错误.我无法超越这一步.由于此错误,我无法构建DLL项目.因此,这是行不通的.我必须相信有某种方法可以执行此操作-只需使用.net中DLL项目进程的状态来更新Windows应用程序文本框即可.我想我缺少了一些东西.感谢任何帮助/想法.
As I said in my first post - I have added the Imports.Windows.System.Form in the DLL Project. As a matter of fact, .net would not let me add Imports.Windows.System.Form unless I actually added a form to the dll project - which eventually I did just to get past that step.
To simply try and make this work, I changed the control in the Windows App from a status bar to a Text Box. The full code now reads:
Windows App:
ReturnValue = MyProcess.Start(me)
Dll Project:
Class Name is MyProcess
Imports.Windows.System.Form
''I had to actually add a form to get this Imports entered
Public Function Start(frm as Form) as Boolean
For x = 1 to 1000
frm.TextBox1.Text = x
Next X
Start = True
End Function
In the DLL Project - intellisense underlines TextBox1 as error. I can''t get past this step. I can''t build the DLL Project because of this error. Therefore this is not working. I have to believe there is some way to do this - simply updating a Windows App Textbox with status from a DLL Project process in .net. I think I am missing something. Appreciate any help/Ideas.
这是我最近的尝试.这会将x的值传递回我的Windows App文本框-但是只有最后一个x值(1000).我想取回每个x值作为其处理.我把vbcrlf放进去,看是否会回传每个x值.想知道BackgroundWorker是否会更好地用于我正在寻找的东西.
Here is my latest try. This is passing the value of x back to my Windows App textbox - however only the last x value (1000). I want to get back each x value as its processed. I put the vbcrlf in to see if it will post back each x value. Wondering if BackgroundWorker would be better to use for what I''m looking for.
Window App:
Imports MainDLL
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim myMainDll As New MainDLL.Class1
myMainDll.mytb = Me.TextBox1
myMainDll.MyProcess()
End Sub
End Class
Dll Project(MainDll):
Imports System.Windows.Forms
Public Class Class1
Private m_tb As TextBox
Public Property mytb() As TextBox
Get
Return m_tb
End Get
Set(ByVal tbname As TextBox)
m_tb = tbname
End Set
End Property
Public Function MyProcess() As Boolean
Dim x As Integer
For x = 1 To 1000
m_tb.Text = (x).ToString & vbCrLf
Next
MyProcess = True
End Function
End Class