kvnsdr
asked on
TabPage Font Bold in seperate class?
I found this cool tabpage font-to-bold code that works very well.
Q. How code this in a seperate class rather than on the same Winform with the actual TabControl1?
Here's what I have so far:
[WinFrom]
public Form1()
{
InitializeComponent();
new TabPageFont(this.tabContro l1);
}
[TabPageFont.cs]
using System;
using System.Collections.Generic ;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
namespace Grammer
{
class TabPageFont
{
internal TabControl tabControl;
public TabPageFont()
{
// Initialize Components
this.tabControl.DrawMode = System.Windows.Forms.TabDr awMode.Own erDrawFixe d;
this.tabControl.DrawItem += new DrawItemEventHandler(this. tabControl _DrawItem) ;
}
private void tabControl_DrawItem(object sender, System.Windows.Forms.DrawI temEventAr gs e)
{
Font fntTab;
Brush bshBack;
Brush bshFore;
if (e.Index == this.tabControl.SelectedIn dex)
{
fntTab = new Font(e.Font, FontStyle.Bold);
bshBack = new System.Drawing.Drawing2D.L inearGradi entBrush(e .Bounds, SystemColors.Control, SystemColors.Control, System.Drawing.Drawing2D.L inearGradi entMode.Ba ckwardDiag onal);
bshFore = Brushes.Black;
//bshBack = new System.Drawing.Drawing2D.L inearGradi entBrush(e .Bounds, Color.LightSkyBlue , Color.LightGreen, System.Drawing.Drawing2D.L inearGradi entMode.Ba ckwardDiag onal);
//bshFore = Brushes.Blue;
}
else
{
fntTab = e.Font;
bshBack = new SolidBrush(SystemColors.Co ntrol);
bshFore = new SolidBrush(Color.Black);
//bshBack = new SolidBrush(Color.White);
//bshFore = new SolidBrush(Color.Black);
}
string tabName = this.tabControl.TabPages[e .Index].Te xt;
StringFormat sftTab = new StringFormat();
e.Graphics.FillRectangle(b shBack, e.Bounds);
Rectangle recTab = e.Bounds;
recTab = new Rectangle(recTab.X, recTab.Y + 4, recTab.Width, recTab.Height - 4);
e.Graphics.DrawString(tabN ame, fntTab, bshFore, recTab, sftTab);
}
}
}
Q. How code this in a seperate class rather than on the same Winform with the actual TabControl1?
Here's what I have so far:
[WinFrom]
public Form1()
{
InitializeComponent();
new TabPageFont(this.tabContro
}
[TabPageFont.cs]
using System;
using System.Collections.Generic
using System.Text;
using System.Drawing;
using System.Windows.Forms;
namespace Grammer
{
class TabPageFont
{
internal TabControl tabControl;
public TabPageFont()
{
// Initialize Components
this.tabControl.DrawMode = System.Windows.Forms.TabDr
this.tabControl.DrawItem += new DrawItemEventHandler(this.
}
private void tabControl_DrawItem(object
{
Font fntTab;
Brush bshBack;
Brush bshFore;
if (e.Index == this.tabControl.SelectedIn
{
fntTab = new Font(e.Font, FontStyle.Bold);
bshBack = new System.Drawing.Drawing2D.L
bshFore = Brushes.Black;
//bshBack = new System.Drawing.Drawing2D.L
//bshFore = Brushes.Blue;
}
else
{
fntTab = e.Font;
bshBack = new SolidBrush(SystemColors.Co
bshFore = new SolidBrush(Color.Black);
//bshBack = new SolidBrush(Color.White);
//bshFore = new SolidBrush(Color.Black);
}
string tabName = this.tabControl.TabPages[e
StringFormat sftTab = new StringFormat();
e.Graphics.FillRectangle(b
Rectangle recTab = e.Bounds;
recTab = new Rectangle(recTab.X, recTab.Y + 4, recTab.Width, recTab.Height - 4);
e.Graphics.DrawString(tabN
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER