首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

VB.NET的代码转为C#解决思路

2012-01-06 
VB.NET的代码转为C#Dim WithEvents RecoContext As SpeechLib.SpSharedRecoContextDim Grammar As SpeechL

VB.NET的代码转为C#
Dim WithEvents RecoContext As SpeechLib.SpSharedRecoContext
Dim Grammar As SpeechLib.ISpeechRecoGrammar

Dim m_bRecoRunning As Boolean
Dim m_cChars As Short


Private Sub SimpleDict_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
SetState(False)
m_cChars = 0
End Sub

Private Sub btnStart_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles btnStart.Click
System.Diagnostics.Debug.Assert(Not m_bRecoRunning, "")
If (RecoContext Is Nothing) Then
  RecoContext = New SpeechLib.SpSharedRecoContext
  Grammar = RecoContext.CreateGrammar(1)
  Grammar.DictationLoad()
  End If

Grammar.DictationSetState(SpeechLib.SpeechRuleState.SGDSActive)
SetState(True)
End Sub

Private Sub btnStop_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles btnStop.Click
System.Diagnostics.Debug.Assert(m_bRecoRunning, "")
Grammar.DictationSetState(SpeechLib.SpeechRuleState.SGDSInactive)
SetState(False)
End Sub


Private Sub RecoContext_Recognition(ByVal StreamNumber As Integer, ByVal StreamPosition As Object, ByVal RecognitionType As SpeechLib.SpeechRecognitionType, ByVal Result As SpeechLib.ISpeechRecoResult) Handles RecoContext.Recognition
Dim strText As String
strText = Result.PhraseInfo.GetText
txtSpeech.SelectionStart = m_cChars
txtSpeech.SelectedText = strText & " "
m_cChars = m_cChars + 1 + Len(strText)
End Sub
Private Sub SetState(ByVal bNewState As Boolean)
  m_bRecoRunning = bNewState
  btnStart.Enabled = Not m_bRecoRunning
  btnStop.Enabled = m_bRecoRunning
  End Sub


这段代码如何转为C#呢?

[解决办法]
http://labs.developerfusion.co.uk/convert/vb-to-csharp.aspx
[解决办法]

C# code
SpeechLib.SpSharedRecoContext RecoContext; SpeechLib.ISpeechRecoGrammar Grammar; bool m_bRecoRunning; short m_cChars; private void SimpleDict_Load(object eventSender, System.EventArgs eventArgs) {     SetState(false);     m_cChars = 0; } private void btnStart_Click(object eventSender, System.EventArgs eventArgs) {     System.Diagnostics.Debug.Assert(!m_bRecoRunning, "");     if ((RecoContext == null)) {         RecoContext = new SpeechLib.SpSharedRecoContext();         Grammar = RecoContext.CreateGrammar(1);         Grammar.DictationLoad();     }         Grammar.DictationSetState(SpeechLib.SpeechRuleState.SGDSActive);     SetState(true); } private void btnStop_Click(object eventSender, System.EventArgs eventArgs) {     System.Diagnostics.Debug.Assert(m_bRecoRunning, "");     Grammar.DictationSetState(SpeechLib.SpeechRuleState.SGDSInactive);     SetState(false); } private void RecoContext_Recognition(int StreamNumber, object StreamPosition, SpeechLib.SpeechRecognitionType RecognitionType, SpeechLib.ISpeechRecoResult Result) {     string strText;     strText = Result.PhraseInfo.GetText;     txtSpeech.SelectionStart = m_cChars;     txtSpeech.SelectedText = strText + " ";     m_cChars = m_cChars + 1 + Strings.Len(strText); } private void SetState(bool bNewState) {     m_bRecoRunning = bNewState;     btnStart.Enabled = !m_bRecoRunning;     btnStop.Enabled = m_bRecoRunning; } 

热点排行