[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:
void ColorTabControl_ControlAdded(object sender, ControlEventArgs e)
{
if (e.Control.GetType() == typeof(TabPage))
{
e.Control.Font = new Font(e.Control.Font, e.Control.Font.Style & ~FontStyle.Bold);
}
}
VB Code That I think it is... Code:
Private Sub ColorTab_ControlAdded(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ControlEventArgs) Handles MyBase.ControlAdded
' ERROR: 'is' expected \/
If e.Control.GetType() = typeOf(Tabpage) Then
e.Control.Font = New Font(e.Control.Font, e.Control.Font.Style & FontStyle.Bold)
End If
End Sub
Sorry if this is the wrong section since my result code will ve in vb thats why i posted it here.
Re: Need help converting CSharp to VB.net
Try
Code:
If TypeOf e.Control Is TabPage Then ....
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.
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