如何举办活动? [英] How to raise events?
问题描述
您好,我有一些有趣的代码正在尝试解决,但是即时消息是从C#到VB.net转换.
Hello I have an interesting bit of code which I am trying to fix but the error im getting is from a C# to VB.net conversion.
Error 1 'Public Event CurrentPath(hive As String, path As String)' is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event. C:\Users\Admin\Desktop\Registry Cleaner VB.NET\Form1.vb 287 9 VTRegScan
有问题的代码是:
the code in question is:
_RegScan.CurrentPath += New cRegScan.CurrentPathDelegate(AddressOf RegScan_CurrentPath)
在代码_RegScan中是:
in the code _RegScan is :
Private _RegScan As cRegScan 'which is a different class within the project.
currentpath是:
currentpath is :
Public Event CurrentPath As CurrentPathDelegate
导致currentpathdelegate为:
which leads to currentpathdelegate which is :
Public Delegate Sub CurrentPathDelegate(ByVal hive As String, ByVal path As String)
我可以提供有关该代码的最后一部分的信息是RegScan_CurrentPath,它是一个私有子目录:
The last section of this code that i can give information about is RegScan_CurrentPath which is a private sub :
Private Sub RegScan_CurrentPath(ByVal hive As String, ByVal path As String)
_sHive = hive
_sPath = path
End Sub
在私有子配置单元和路径中是字符串和_sHive,_sPath ="
对于这个问题,我该如何纠正这个问题以引发事件?
提前谢谢!!
C#中的代码就像这样....
within the private sub hive and path are strings and _sHive , _sPath = ""
For this question how might I correct this problem to raise the event?
thank you in advance!!
The code in C# is like so....
private void InitFields()
{
_RegScan = new cRegScan();
_RegScan.CurrentPath += new cRegScan.CurrentPathDelegate(RegScan_CurrentPath);
_RegScan.KeyCount += new cRegScan.KeyCountDelegate(RegScan_KeyCount);
_RegScan.LabelChange += new cRegScan.LabelChangeDelegate(RegScan_LabelChange);
_RegScan.MatchItem += new cRegScan.MatchItemDelegate(RegScan_MatchItem);
_RegScan.ProcessChange += new cRegScan.ProcessChangeDelegate(RegScan_ProcessChange);
_RegScan.ProcessCompleted += new cRegScan.ProcessCompletedEventHandler(RegScan_ProcessCompleted);
_RegScan.ScanComplete += new cRegScan.ScanCompleteDelegate(RegScan_ScanComplete);
_RegScan.SubScanComplete += new cRegScan.SubScanCompleteDelegate(RegScan_SubScanComplete);
_RegScan.ScanCount += new cRegScan.ScanCountDelegate(RegScan_ScanCount);
_RegScan.StatusChange += new cRegScan.StatusChangeDelegate(RegScan_StatusChange);
}
public event CurrentPathDelegate CurrentPath;
private void RegScan_CurrentPath(string hive, string path)
{
_sHive = hive;
_sPath = path;
}
#region Delegates
public delegate void LabelChangeDelegate(string phase, string label);
public delegate void CurrentPathDelegate(string hive, string path);
public delegate void KeyCountDelegate();
public delegate void MatchItemDelegate(cLightning.ROOT_KEY root, string subkey, string value, string data, RESULT_TYPE id);
public delegate void StatusChangeDelegate(string label);
public delegate void ProcessChangeDelegate();
public delegate void ScanCountDelegate(int count);
public delegate void ScanCompleteDelegate();
public delegate void SubScanCompleteDelegate(string id);
#endregion
#region Events
[Description("Status update")]
public event LabelChangeDelegate LabelChange;
[Description("Current processing path")]
public event CurrentPathDelegate CurrentPath;
[Description("Key processed count")]
public event KeyCountDelegate KeyCount;
[Description("Match item was found")]
public event MatchItemDelegate MatchItem;
[Description("Processing status has changed")]
public event StatusChangeDelegate StatusChange;
[Description("Processing shifted to new task")]
public event ProcessChangeDelegate ProcessChange;
[Description("Task counter")]
public event ScanCountDelegate ScanCount;
[Description("Scan Completed")]
public event ScanCompleteDelegate ScanComplete;
[Description("Scan Completed")]
public event SubScanCompleteDelegate SubScanComplete;
#endregion
我希望我已经提供了足够的解决方案,谢谢您..
I hope I have provided enough for a solution thank you..
推荐答案
您始终可以仔细阅读错误消息.它并不能完全向您隐藏解决方案:
You could always read the error message carefully. It doesn''t exactly hide the solution from you:
is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event
因此,用于"RaiseEvent"的快速Google会将您直接带到MSDN: RaiseEvent [ ^ ]通过280,000页的信息列表.
将来,请尝试至少自己进行基础研究,不要浪费您或我们的时间.
So a quick google for "RaiseEvent" will take you directly to MSDN: RaiseEvent[^] via a list of 280,000 pages of information.
In future, please try to do at least basic research yourself, and not waste your time or ours.
请提供C#代码,以便在此之后我可以提供适当的解决方案.
Please provide C# code so after that I can provide proper solution.
这篇关于如何举办活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!