9 Şubat 2016 Salı

[Theme] AviraTabControl Porting To C#

Good Working
image //i.imgur.com/aQ2IwR4.png

original post //hackforums.net/showthread.php?tid=4208332
this theme only work in vb.net

vb.net - > c#
add your class and compile once you can use this

Code:
using System;
using System.Windows.Forms;
using System.Drawing;
using System.Diagnostics;
using System.Drawing.Drawing2D;

namespace AviraTabControl
{
    class AviraTabControl : TabControl
    {

        //Background Color
        private Color BC = Color.FromArgb(73, 73, 73);
        //Selected Tab Gradient Color Top
        private Color SLGT = Color.FromArgb(255, 255, 255);
        //Selected Tab Gradient Color Bottom
        private Color SLGB = Color.FromArgb(200, 200, 200);

        //Selected Tab Line Color Top
        private Pen SLLT = new Pen(Color.FromArgb(165, 165, 165));
        //Selected Tab Line Color Bottom
        private Pen SLLB = new Pen(Color.FromArgb(98, 98, 98));
        //Header Text Color
        private SolidBrush TC = new SolidBrush(Color.FromArgb(180, 180, 180));
        //Unselected Tab Font Color
        private Brush UTC = Brushes.White;
        //Selected Tab Font Color
        private Brush STC = Brushes.Black;

        private SolidBrush BCB = new SolidBrush(Color.FromArgb(73, 73, 73));
        private Pen BCP = new Pen(Color.FromArgb(73, 73, 73));
        private Rectangle TR;
        private Rectangle InTR;
        private Rectangle InR;
        private Rectangle LR;
        private Rectangle ImR;
        private StringFormat SF = new StringFormat
        {
            Alignment = StringAlignment.Near,
            LineAlignment = StringAlignment.Center
        };
        private StringFormat SFHeader = new StringFormat
        {
            Alignment = StringAlignment.Near,
            LineAlignment = StringAlignment.Far
        };
        private int ICounter = 0;
        private LinearGradientBrush SLGBr;
        private SolidBrush TSB;

        private int TROffset = 1;
        public AviraTabControl()
        {
            SetStyle(ControlStyles.UserPaint | ControlStyles.Opaque | ControlStyles.ResizeRedraw | ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque, true);
            SetStyle(ControlStyles.Selectable, false);
            SizeMode = TabSizeMode.Fixed;
            Alignment = TabAlignment.Left;
            ItemSize = new Size(21, 180);
            DrawMode = TabDrawMode.OwnerDrawFixed;
            Font = new Font("Verdana", 8);
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            Graphics g = e.Graphics;
            if ((this.SelectedIndex == 0 || this.SelectedIndex == -1 || this.SelectedIndex > checked(this.TabPages.Count - 1) || this.TabPages[this.SelectedIndex].BackColor == Color.Transparent ? true : false))
            {
                g.Clear(Color.White);
            }
            else
            {
                g.Clear(this.TabPages[this.SelectedIndex].BackColor);
            }
            this.ICounter = 0;
            Size itemSize = this.ItemSize;
            this.LR = new Rectangle(0, 0, checked(itemSize.Height + 3), this.Height);
            g.FillRectangle(this.BCB, this.LR);
            g.DrawRectangle(this.BCP, this.LR);
            g.SmoothingMode = SmoothingMode.AntiAlias;
            int tabCount = checked(this.TabCount - 1);
            for (int i = 0; i <= tabCount; i++)
            {
                this.TR = this.GetTabRect(i);
                this.TR = new Rectangle(this.TR.X, this.TR.Y, checked(this.TR.Width - 1), this.TR.Height);
                if ((this.TabPages[i].Tag == null || this.TabPages[i].Tag == string.Empty ? false : true))
                {
                    this.InR = new Rectangle(checked(this.TR.X + 10), this.TR.Y, checked(this.TR.Width - 10), this.TR.Height);
                    g.DrawString(this.TabPages[i].Text.ToUpper(), this.Font, this.TC, this.InR, this.SFHeader);
                    this.ICounter = checked(this.ICounter + 1);
                }
                else if (i != this.SelectedIndex)
                {
                    this.InR = new Rectangle(checked(this.TR.X + 36), this.TR.Y, checked(this.TR.Width - 36), this.TR.Height);
                    g.DrawString(this.TabPages[i].Text, this.Font, this.UTC, this.InR, this.SF);
                    if ((this.UnselectedImageList == null || this.UnselectedImageList.Images.Count <= checked(i - this.ICounter) || this.UnselectedImageList.Images[checked(i - this.ICounter)] == null ? false : true))
                    {
                        this.ImR = new Rectangle(checked(this.TR.X + 13), checked((int)Math.Round((double)this.TR.Y + ((double)this.TR.Height / 2 - 8))), 16, 16);
                        g.DrawImage(this.UnselectedImageList.Images[checked(i - this.ICounter)], this.ImR);
                    }
                }
                else
                {
                    this.SLGBr = new LinearGradientBrush(this.TR, this.SLGT, this.SLGB, 90f);
                    this.InR = new Rectangle(checked(this.TR.X + 36), this.TR.Y, checked(this.TR.Width - 36), this.TR.Height);
                    this.InTR = new Rectangle(this.TR.X, checked(this.TR.Y + this.TROffset), this.TR.Width, checked(this.TR.Height - checked(2 * this.TROffset)));
                    g.FillRectangle(this.SLGBr, this.InTR);
                    g.DrawLine(this.SLLT, this.TR.X, checked(this.TR.Y + this.TROffset), checked(checked(this.TR.X + this.TR.Width) - 1), checked(this.TR.Y + this.TROffset));
                    g.DrawLine(this.SLLB, this.TR.X, checked(checked(this.TR.Y + this.TR.Height) - this.TROffset), checked(checked(this.TR.X + this.TR.Width) - 1), checked(checked(this.TR.Y + this.TR.Height) - this.TROffset));
                    g.DrawString(this.TabPages[i].Text, this.Font, this.STC, this.InR, this.SF);
                    if ((this.SelectedImageList == null || this.SelectedImageList.Images.Count <= checked(i - this.ICounter) || this.SelectedImageList.Images[checked(i - this.ICounter)] == null ? false : true))
                    {
                        this.ImR = new Rectangle(checked(this.TR.X + 13), checked((int)Math.Round((double)this.TR.Y + ((double)this.TR.Height / 2 - 8))), 16, 16);
                        g.DrawImage(this.SelectedImageList.Images[checked(i - this.ICounter)], this.ImR);
                    }
                }
            }
            g.Dispose();
        }

        private ImageList UnselectedImageList;
        public ImageList ImageList_Unselected
        {
            get { return UnselectedImageList; }
            set
            {
                UnselectedImageList = value;
                if (UnselectedImageList != null && !(UnselectedImageList.ImageSize == new Size(16, 16)))
                {
                    UnselectedImageList.ImageSize = new Size(16, 16);
                }
                Invalidate();
            }
        }

        private ImageList SelectedImageList;
        public ImageList ImageList_Selected
        {
            get { return SelectedImageList; }
            set
            {
                SelectedImageList = value;
                if (SelectedImageList != null && !(SelectedImageList.ImageSize == new Size(16, 16)))
                {
                    SelectedImageList.ImageSize = new Size(16, 16);
                }
                Invalidate();
            }
        }

     
        protected override void OnSelecting(TabControlCancelEventArgs e)
        {
            base.OnSelecting(e);
            if (e.TabPage != null && e.TabPage.Tag != null && !object.ReferenceEquals(e.TabPage.Tag, string.Empty) && !DesignMode)
            {
                e.Cancel = true;
            }
        }

    }
}