Results 1 to 12 of 12

Thread: [RESOLVED] Custom Tab control & Custom Tab Page

  1. #1

    Thread Starter
    Fanatic Member TDQWERTY's Avatar
    Join Date
    Oct 2003
    Location
    Oporto & Leiria, Portugal / Luanda, Angola
    Posts
    972

    Resolved [RESOLVED] Custom Tab control & Custom Tab Page

    I've been using a few custom controls that are freely available on the internet for custom tab controls and they're working great in certain conditions.
    The control I'm using uses DrawMode=OwnerDrawFixed so it can design custom navigation buttons and that's working ok, even when i use SetParent() api. The problem is in the TabPages, they get overlayed and present a heavy flicker.
    I did notice that when using DrawMode=Normal, the problem goes away, but then, the Custom Tab Control custom buttons disappear.

    This is my custom TabPage I'm trying to use but so far the flicker didn't disappear

    Code:
    Imports System.Collections.Generic
    Imports System.ComponentModel
    Imports System.Drawing
    Imports System.Data
    Imports System.Text
    Imports System.Windows.Forms
    Imports System.Drawing.Design
    Imports System.Drawing.Drawing2D
    
    <System.ComponentModel.ToolboxItem(True)>
    Partial Public Class TabControl
        Inherits System.Windows.Forms.TabControl
    
        <Editor(GetType(TabPageCollectionEditor), GetType(UITypeEditor))> _
        Public Shadows ReadOnly Property TabPages() As TabPageCollection
            Get
                Return MyBase.TabPages
            End Get
        End Property
    
        Sub New()
            Me.DrawMode = System.Windows.Forms.TabDrawMode.Normal
        End Sub
    
        Protected Shadows Sub OnDrawItem(ByVal sender As Object, ByVal e As DrawItemEventArgs)
            Dim page As TabPage = Me.TabPages(e.Index)
            Me.DrawMode = System.Windows.Forms.TabDrawMode.Normal
            e.Graphics.FillRectangle(New SolidBrush(page.BackColor), e.Bounds)
        End Sub
    End Class
    
    Public Class CustomTabPages
        Inherits System.Windows.Forms.TabPage
    
        Sub New()
            MyBase.New()
            MyBase.DoubleBuffered = True
        End Sub
    End Class
    
    Public Class TabPageCollectionEditor
        Inherits System.ComponentModel.Design.CollectionEditor
    
        Public Sub New(ByVal type As Type)
            MyBase.New(type)
        End Sub
    
        Protected Overrides Function CreateCollectionItemType() As System.Type
            Return GetType(TabPage)
        End Function
    
        Protected Overrides Function CreateNewItemTypes() As System.Type()
            Return New Type() {GetType(TabPage), GetType(CustomTabPages)}
        End Function
    End Class
    Any idea?
    ::Winamp 5.xx id3v2 & modern skin support::
    ::NetCF DataGrid Programatically Scroll Example::
    Don't forget to rate posts from those who helped you solving your problem, clicking on and rating it.

  2. #2

    Thread Starter
    Fanatic Member TDQWERTY's Avatar
    Join Date
    Oct 2003
    Location
    Oporto & Leiria, Portugal / Luanda, Angola
    Posts
    972

    Re: Custom Tab control & Custom Tab Page

    bump
    ::Winamp 5.xx id3v2 & modern skin support::
    ::NetCF DataGrid Programatically Scroll Example::
    Don't forget to rate posts from those who helped you solving your problem, clicking on and rating it.

  3. #3
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Custom Tab control & Custom Tab Page

    vb.net Code:
    1. Imports System.Collections.Generic
    2. Imports System.ComponentModel
    3. Imports System.Drawing
    4. Imports System.Data
    5. Imports System.Text
    6. Imports System.Windows.Forms
    7. Imports System.Drawing.Design
    8. Imports System.Drawing.Drawing2D
    9.  
    10. <System.ComponentModel.ToolboxItem(True)>
    11. Partial Public Class TabControl ' partial? But you're inheriting ..... ? Completely redundant anyway!
    12.     Inherits System.Windows.Forms.TabControl
    13.  
    14.     <Editor(GetType(TabPageCollectionEditor), GetType(UITypeEditor))> _
    15.     Public Shadows ReadOnly Property TabPages() As TabPageCollection ' this doesn't add anything that' not already part of the inherited control
    16.         Get
    17.             Return MyBase.TabPages
    18.         End Get
    19.     End Property
    20.  
    21.     Sub New()
    22.         Me.DrawMode = System.Windows.Forms.TabDrawMode.Normal
    23.     End Sub
    24.  
    25.     Protected Shadows Sub OnDrawItem(ByVal sender As Object, ByVal e As DrawItemEventArgs) ' shadows?
    26.         Dim page As TabPage = Me.TabPages(e.Index) ' why the extra variable? You already have the value so use it!
    27.         Me.DrawMode = System.Windows.Forms.TabDrawMode.Normal ' you did this in New(), why do it again?
    28.         e.Graphics.FillRectangle(New SolidBrush(page.BackColor), e.Bounds)
    29.     End Sub
    30. End Class
    31.  
    32. Public Class CustomTabPages ' seems completely redundant, you're not customising the pages at all!
    33.     Inherits System.Windows.Forms.TabPage
    34.  
    35.     Sub New()
    36.         MyBase.New()
    37.         MyBase.DoubleBuffered = True
    38.     End Sub
    39. End Class
    40.  
    41. Public Class TabPageCollectionEditor ' again redundant as your customised pages aren't actually customised
    42.     Inherits System.ComponentModel.Design.CollectionEditor
    43.  
    44.     Public Sub New(ByVal type As Type)
    45.         MyBase.New(type)
    46.     End Sub
    47.  
    48.     Protected Overrides Function CreateCollectionItemType() As System.Type
    49.         Return GetType(TabPage)
    50.     End Function
    51.  
    52.     Protected Overrides Function CreateNewItemTypes() As System.Type()
    53.         Return New Type() {GetType(TabPage), GetType(CustomTabPages)}
    54.     End Function
    55. End Class

    That's more than a few extra steps to achieve what the native control already does and because you use shadows and partial classes there is also the potential for duplicated processes and unexpected spin-offs. Where that's going to show will inevitably be in the painting.

    But the main worry is that you actually don't need any of these classes. You simply set the native control to OwnerDraw and do all your customising in the Paint event handler.
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  4. #4
    Addicted Member
    Join Date
    May 2004
    Posts
    141

    Re: Custom Tab control & Custom Tab Page

    I'm probably completely off the mark here - i probably misunderstood the question - but a while ago I was doing some work with custom tab controls that I made myself which contained datagridview controls. In some computers I was getting a lot of flicker as the datagridview was populated. Even just resizing the form caused a lot of flicker kind of exposing for a moment (between the grid cells) some data from the tab pages underneath and other strange effects.

    The solution in my case was to set the DoubleBuffered property of the datagridview. That property is not normally exposed but you can get at it using system.reflection. And that fixed the problem.

    So, maybe see if the controls you're using expose the doublebuffered property or see if there's some way to get at it using system.reflection.
    Last edited by Axcontrols; May 9th, 2013 at 09:15 AM.

  5. #5

    Thread Starter
    Fanatic Member TDQWERTY's Avatar
    Join Date
    Oct 2003
    Location
    Oporto & Leiria, Portugal / Luanda, Angola
    Posts
    972

    Re: Custom Tab control & Custom Tab Page

    dunfiddlin, that's not the whole program, that's only a simple example that has the same basic code I'm using.
    Also that has a lot of redundancy and errors because I've did try everything, and didn't do anything at all.

    Didn't realise the shadowing, it should be overwrite.
    ::Winamp 5.xx id3v2 & modern skin support::
    ::NetCF DataGrid Programatically Scroll Example::
    Don't forget to rate posts from those who helped you solving your problem, clicking on and rating it.

  6. #6
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Custom Tab control & Custom Tab Page

    that's not the whole program, that's only a simple example
    So how are we supposed to help if we don't even get to see the actual thing that's causing the problem?
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  7. #7

    Thread Starter
    Fanatic Member TDQWERTY's Avatar
    Join Date
    Oct 2003
    Location
    Oporto & Leiria, Portugal / Luanda, Angola
    Posts
    972

    Re: Custom Tab control & Custom Tab Page

    I am not able to post the whole thing, it's more then 6 gb all the software that is interacting but I'm quite sure the problem is related with the drawmode of the tabpage cause if I switch to DrawMode=Normal, the issue goes away, but then so the designmode of the tab buttons that I'm using. That is why I need the custom tabpage, so It can be rendered using DrawMode=Normal and the tab control that owns this custom page, uses DrawMode=OwnerDrawFixed
    ::Winamp 5.xx id3v2 & modern skin support::
    ::NetCF DataGrid Programatically Scroll Example::
    Don't forget to rate posts from those who helped you solving your problem, clicking on and rating it.

  8. #8
    Hyperactive Member
    Join Date
    Apr 2011
    Location
    England
    Posts
    421

    Re: Custom Tab control & Custom Tab Page

    Hi, there is a website with TabControl tips by Mike Doherty that are specifically related to customising the tab control. Just hover over the VB buttons for the source code.

    Heres the link: http://dotnetrix.co.uk/tabcontrol.htm

    HTH

    Edit: on a quick sidenote, whenever I have used a number of controls on one form or tabpages have flickered for one reason or another I have always found it reduces substantially by using the following:

    Code:
    Protected Overrides ReadOnly Property CreateParams() As CreateParams 
        Get
            Dim cp As CreateParams = MyBase.CreateParams
            cp.ExStyle = cp.ExStyle Or &H2000000
            Return cp
        End Get
    End Property
    There are some cases when controls won't redraw automatically (it's been a while so I can't think up an example) but if anything doesn't redraw properly you just need to perform a .Refresh or .Invalidate on the control.
    Last edited by JayJayson; May 10th, 2013 at 10:27 AM.

  9. #9
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,414

    Re: Custom Tab control & Custom Tab Page

    the only effective way to reduce flickering in vb.net apps is to use DoubleBufferring as suggested by Axcontrols in post #4

  10. #10

    Thread Starter
    Fanatic Member TDQWERTY's Avatar
    Join Date
    Oct 2003
    Location
    Oporto & Leiria, Portugal / Luanda, Angola
    Posts
    972

    Re: Custom Tab control & Custom Tab Page

    Thank you all but the double buffering didn't solve the problem either.
    I did some investigation using ildasm and spy++ and the main problem is related with the setparent() function and the MDI i'm sending my application to. That MDI has some weird styles and it's because of that all my problems.
    ::Winamp 5.xx id3v2 & modern skin support::
    ::NetCF DataGrid Programatically Scroll Example::
    Don't forget to rate posts from those who helped you solving your problem, clicking on and rating it.

  11. #11
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Custom Tab control & Custom Tab Page

    it's more then 6 gb all the software that is interacting
    Well there's your problem! You could run a country with that much software but not on a standard PC system! I'm frankly surprised the only evidence of the problem is this!
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  12. #12

    Thread Starter
    Fanatic Member TDQWERTY's Avatar
    Join Date
    Oct 2003
    Location
    Oporto & Leiria, Portugal / Luanda, Angola
    Posts
    972

    Re: Custom Tab control & Custom Tab Page

    Well, thing is, it's not even close to a standard pc. And that particular software is runing not in one but is more than 30.000 standard pcs on 7 different countries. It's an ERP. And it is not mine. All I'm trying to do is a plugin such as hundreds I've done for the same ERP.
    The issue is not related with the amount of gb that this software costs in space of hdd, the issue is actually related with the using of setparent(), graphic card overlay drawing system in Windows, some controls that can't handle correctly double buffering, bad paint methods, styles, etc.
    A quick search on google tells me that I'm not the only one with this problem in years. So far, no effort has been done in winforms to solve that problem, bug, whatever. I did try using wpf to build exactly the same thing and I didn't have the same problems.
    Coincidence? Don't think so.

    anyway, I've try everything and nothing did actually work so I did some tricks, abandoned the tabpages and replaced them by a TableLayoutPanel and all my problems went away.
    ::Winamp 5.xx id3v2 & modern skin support::
    ::NetCF DataGrid Programatically Scroll Example::
    Don't forget to rate posts from those who helped you solving your problem, clicking on and rating it.

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