Click here to Skip to main content
14,599,188 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hi
I am trying to convert below C# code to VB.net through code converte, but having error on one line which i cannot resolve
(c# code link : Changing border color of GroupBox[^] )
C#
parent.Paint += new PaintEventHandler( OnParentPaint );


vb code:- (Also see in what i have tried for vb.net code)
parent.Paint += New PaintEventHandler(AddressOf OnParentPaint)

underlines in red below text and gives error

Parent.Paint

Error: 'Public Event Paint As PaintEventHandler' is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event.


C# code
       /// <summary>
       /// Parent Changed Event
       /// </summary>
       /// <param name="e">event arguments</param>
       protected override void OnParentChanged( EventArgs e )
       {
           base.OnParentChanged( e );
           Control parent = this.Parent;
           while ( null != parent )
           {
               if ( null != parent )
               {
                   parent.Paint += new PaintEventHandler( OnParentPaint );
               }
               parent = parent.Parent;
           }
       }

       /// <summary>
       /// Parent Paint Event
       /// </summary>
       /// <param name="sender">sender object</param>
       /// <param name="e">event arguments</param>

private void OnParentPaint( object sender, PaintEventArgs e )
       {
           this.Refresh();
       }


What I have tried:

VB.NET code
Protected Overrides Sub OnParentChanged(ByVal e As EventArgs)
        MyBase.OnParentChanged(e)
        Dim parent As Control = Me.Parent

        While parent IsNot Nothing

            If parent IsNot Nothing Then
                parent.Paint += New PaintEventHandler(AddressOf OnParentPaint)
            End If

            parent = parent.Parent
        End While
    End Sub
Posted
Updated 13-May-20 3:47am
v4
Comments
Richard MacCutchan 12-May-20 15:35pm
   
You need to change your code as directed by the error message.
Rate this:
Please Sign up or sign in to vote.

Solution 1

You need to use AddHandler in VB.NET to add event handlers:
AddHandler Statement - Visual Basic | Microsoft Docs[^]
AddHandler parent.Paint, AddressOf OnParentPaint
   
Comments
pravin9455 12-May-20 16:30pm
   
Thanks
Rate this:
Please Sign up or sign in to vote.

Solution 2

You should try using Sharp Develop it is pretty accurate.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100