Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# to VB.Net Syntax conversion

Tags:

vb.net

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()
        {...}
like image 509
Manohar Avatar asked Feb 25 '26 21:02

Manohar


2 Answers

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
like image 107
Adam Robinson Avatar answered Mar 01 '26 01:03

Adam Robinson


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
like image 31
David Glass Avatar answered Mar 01 '26 03:03

David Glass



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!