コード例 #1
0
 protected override void OnPaint(PaintEventArgs e)
 {
     base.OnPaint(e);
     if (this.drawItems.Length == this.tabItemList.Count)
     {
         e.Graphics.TextRenderingHint = TextRenderingHint.AntiAlias;
         System.Drawing.Color color  = System.Drawing.Color.FromArgb(0xff, 0xee, 0xc2);
         System.Drawing.Color color2 = System.Drawing.Color.FromArgb(0xff, 0xc0, 0x6f);
         if (SystemInformation.HighContrast)
         {
             color  = System.Drawing.Color.FromArgb(0xff - color.R, 0xff - color.G, 0xff - color.B);
             color2 = System.Drawing.Color.FromArgb(0xff - color2.R, 0xff - color2.G, 0xff - color2.B);
         }
         using (Brush brush = new SolidBrush(color))
         {
             using (Brush brush2 = new SolidBrush(color2))
             {
                 for (int i = 0; i < this.drawItems.Length; i++)
                 {
                     System.Workflow.ComponentModel.Design.ItemInfo tabItemInfo = this.tabItemList[i];
                     DrawTabItemStruct struct2          = this.drawItems[i];
                     Brush             control          = SystemBrushes.Control;
                     Rectangle         tabItemRectangle = struct2.TabItemRectangle;
                     if (this.selectedTab == i)
                     {
                         control = brush2;
                         e.Graphics.FillRectangle(control, tabItemRectangle);
                         e.Graphics.DrawRectangle(SystemPens.Highlight, tabItemRectangle);
                     }
                     else
                     {
                         Point pt = base.PointToClient(Control.MousePosition);
                         if (tabItemRectangle.Contains(pt))
                         {
                             control = brush;
                             e.Graphics.FillRectangle(control, tabItemRectangle);
                             e.Graphics.DrawRectangle(SystemPens.ControlDarkDark, tabItemRectangle);
                         }
                     }
                     Rectangle tabImageRectangle = this.GetTabImageRectangle(tabItemInfo);
                     if (!tabImageRectangle.IsEmpty)
                     {
                         e.Graphics.DrawImage(tabItemInfo.Image, tabImageRectangle);
                     }
                     Rectangle tabTextRectangle = this.GetTabTextRectangle(tabItemInfo);
                     if (!tabTextRectangle.IsEmpty)
                     {
                         StringFormat format = new StringFormat {
                             Alignment     = StringAlignment.Center,
                             LineAlignment = StringAlignment.Center,
                             Trimming      = StringTrimming.EllipsisCharacter
                         };
                         if (this.orientation == Orientation.Horizontal)
                         {
                             RectangleF layoutRectangle = new RectangleF((float)tabTextRectangle.X, (float)tabTextRectangle.Y, (float)tabTextRectangle.Width, (float)tabTextRectangle.Height);
                             e.Graphics.DrawString(tabItemInfo.Text, this.Font, SystemBrushes.ControlText, layoutRectangle, format);
                         }
                         else
                         {
                             using (Bitmap bitmap = new Bitmap(tabTextRectangle.Height, tabTextRectangle.Width, e.Graphics))
                             {
                                 using (Graphics graphics = Graphics.FromImage(bitmap))
                                 {
                                     graphics.TextRenderingHint = TextRenderingHint.AntiAlias;
                                     graphics.FillRectangle(control, new Rectangle(0, 0, bitmap.Width, bitmap.Height));
                                     graphics.DrawString(this.tabItemList[i].Text, this.Font, SystemBrushes.ControlText, new Rectangle(0, 0, bitmap.Width, bitmap.Height), format);
                                     bitmap.RotateFlip(RotateFlipType.Rotate90FlipNone);
                                     e.Graphics.DrawImage(bitmap, tabTextRectangle);
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
コード例 #2
0
 protected override void OnLayout(LayoutEventArgs levent)
 {
     base.OnLayout(levent);
     using (Graphics graphics = base.CreateGraphics())
     {
         this.drawItems = new DrawTabItemStruct[this.tabItemList.Count];
         int  num  = (this.orientation == Orientation.Horizontal) ? base.Width : base.Height;
         bool flag = false;
         if (num <= this.MinimumRequiredSize)
         {
             flag = true;
         }
         int num2 = 0;
         for (int i = 0; i < this.tabItemList.Count; i++)
         {
             int num4 = 0;
             System.Workflow.ComponentModel.Design.ItemInfo info = this.tabItemList[i];
             if (info.Image != null)
             {
                 num4++;
                 num4 += this.reqTabItemSize - 2;
             }
             if ((info.Text != null) && (info.Text.Length > 0))
             {
                 SizeF ef    = graphics.MeasureString(info.Text, this.Font);
                 int   width = Convert.ToInt32(Math.Ceiling((double)ef.Width));
                 this.drawItems[i].TextSize = new Size(width, Convert.ToInt32(Math.Ceiling((double)ef.Height)));
                 if (!flag)
                 {
                     num4 += this.drawItems[i].TextSize.Width + 1;
                 }
             }
             num4 += (num4 == 0) ? this.reqTabItemSize : 1;
             this.drawItems[i].TabItemRectangle = Rectangle.Empty;
             if (this.orientation == Orientation.Horizontal)
             {
                 this.drawItems[i].TabItemRectangle.X      = num2;
                 this.drawItems[i].TabItemRectangle.Y      = 0;
                 this.drawItems[i].TabItemRectangle.Width  = num4;
                 this.drawItems[i].TabItemRectangle.Height = this.reqTabItemSize;
             }
             else
             {
                 this.drawItems[i].TabItemRectangle.X      = 0;
                 this.drawItems[i].TabItemRectangle.Y      = num2;
                 this.drawItems[i].TabItemRectangle.Width  = this.reqTabItemSize;
                 this.drawItems[i].TabItemRectangle.Height = num4;
             }
             num2 += num4 + 1;
         }
         num2--;
         if (num2 > num)
         {
             int num5 = (int)Math.Ceiling((double)(((double)(num2 - num)) / ((double)Math.Max(1, this.tabItemList.Count))));
             num2 = 0;
             DrawTabItemStruct struct2 = this.drawItems[this.tabItemList.Count - 1];
             int num6 = (this.orientation == Orientation.Horizontal) ? (struct2.TabItemRectangle.Width - num5) : (struct2.TabItemRectangle.Height - num5);
             if (num6 < this.reqTabItemSize)
             {
                 num5 += (int)Math.Ceiling((double)(((double)(this.reqTabItemSize - num6)) / ((double)Math.Max(1, this.tabItemList.Count))));
             }
             for (int j = 0; j < this.tabItemList.Count; j++)
             {
                 if (this.orientation == Orientation.Horizontal)
                 {
                     this.drawItems[j].TabItemRectangle.X     -= num2;
                     this.drawItems[j].TabItemRectangle.Width -= num5;
                     if ((j == (this.tabItemList.Count - 1)) && (this.drawItems[j].TabItemRectangle.Width < this.reqTabItemSize))
                     {
                         this.drawItems[j].TabItemRectangle.Width = this.reqTabItemSize;
                     }
                 }
                 else
                 {
                     this.drawItems[j].TabItemRectangle.Y      -= num2;
                     this.drawItems[j].TabItemRectangle.Height -= num5;
                     if ((j == (this.tabItemList.Count - 1)) && (this.drawItems[j].TabItemRectangle.Height < this.reqTabItemSize))
                     {
                         this.drawItems[j].TabItemRectangle.Height = this.reqTabItemSize;
                     }
                 }
                 num2 += num5;
             }
         }
     }
 }