Click here to Skip to main content
15,886,075 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I have a problem on overriding method on vb.net

Here's the code :
VB
Protected Overrides Sub TabControl1_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles TabControl1.DrawItem
       MsgBox("Draw Item")

   End Sub


It throw me error :
Error 1 sub 'TabControl1_DrawItem' cannot be declared 'Overrides' because it does not override a sub in a base class. C:\Users\satrio.budiharmawan\AppData\Local\Temporary Projects\sieg01\Form1.vb 39 29 sieg01

The question is, how do I overrides that method?
Posted

1 solution

If you are overriding the DrawItem method you would override Protected Overrides Sub DrawItem..., but only if the class you are writing derives from TabControl.
If this is a Form where you simply want to create a handler for the TabControl1.DrawItem method, then just remove the Overrides from your sub definition. (This second point is what I think is more likely.)
 
Share this answer
 
Comments
satrio_budidharmawan 7-Jan-13 21:10pm    
Well, what i tried to do is adding something to my tabpage (close button, just like tab in browser, such as Firefox). So in that case, according to this http://www.codeproject.com/Articles/20050/FireFox-like-Tab-Control article I need to overrides that method.
fjdiewornncalwe 8-Jan-13 10:19am    
As I said in my answer already, if you are writing this code in a class that inherits from TabControl then you need to override, but I suspect that you have placed a TabControl on your Form/UserControl and are trying to get to the DrawItem of the TabControl that way. In that situation, you need to take the Overrides out and attach the DrawItem event for the TabControl to your method.
satrio_budidharmawan 8-Jan-13 20:08pm    
ah, I just realized what you meant on your answer..hahaha,
So, I need to create my tabControl on the fly?not attach it on my form from designer?
But yes I've tried to write my code on TabControl1_OnDrawItem which created by .Net, but it didn't work.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900