Advertisement
dreadngel

My SplitterConteiner

Oct 10th, 2012
1,179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.85 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Diagnostics;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using System.Drawing;
  9.  
  10. namespace Splitter
  11. {
  12.     public enum Direction
  13.     {
  14.         Right = 0,
  15.         Left,
  16.         Up,
  17.         Down
  18.     }
  19.  
  20.     public class ACSplitter : SplitContainer
  21.     {
  22.         public ACSplitter()
  23.         {
  24.             //InitializeComponent();
  25.         }
  26.  
  27.         #region private properties
  28.  
  29.         private System.Drawing.Color hotColor = CalculateColor(SystemColors.Highlight, SystemColors.Window, 70);
  30.  
  31.         #endregion
  32.  
  33.         // solid color obtained as a result of alpha-blending
  34.         private static Color CalculateColor(Color front, Color back, int alpha)
  35.         {
  36.             Color frontColor = Color.FromArgb(255, front);
  37.             Color backColor = Color.FromArgb(255, back);
  38.  
  39.             float frontRed = frontColor.R;
  40.             float frontGreen = frontColor.G;
  41.             float frontBlue = frontColor.B;
  42.             float backRed = backColor.R;
  43.             float backGreen = backColor.G;
  44.             float backBlue = backColor.B;
  45.  
  46.             float fRed = frontRed * alpha / 255 + backRed * ((float)(255 - alpha) / 255);
  47.             byte newRed = (byte)fRed;
  48.             float fGreen = frontGreen * alpha / 255 + backGreen * ((float)(255 - alpha) / 255);
  49.             byte newGreen = (byte)fGreen;
  50.             float fBlue = frontBlue * alpha / 255 + backBlue * ((float)(255 - alpha) / 255);
  51.             byte newBlue = (byte)fBlue;
  52.  
  53.             return Color.FromArgb(255, newRed, newGreen, newBlue);
  54.         }
  55.  
  56.         // This creates a point array to draw a arrow-like polygon
  57.         private Point[] ArrowPointArray(int x, int y, Direction direction)
  58.         {
  59.             Point[] point = new Point[3];
  60.  
  61.             // decide which direction the arrow will point
  62.             if (direction == Direction.Right)
  63.             {
  64.                 // right arrow
  65.                 point[0] = new Point(x, y);
  66.                 point[1] = new Point(x + 3, y + 3);
  67.                 point[2] = new Point(x, y + 6);
  68.             }
  69.             if (direction == Direction.Left)
  70.             {
  71.                 // left arrow
  72.                 point[0] = new Point(x + 3, y);
  73.                 point[1] = new Point(x, y + 3);
  74.                 point[2] = new Point(x + 3, y + 6);
  75.             }
  76.             if (direction == Direction.Up)
  77.             {
  78.                 // up arrow
  79.                 point[0] = new Point(x + 3, y);
  80.                 point[1] = new Point(x + 6, y + 4);
  81.                 point[2] = new Point(x, y + 4);
  82.             }
  83.             if (direction == Direction.Down)
  84.             {
  85.                 // down arrow
  86.                 point[0] = new Point(x, y);
  87.                 point[1] = new Point(x + 2, y + 3);
  88.                 point[2] = new Point(x + 5, y);
  89.             }
  90.             return point;
  91.         }
  92.  
  93.         protected override void OnPaint(PaintEventArgs pe)
  94.         {
  95.             Graphics g = pe.Graphics;
  96.  
  97.             Rectangle r = this.ClientRectangle;
  98.             g.FillRectangle(new SolidBrush(this.BackColor), r);
  99.  
  100.  
  101.             if (this.Orientation == System.Windows.Forms.Orientation.Horizontal)
  102.             {
  103.                 this.SplitterWidth = 9;
  104.                 int recWidth = SplitterRectangle.Width / 3;
  105.                 Rectangle split_rect = new Rectangle(SplitterRectangle.X + recWidth, SplitterRectangle.Y, SplitterRectangle.Width - recWidth, SplitterRectangle.Height);
  106.  
  107.                 int x = split_rect.X;
  108.                 int y = split_rect.Y + 3;
  109.  
  110.                 g.DrawLine(new Pen(SystemColors.ControlLightLight), x, y, x, y + 2);
  111.                 g.DrawLine(new Pen(SystemColors.ControlLightLight), x, y, x + recWidth, y);
  112.                 g.DrawLine(new Pen(SystemColors.ControlDark), x, y + 2, x + recWidth, y + 2);
  113.                 g.DrawLine(new Pen(SystemColors.ControlDark), x + recWidth, y, x + recWidth, y + 2);
  114.             }
  115.             else
  116.             {
  117.                 this.SplitterWidth = 9;
  118.                 int recHeight = SplitterRectangle.Height / 3;
  119.                 Rectangle split_rect = new Rectangle(SplitterRectangle.X, SplitterRectangle.Y + recHeight, SplitterRectangle.Width, SplitterRectangle.Height - 2 * recHeight);
  120.  
  121.                 int x = split_rect.X + 3;
  122.                 int y = split_rect.Y;
  123.  
  124.                 g.DrawLine(new Pen(SystemColors.ControlLightLight), x, y, x + 2, y);
  125.                 g.DrawLine(new Pen(SystemColors.ControlLightLight), x, y, x, y + recHeight);
  126.                 g.DrawLine(new Pen(SystemColors.ControlDark), x + 2, y, x + 2, y + recHeight);
  127.                 g.DrawLine(new Pen(SystemColors.ControlDark), x, y + recHeight, x + 2, y + recHeight);
  128.             }
  129.             // Calling the base class OnPaint
  130.             base.OnPaint(pe);
  131.         }
  132.     }
  133. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement