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