GUI/SplitContainerAdv.cs
author sl
Sun, 03 Feb 2013 18:01:50 +0100
changeset 391 ca4c0e7ae75d
parent 158 119693c3b7d1
permissions -rw-r--r--
Converted project to VisualStudio 2012.
Adding SoundGraphDisplay and SensorFrontView classes.
They were respectively based on SystemTray and SensorNotifyIcon.
SoundGraphDisplay is now able to load iMONDisplay.dll providing it lives on your PATH.
Adding option to sensor context menu for adding it into FrontView.
moel@158
     1
/*
moel@158
     2
 
moel@344
     3
  This Source Code Form is subject to the terms of the Mozilla Public
moel@344
     4
  License, v. 2.0. If a copy of the MPL was not distributed with this
moel@344
     5
  file, You can obtain one at http://mozilla.org/MPL/2.0/.
moel@158
     6
 
moel@344
     7
  Copyright (C) 2009-2010 Michael Möller <mmoeller@openhardwaremonitor.org>
moel@344
     8
	
moel@158
     9
*/
moel@158
    10
moel@158
    11
using System;
moel@158
    12
using System.Collections.Generic;
moel@158
    13
using System.Drawing;
moel@158
    14
using System.Windows.Forms;
moel@158
    15
moel@158
    16
namespace OpenHardwareMonitor.GUI {
moel@158
    17
  public class SplitContainerAdv : SplitContainer {
moel@158
    18
moel@158
    19
    private int delta = 0;
moel@158
    20
    private Border3DStyle border3DStyle = Border3DStyle.Raised;
moel@158
    21
    private Color color = SystemColors.Control;
moel@158
    22
moel@158
    23
    public SplitContainerAdv()
moel@158
    24
      : base() {
moel@158
    25
      SetStyle(ControlStyles.ResizeRedraw, true);
moel@158
    26
      SetStyle(ControlStyles.AllPaintingInWmPaint, true);
moel@158
    27
      SetStyle(ControlStyles.UserPaint, true);
moel@158
    28
      SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
moel@158
    29
      SetStyle(ControlStyles.ContainerControl, true);
moel@158
    30
      UpdateStyles();
moel@158
    31
    }
moel@158
    32
moel@158
    33
    protected override void OnPaint(PaintEventArgs e) {
moel@158
    34
      base.OnPaint(e);
moel@158
    35
moel@158
    36
      Graphics g = e.Graphics;
moel@158
    37
      Rectangle r = SplitterRectangle;
moel@158
    38
      using (SolidBrush brush = new SolidBrush(color))
moel@158
    39
        g.FillRectangle(brush, r);
moel@158
    40
      ControlPaint.DrawBorder3D(g, r, border3DStyle);
moel@158
    41
    }
moel@158
    42
moel@158
    43
    protected override void OnKeyDown(KeyEventArgs e) {
moel@158
    44
      if (!base.IsSplitterFixed) {
moel@158
    45
        if (e.KeyData == Keys.Right || e.KeyData == Keys.Down) {
moel@158
    46
          SplitterDistance += SplitterIncrement;
moel@158
    47
        } else if (e.KeyData == Keys.Left || e.KeyData == Keys.Up) {
moel@158
    48
          SplitterDistance -= SplitterIncrement;
moel@158
    49
        }
moel@158
    50
        Invalidate();
moel@158
    51
      }
moel@158
    52
    }
moel@158
    53
moel@158
    54
    protected override void OnMouseDown(MouseEventArgs e) {
moel@158
    55
      if (Orientation == Orientation.Vertical) {
moel@158
    56
        delta = this.SplitterDistance - e.X;
moel@158
    57
        Cursor.Current = Cursors.VSplit;
moel@158
    58
      } else {
moel@158
    59
        delta = this.SplitterDistance - e.Y;
moel@158
    60
        Cursor.Current = Cursors.HSplit;
moel@158
    61
      }
moel@158
    62
      base.IsSplitterFixed = true;
moel@158
    63
    }
moel@158
    64
moel@158
    65
    protected override void OnMouseMove(MouseEventArgs e) {
moel@158
    66
      if (base.IsSplitterFixed) {
moel@158
    67
        if (e.Button == MouseButtons.Left) {
moel@158
    68
          if (Orientation == Orientation.Vertical) {
moel@158
    69
            if (e.X > 0 && e.X < Width) {
moel@158
    70
              SplitterDistance = e.X + delta < 0 ? 0 : e.X + delta;
moel@158
    71
            }
moel@158
    72
          } else {
moel@158
    73
            if (e.Y > 0 && e.Y < Height) {
moel@158
    74
              SplitterDistance = e.Y + delta < 0 ? 0 : e.Y + delta;
moel@158
    75
            }
moel@158
    76
          }
moel@158
    77
        } else {
moel@158
    78
          base.IsSplitterFixed = false;
moel@158
    79
        }
moel@158
    80
        Invalidate();
moel@158
    81
      } else {
moel@158
    82
        if (SplitterRectangle.Contains(e.Location)) {
moel@158
    83
          Cursor = Orientation == Orientation.Vertical ?
moel@158
    84
            Cursors.VSplit : Cursors.HSplit;
moel@158
    85
        }
moel@158
    86
      }
moel@158
    87
    }
moel@158
    88
moel@158
    89
    protected override void OnMouseLeave(EventArgs e) {
moel@158
    90
      base.OnMouseLeave(e);
moel@158
    91
      Cursor = Cursors.Default;
moel@158
    92
    }
moel@158
    93
moel@158
    94
    protected override void OnMouseUp(MouseEventArgs e) {
moel@158
    95
      delta = 0;
moel@158
    96
      base.IsSplitterFixed = false;
moel@158
    97
      Cursor.Current = Cursors.Default;
moel@158
    98
    }
moel@158
    99
moel@158
   100
    public Border3DStyle Border3DStyle {
moel@158
   101
      get { return border3DStyle; }
moel@158
   102
      set {
moel@158
   103
        border3DStyle = value;
moel@158
   104
        Invalidate(false);
moel@158
   105
      }
moel@158
   106
    }
moel@158
   107
moel@158
   108
    public Color Color {
moel@158
   109
      get { return color; }
moel@158
   110
      set {
moel@158
   111
        color = value;
moel@158
   112
        Invalidate(false);
moel@158
   113
      }
moel@158
   114
    }
moel@158
   115
moel@158
   116
    public new bool IsSplitterFixed {
moel@158
   117
      get {
moel@158
   118
        return false;
moel@158
   119
      }
moel@158
   120
    }
moel@158
   121
moel@158
   122
  }
moel@158
   123
}