2

Can any one translate the following syntax to vb.net.

m_TextBox.Loaded += TextBoxLoaded
m_TextBox.Loaded -= TextBoxLoaded;
private void TextBoxLoaded(object sender, RoutedEventArgs e)
 {
   Init();
 }

..
containsTextProp.AddValueChanged(m_TextBox, (sender, args) => UpdateAdorner());
...
private void UpdateAdorner()
        {...}

4 Answers 4

6

Here it is:

AddHandler m_TextBox.Loaded, AddressOf TextBoxLoaded
RemoveHandler m_TextBox.Loaded, AddressOf TextBoxLoaded

Private Sub TextBoxLoaded(ByVal sender as Object, ByVal e as RoutedEventArgs)
    Init()
End Sub

Your call to AddValueChanged can't be directly translated, as VB.NET's lambda expression support is not as robust as C#'s. In particular, VB.NET lambdas must be an expression, so you must either return a value or call a Function. In your case, you would be calling a Sub, which isn't allowed in VB.NET. You should consider changing the signature of UpdateAdorner to be a standard event handler (like the TextBoxLoaded method) and pass AddressOf UpdateAdoerner to AddValueChanged.

Like this:

containsTextProp.AddValueChanged(m_TextBox, AddressOf UpdateAdorner);

...

Private Sub UpdateAdorner(ByVal sender as Object, ByVal e as EventArgs)
    ... 
End Sub
Sign up to request clarification or add additional context in comments.

Comments

3

There are plenty of online converters, you shuold probably try that first next time and post here if it doesn't work or you have a problem.

AddHandler m_TextBox.Loaded, AddressOf TextBoxLoaded     ' per @Adam Robinson'
RemoveHandler m_TextBox.Loaded, AddressOf TextBoxLoaded  ' per @Adam Robinson'

Private Sub TextBoxLoaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
  Init()
End Sub

Private Sub UpdateAdorner()

End Sub

4 Comments

i tried Developer Fusion's Converter and Telerik converter.. converted code is giving me compile time errors... like use RaiseEvent ... new to vb.net ..so asked here...
Events in VB.NET use AddHandler and RemoveHandler, not the operator syntax of C# as you have here.
getting compile time errors with above syntax.. using Adam's syntax... anyway thanx for the replay and +1
@Adam, see I just used the converter and didn't notice, thanks!
1

You might find the "C# and VB.NET Comparison Cheat Sheet" useful. http://aspalliance.com/625

Comments

1

You can toss it in an app, build it, then open the app in .NET reflector. .NET Reflector can take the IL and "turn it into" C#/VB.NET, etc.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.