Results 1 to 4 of 4

Thread: [RESOLVED] Need help converting CSharp to VB.net

  1. #1

    Thread Starter
    Member MicLovin's Avatar
    Join Date
    Jul 2008
    Location
    Under a rock
    Posts
    62

    Resolved [RESOLVED] Need help converting CSharp to VB.net

    I have been trying to design a custom tabcontrol in vb.net used a codeproject example to develop the said tabcontrol but the example is in C# I have converted all parts and theres only one error i cant seem to work around could you guys help?

    C# Code Code:
    1. void ColorTabControl_ControlAdded(object sender, ControlEventArgs e)
    2.         {
    3.             if (e.Control.GetType() == typeof(TabPage))
    4.             {
    5.                 e.Control.Font = new Font(e.Control.Font, e.Control.Font.Style & ~FontStyle.Bold);
    6.             }
    7.         }
    VB Code That I think it is... Code:
    1. Private Sub ColorTab_ControlAdded(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ControlEventArgs) Handles MyBase.ControlAdded
    2. ' ERROR: 'is' expected                            \/
    3.         If e.Control.GetType() = typeOf(Tabpage) Then
    4.             e.Control.Font = New Font(e.Control.Font, e.Control.Font.Style & FontStyle.Bold)
    5.         End If
    6.     End Sub

    Sorry if this is the wrong section since my result code will ve in vb thats why i posted it here.
    Beginner: Java
    Intermediate: VB.Net, C#, Delphi, Perl
    Master: HTML, XHTML, PHP, JavaScript, Pascal, SCAR

  2. #2
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: Need help converting CSharp to VB.net

    Try
    Code:
    If TypeOf e.Control Is TabPage Then ....
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  3. #3
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Need help converting CSharp to VB.net

    I wouldn't even bother to check what type of control it is.

    ColorTab is a tabcontrol right? TabControls can only have 1 type of control added to them, and that is tabpages. If you try to add any control to a tabcontrol, that is not a tabpage, an exception will occur telling you what I am telling you. So the ControlAdded event of a tabcontrol WILL NEVER FIRE unless a tabpage was actually added to the tabcontrol, so there is no need to check that it is that type. It will always be a tabpage.

  4. #4
    Fanatic Member
    Join Date
    Jan 2006
    Posts
    710

    Re: [RESOLVED] Need help converting CSharp to VB.net

    The 'keyword overlap' can be confusing.

    The VB equivalent is:
    Code:
    Private Sub ColorTabControl_ControlAdded(ByVal sender As Object, ByVal e As ControlEventArgs)
    	If e.Control.GetType() Is GetType(TabPage) Then
    		e.Control.Font = New Font(e.Control.Font, e.Control.Font.Style And (Not FontStyle.Bold))
    	End If
    End Sub
    David Anton
    Convert between VB, C#, C++, & Java
    www.tangiblesoftwaresolutions.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width