473,385 Members | 1,925 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Problem with TabControl Resizing

I have a few hundred forms in my application. All are based on a custom base form class.

I decided that I wanted to globally change the look and feel of many of the controls in my application - including the tab control. I did this by writing a component that I attached to the form. The component has a "Start" function which takes the form as a paramater. This cycles through all the controls on the form, changes some of the properties and adds handlers to the paint control where required.

For the tabcontrol I've created handlers for the paint event on both the tabcontrol and the tabpages to use the following methods :

================================================== =============================
Private Sub TabControlDrawTab(ByVal sender As Object, ByVal e As DrawItemEventArgs)

Dim tc As TabControl = sender

Dim rect As Rectangle = tc.GetTabRect(e.Index)

Dim text As String = tc.TabPages(e.Index).Text

If tc.SelectedIndex = e.Index Then

e.Graphics.FillRectangle(New SolidBrush(Color.DarkBlue), rect)

Else

e.Graphics.FillRectangle(New SolidBrush(Color.FromArgb(180, 180, 255)), rect)

End If

' Work out the text to draw

If tc.SelectedIndex = e.Index Then

e.Graphics.DrawString(text, tc.Font, New SolidBrush(Color.White), rect.X + 1, rect.Y + 1)

Else

e.Graphics.DrawString(text, tc.Font, New SolidBrush(Color.DarkBlue), rect.X + 1, rect.Y + 1)

End If

End Sub

Private Sub TabControlPaint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs)

Dim rect As Rectangle = e.ClipRectangle

'Dim tp As TabPage = sender

'Dim tc As TabControl = DirectCast(tc.Parent, TabControl)

'rect = tc.DisplayRectangle

e.Graphics.DrawRectangle(New Pen(Color.DarkBlue, 4), rect.X, rect.Y, rect.Width, rect.Height)

'e.Graphics.FillRectangle(New SolidBrush(Color.Red), rect) 'Color.FromArgb(180, 180, 255)), rect)

End Sub

================================================== ====================


This seems to work (the selected tab is dark blue and the other tabs are lighter). However, many of my tab controls are anchored to the edges of the form (by having the anchor set to top/bottom/left/right) - when I have my component running, the tab controls no longer resize. However, group boxes (which I do the same thing to) seem to resize fine.

Am I doing something conceptually incorrect ? What do I need to do to get the tab controls to resize correctly?

Thanks in advance.
Simon

--
Simon Verona

Aug 14 '06 #1
2 3334
Sorry to add to my own post.. It's the "DrawItem" event I've picked up on the tabcontrol NOT the paint.

Regards
Simon

--
Simon Verona

"Simon Verona" <no****@nomail.zzzwrote in message news:eg*************@TK2MSFTNGP05.phx.gbl...
I have a few hundred forms in my application. All are based on a custom base form class.

I decided that I wanted to globally change the look and feel of many of the controls in my application - including the tab control. I did this by writing a component that I attached to the form. The component has a "Start" function which takes the form as a paramater. This cycles through all the controls on the form, changes some of the properties and adds handlers to the paint control where required.

For the tabcontrol I've created handlers for the paint event on both the tabcontrol and the tabpages to use the following methods :

================================================== =============================
Private Sub TabControlDrawTab(ByVal sender As Object, ByVal e As DrawItemEventArgs)

Dim tc As TabControl = sender

Dim rect As Rectangle = tc.GetTabRect(e.Index)

Dim text As String = tc.TabPages(e.Index).Text

If tc.SelectedIndex = e.Index Then

e.Graphics.FillRectangle(New SolidBrush(Color.DarkBlue), rect)

Else

e.Graphics.FillRectangle(New SolidBrush(Color.FromArgb(180, 180, 255)), rect)

End If

' Work out the text to draw

If tc.SelectedIndex = e.Index Then

e.Graphics.DrawString(text, tc.Font, New SolidBrush(Color.White), rect.X + 1, rect.Y + 1)

Else

e.Graphics.DrawString(text, tc.Font, New SolidBrush(Color.DarkBlue), rect.X + 1, rect.Y + 1)

End If

End Sub

Private Sub TabControlPaint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs)

Dim rect As Rectangle = e.ClipRectangle

'Dim tp As TabPage = sender

'Dim tc As TabControl = DirectCast(tc.Parent, TabControl)

'rect = tc.DisplayRectangle

e.Graphics.DrawRectangle(New Pen(Color.DarkBlue, 4), rect.X, rect.Y, rect.Width, rect.Height)

'e.Graphics.FillRectangle(New SolidBrush(Color.Red), rect) 'Color.FromArgb(180, 180, 255)), rect)

End Sub

================================================== ====================
This seems to work (the selected tab is dark blue and the other tabs are lighter). However, many of my tab controls are anchored to the edges of the form (by having the anchor set to top/bottom/left/right) - when I have my component running, the tab controls no longer resize. However, group boxes (which I do the same thing to) seem to resize fine.

Am I doing something conceptually incorrect ? What do I need to do to get the tab controls to resize correctly?

Thanks in advance.
Simon

--
Simon Verona

Aug 14 '06 #2
More information - this only seems to occur if the form is itself an MDI child of a main form..

Regards
Simon

--
Simon Verona

"Simon Verona" <no****@nomail.zzzwrote in message news:eq**************@TK2MSFTNGP02.phx.gbl...
Sorry to add to my own post.. It's the "DrawItem" event I've picked up on the tabcontrol NOT the paint.

Regards
Simon

--
Simon Verona

"Simon Verona" <no****@nomail.zzzwrote in message news:eg*************@TK2MSFTNGP05.phx.gbl...
I have a few hundred forms in my application. All are based on a custom base form class.

I decided that I wanted to globally change the look and feel of many of the controls in my application - including the tab control. I did this by writing a component that I attached to the form. The component has a "Start" function which takes the form as a paramater. This cycles through all the controls on the form, changes some of the properties and adds handlers to the paint control where required.

For the tabcontrol I've created handlers for the paint event on both the tabcontrol and the tabpages to use the following methods :

================================================== =============================
Private Sub TabControlDrawTab(ByVal sender As Object, ByVal e As DrawItemEventArgs)

Dim tc As TabControl = sender

Dim rect As Rectangle = tc.GetTabRect(e.Index)

Dim text As String = tc.TabPages(e.Index).Text

If tc.SelectedIndex = e.Index Then

e.Graphics.FillRectangle(New SolidBrush(Color.DarkBlue), rect)

Else

e.Graphics.FillRectangle(New SolidBrush(Color.FromArgb(180, 180, 255)), rect)

End If

' Work out the text to draw

If tc.SelectedIndex = e.Index Then

e.Graphics.DrawString(text, tc.Font, New SolidBrush(Color.White), rect.X + 1, rect.Y + 1)

Else

e.Graphics.DrawString(text, tc.Font, New SolidBrush(Color.DarkBlue), rect.X + 1, rect.Y + 1)

End If

End Sub

Private Sub TabControlPaint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs)

Dim rect As Rectangle = e.ClipRectangle

'Dim tp As TabPage = sender

'Dim tc As TabControl = DirectCast(tc.Parent, TabControl)

'rect = tc.DisplayRectangle

e.Graphics.DrawRectangle(New Pen(Color.DarkBlue, 4), rect.X, rect.Y, rect.Width, rect.Height)

'e.Graphics.FillRectangle(New SolidBrush(Color.Red), rect) 'Color.FromArgb(180, 180, 255)), rect)

End Sub

================================================== ====================
This seems to work (the selected tab is dark blue and the other tabs are lighter). However, many of my tab controls are anchored to the edges of the form (by having the anchor set to top/bottom/left/right) - when I have my component running, the tab controls no longer resize. However, group boxes (which I do the same thing to) seem to resize fine.

Am I doing something conceptually incorrect ? What do I need to do to get the tab controls to resize correctly?

Thanks in advance.
Simon

--
Simon Verona

Aug 14 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Tamir Khason | last post by:
How be able to manage more deeply UI of TabControl and TabPage For example - I want to manage border color, change color of TabPage reef, eliminate spaces from both sides of the reef, so I bould...
4
by: Sumit | last post by:
Hi all, I am working on an application in which there is a form which has a tabcontrol containing 4 tab pages. Let the name of the tabpages be A,B,C&D. The default view is that there are all...
7
by: Graham Blandford | last post by:
OK, having answered my questions in a previous feed about pulling my derived class into the IDE.... Here's a new problem that I'm hoping can be fixed and isn't a .NET bug.... I have created an...
0
by: Gianluca | last post by:
Hi All, i'm experencing a frustrating and strange behaviaour : I created a Windows project in VB.NET 2003 with a form and then I added a TabControl on the form, and added 5 TabPages on...
21
by: cmd | last post by:
I have code in the OnExit event of a control on a subform. The code works properly in this instance. If, however, I put the same code in the OnExit event of a control on a Tab Control of a main...
2
by: Richard Carpenter | last post by:
I have a four-page tabcontrol with a gridview on each page. I have the primary key column of each gridview set to hidden (visible = false), but it still shows up on all but the first page. Anyone...
2
by: naamala | last post by:
Hi, I need to change individual tab's background color in TabControl in windows form. I am able to change the Backgrond color of each tab in TabControl with changing the property...
1
by: =?Utf-8?B?QWxleCBLLg==?= | last post by:
Hi all In a Visual Studio 2005 C# project, I have a simplest tabcontrol with two tabpages. When I set tab control's Alignment property to Right, tab texts (captions) disappear. Does anybody...
3
by: tezu | last post by:
hi , Im new to c# , currently i'm developing an UI . i have used windows form in this , i have created my own maximise , minimise and close buttons for the form . the form also contains a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.