473,699 Members | 2,790 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 TabControlDrawT ab(ByVal sender As Object, ByVal e As DrawItemEventAr gs)

Dim tc As TabControl = sender

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

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

If tc.SelectedInde x = e.Index Then

e.Graphics.Fill Rectangle(New SolidBrush(Colo r.DarkBlue), rect)

Else

e.Graphics.Fill Rectangle(New SolidBrush(Colo r.FromArgb(180, 180, 255)), rect)

End If

' Work out the text to draw

If tc.SelectedInde x = e.Index Then

e.Graphics.Draw String(text, tc.Font, New SolidBrush(Colo r.White), rect.X + 1, rect.Y + 1)

Else

e.Graphics.Draw String(text, tc.Font, New SolidBrush(Colo r.DarkBlue), rect.X + 1, rect.Y + 1)

End If

End Sub

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

Dim rect As Rectangle = e.ClipRectangle

'Dim tp As TabPage = sender

'Dim tc As TabControl = DirectCast(tc.P arent, TabControl)

'rect = tc.DisplayRecta ngle

e.Graphics.Draw Rectangle(New Pen(Color.DarkB lue, 4), rect.X, rect.Y, rect.Width, rect.Height)

'e.Graphics.Fil lRectangle(New SolidBrush(Colo r.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 3349
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******** *****@TK2MSFTNG P05.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 TabControlDrawT ab(ByVal sender As Object, ByVal e As DrawItemEventAr gs)

Dim tc As TabControl = sender

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

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

If tc.SelectedInde x = e.Index Then

e.Graphics.Fill Rectangle(New SolidBrush(Colo r.DarkBlue), rect)

Else

e.Graphics.Fill Rectangle(New SolidBrush(Colo r.FromArgb(180, 180, 255)), rect)

End If

' Work out the text to draw

If tc.SelectedInde x = e.Index Then

e.Graphics.Draw String(text, tc.Font, New SolidBrush(Colo r.White), rect.X + 1, rect.Y + 1)

Else

e.Graphics.Draw String(text, tc.Font, New SolidBrush(Colo r.DarkBlue), rect.X + 1, rect.Y + 1)

End If

End Sub

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

Dim rect As Rectangle = e.ClipRectangle

'Dim tp As TabPage = sender

'Dim tc As TabControl = DirectCast(tc.P arent, TabControl)

'rect = tc.DisplayRecta ngle

e.Graphics.Draw Rectangle(New Pen(Color.DarkB lue, 4), rect.X, rect.Y, rect.Width, rect.Height)

'e.Graphics.Fil lRectangle(New SolidBrush(Colo r.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******** ******@TK2MSFTN GP02.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******** *****@TK2MSFTNG P05.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 TabControlDrawT ab(ByVal sender As Object, ByVal e As DrawItemEventAr gs)

Dim tc As TabControl = sender

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

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

If tc.SelectedInde x = e.Index Then

e.Graphics.Fill Rectangle(New SolidBrush(Colo r.DarkBlue), rect)

Else

e.Graphics.Fill Rectangle(New SolidBrush(Colo r.FromArgb(180, 180, 255)), rect)

End If

' Work out the text to draw

If tc.SelectedInde x = e.Index Then

e.Graphics.Draw String(text, tc.Font, New SolidBrush(Colo r.White), rect.X + 1, rect.Y + 1)

Else

e.Graphics.Draw String(text, tc.Font, New SolidBrush(Colo r.DarkBlue), rect.X + 1, rect.Y + 1)

End If

End Sub

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

Dim rect As Rectangle = e.ClipRectangle

'Dim tp As TabPage = sender

'Dim tc As TabControl = DirectCast(tc.P arent, TabControl)

'rect = tc.DisplayRecta ngle

e.Graphics.Draw Rectangle(New Pen(Color.DarkB lue, 4), rect.X, rect.Y, rect.Width, rect.Height)

'e.Graphics.Fil lRectangle(New SolidBrush(Colo r.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
18507
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 custom control that inherit all information from TabPage, but how to access those properties, not supported by standart interface??? Thank you
4
1874
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 the tabpages(A-D) in the tabControl. Now there is a button on TabPage A & when the button is clicked the default view changes to a tabcontrol having three tabpages A,B & D.
7
1468
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 inherited class based on the textbox... which, all I am doing is allowing a forecolor to be set when .enabled is set to true. it works nicely, EXCEPT that when I click into the box, the font (set as default MS Sans 8.25pt) does not appear to be...
0
1162
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 TabControl. then I added some controls (button, picturebox,labels, ... ) on each TabPage. close the form and open it again. Now when I click TabControl to go to any tab page and right click on any control (button, label, picture,..) , I can only see...
21
5097
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 form, the code errors out at the 2nd line. The error number is 13 and the description is "Type mismatch". Both controls are memo fields. I suspect that "Screen.ActiveControl.Parent" is not referencing the form as intended. Thanks for any help,...
2
2630
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 else see this behavior? How might I correct it?
2
1764
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 "DrawMode=OwnerDrawFixed". The problem When I use "DrawMode=Normal", tabcontrol rendering the background color of the form where there are no tabs, But When Change "DrawMode=OwnerDrawFixed", it's not rendering Form's BackGround Color where there are no tabs,...
1
3456
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 know how to fix this? I tried this on two computers, at work and at home, both with Windows XP with latest service packs, and Framework 2.0 and 3.0 with latest SP.
3
11661
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 Tabcontrol . when i click on the maximise button of the form i'm setting the properties of the form to FormWindowState.Maximized; now i want my tabcontrol also to be resized to the width of my form , how can i achieve this??? please help ASAP :) ...
0
8704
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9053
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8936
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8894
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7776
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6540
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4390
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3071
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2015
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.