|
-
Apr 29th, 2013, 03:36 AM
#1
Thread Starter
Fanatic Member
[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?
-
May 9th, 2013, 08:32 AM
#2
Thread Starter
Fanatic Member
Re: Custom Tab control & Custom Tab Page
-
May 9th, 2013, 08:58 AM
#3
Re: Custom Tab control & Custom Tab Page
vb.net 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 ' partial? But you're inheriting ..... ? Completely redundant anyway!
Inherits System.Windows.Forms.TabControl
<Editor(GetType(TabPageCollectionEditor), GetType(UITypeEditor))> _
Public Shadows ReadOnly Property TabPages() As TabPageCollection ' this doesn't add anything that' not already part of the inherited control
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) ' shadows?
Dim page As TabPage = Me.TabPages(e.Index) ' why the extra variable? You already have the value so use it!
Me.DrawMode = System.Windows.Forms.TabDrawMode.Normal ' you did this in New(), why do it again?
e.Graphics.FillRectangle(New SolidBrush(page.BackColor), e.Bounds)
End Sub
End Class
Public Class CustomTabPages ' seems completely redundant, you're not customising the pages at all!
Inherits System.Windows.Forms.TabPage
Sub New()
MyBase.New()
MyBase.DoubleBuffered = True
End Sub
End Class
Public Class TabPageCollectionEditor ' again redundant as your customised pages aren't actually customised
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
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!
-
May 9th, 2013, 09:09 AM
#4
Addicted Member
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.
-
May 9th, 2013, 03:35 PM
#5
Thread Starter
Fanatic Member
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.
-
May 9th, 2013, 05:16 PM
#6
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!
-
May 10th, 2013, 09:16 AM
#7
Thread Starter
Fanatic Member
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
-
May 10th, 2013, 10:15 AM
#8
Hyperactive Member
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.
-
May 10th, 2013, 10:21 AM
#9
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
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
May 17th, 2013, 02:57 AM
#10
Thread Starter
Fanatic Member
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.
-
May 17th, 2013, 12:36 PM
#11
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!
-
May 18th, 2013, 03:11 PM
#12
Thread Starter
Fanatic Member
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|