1
.net控件已被引用並添加到vb6項目中。它還顯示了我在界面中的事件。但是,vb6沒有註冊這些事件,我不知道爲什麼。我已經閱讀了幾十篇關於這個主題的文章,使用了一個工作的.Net Control/vb6的代碼。這是我第一次循環賽與活動所以它可能是一些非常小的我失蹤,但這裏的代碼:如何在vb6中收聽C#.NET的activeX控件的事件
C#.NET
[ComVisible (true)]
[Guid(CustomerCreditControl.EventsId)]
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface ICustomerCreditControlEvents
{
[DispId(1)]
void Test();
}
[ComVisible(true)]
[Guid(CustomerCreditControl.InterfaceId)]
[InterfaceType(ComInterfaceType.InterfaceIsDual)]
public interface ICustomerCreditControl
{
void SetAccount(string customerNumber, int generatorId);
string CreditHold { get; }
}
[ComVisible(true)]
[Guid(CustomerCreditControl.ClassId)]
[ClassInterface(ClassInterfaceType.None)]
[ComSourceInterfaces(typeof(ICustomerCreditControlEvents))]
public partial class CustomerCreditControl : UserControl, ICustomerCreditControl
{
public delegate void TestEventHandler();
public event TestEventHandler TestEvent;
[ComRegisterFunction()]
private static void Register(Type t)
{
ComRegistration.RegisterControl(t, "");
}
[ComUnregisterFunction()]
private static void Unregister(Type t)
{
ComRegistration.UnregisterControl(t);
}
public CustomerCreditControl()
{
InitializeComponent();
}
public void SetAccount(string customerNumber, int generatorId)
{
_customer = RCI.DataAccess.DataFactory.Current.AccountService.GetCustomer(customerNumber.Trim());
SetAccount(_customer, generatorId);
}
public void btnNewSalesOrder_Click(object sender, EventArgs e)
{
if (TestEvent != null)
{
MessageBox.Show("Test Event Fired");
TestEvent();
}
else
MessageBox.Show("TestEvent = null");
string[] SOI = {"a","b","c"};
MessageBox.Show(SOI.ToString());
OnNewSalesOrder(ref SOI);
}
}
VB6
Private Sub customerCreditInfo_Test()
MsgBox "Test 2"
End Sub
VB6的代碼識別測試事件,但它不會註冊到事件。該控件放置在vb6表單上。我有'MsgBox'測試2''就像一個測試。項目引用了tlb,並將activeX添加到工具箱組件中。我已經從Windows註銷這個DLL並通過並從註冊表中刪除所有實例。我正在使用regasm/register/codebase/tlb來註冊該dll。
使用Visual Studio 2008,.net 2.0和在Windows 7計算機上編譯。
我錯過了什麼?
謝謝,發佈後不久,我看到了這個錯誤,並糾正它。有時在查看代碼後,您必須離開並再次查看它:)感謝您的迴應! – EZE