예제 #1
0
 public void RemoveOffset()
 {
     ToDate   = ToDate.AddMinutes(TimeOffset);
     FromDate = FromDate.AddMinutes(TimeOffset);
 }
예제 #2
0
        public void GanttChart_MouseMove(object sender, MouseEventArgs e)
        {
            if (shownHeaderList == null)
            {
                return;
            }
            if (shownHeaderList.Count == 0)
            {
                return;
            }

            if (e.Button != System.Windows.Forms.MouseButtons.Left)
            {
                //mouseHoverPart = MouseOverPart.Empty;

                // If bar has changed manually, but left mouse button is no longer pressed the BarChanged event will be raised

                if (AllowManualEditBar == true)
                {
                    if (barIsChanging >= 0)
                    {
                        if (AllowChange)
                        {
                            if (BarChanged != null)
                            {
                                BarChanged(bars[barIsChanging].Value, new EventArgs());
                            }

                            BarInformation barInfo   = bars[barIsChanging].Value as BarInformation;
                            DateTime       tempValue = _mouseOverColumnValue;
                            if (mouseHoverPart == MouseOverPart.BarLeftSide)
                            {
                                barInfo.FromTime = tempValue;
                            }
                            else if (mouseHoverPart == MouseOverPart.BarRightSide)
                            {
                                barInfo.ToTime = tempValue;
                            }
                        }
                        barIsChanging = -1;
                    }
                }

                mouseHoverPart = MouseOverPart.Empty;
            }

            mouseHoverBarIndex = -1;

            Point LocalMousePosition = default(Point);

            LocalMousePosition = PointToClient(Cursor.Position);

            // Finds pixels per minute

            TimeSpan timeBetween    = shownHeaderList[1].Time - shownHeaderList[0].Time;
            int      minutesBetween = (timeBetween.Days * 1440) + (timeBetween.Hours * 60) + timeBetween.Minutes;
            dynamic  widthBetween   = (shownHeaderList[1].StartLocation - shownHeaderList[0].StartLocation);
            float    perMinute      = (float)widthBetween / (float)minutesBetween;

            if (perMinute == 0)
            {
                perMinute = 1;
            }

            // Finds the time at mousepointer

            int minutesAtCursor = 0;

            if (LocalMousePosition.X > barStartLeft)
            {
                minutesAtCursor       = (int)((LocalMousePosition.X - barStartLeft) / perMinute);
                _mouseOverColumnValue = FromDate.AddMinutes(minutesAtCursor);
            }
            else
            {
                _mouseOverColumnValue = DateTime.MinValue;
            }

            // Finds the row at mousepointer

            string rowText  = "";
            object rowValue = null;

            // Tests to see if the mouse pointer is hovering above the scrollbar

            bool scrollBarStatusChanged = false;

            // Tests to see if the mouse is hovering over the scroll-area bottom-arrow

            if (LocalMousePosition.X > BottomPart.Left & LocalMousePosition.Y < BottomPart.Right & LocalMousePosition.Y <BottomPart.Bottom& LocalMousePosition.Y> BottomPart.Top)
            {
                if (mouseOverBottomPart == false)
                {
                    scrollBarStatusChanged = true;
                }

                mouseOverBottomPart = true;
            }
            else
            {
                if (mouseOverBottomPart == false)
                {
                    scrollBarStatusChanged = true;
                }

                mouseOverBottomPart = false;
            }

            // Tests to see if the mouse is hovering over the scroll-area top-arrow

            if (LocalMousePosition.X > topPart.Left & LocalMousePosition.Y < topPart.Right & LocalMousePosition.Y <topPart.Bottom& LocalMousePosition.Y> topPart.Top)
            {
                if (mouseOverTopPart == false)
                {
                    scrollBarStatusChanged = true;
                }

                mouseOverTopPart = true;
            }
            else
            {
                if (mouseOverTopPart == false)
                {
                    scrollBarStatusChanged = true;
                }

                mouseOverTopPart = false;
            }

            // Tests to see if the mouse is hovering over the scroll

            if (LocalMousePosition.X > scroll.Left & LocalMousePosition.Y < scroll.Right & LocalMousePosition.Y <scroll.Bottom& LocalMousePosition.Y> scroll.Top)
            {
                if (mouseOverScrollBar == false)
                {
                    scrollBarStatusChanged = true;
                }

                mouseOverScrollBar     = true;
                mouseOverScrollBarArea = true;
            }
            else
            {
                if (mouseOverScrollBar == false)
                {
                    scrollBarStatusChanged = true;
                }

                mouseOverScrollBar     = false;
                mouseOverScrollBarArea = false;
            }

            // If the mouse is not above the scroll, test if it's over the scroll area (no need to test if it's not above the scroll)

            if (mouseOverScrollBarArea == false)
            {
                if (LocalMousePosition.X > scrollBarArea.Left & LocalMousePosition.Y < scrollBarArea.Right & LocalMousePosition.Y <scrollBarArea.Bottom& LocalMousePosition.Y> scrollBarArea.Top)
                {
                    mouseOverScrollBarArea = true;
                }
            }


            // Tests to see if the mouse pointer is hovering above a bar

            int index = 0;


            foreach (ChartBarDate bar in bars)
            {
                // If the bar is set to be hidden from mouse move, the current bar will be ignored

                if (bar.HideFromMouseMove == false)
                {
                    if (bar.EndValue == null)
                    {
                        bar.EndValue = DateTime.Now;
                    }

                    // Mouse pointer needs to be inside the X and Y positions of the bar

                    if (LocalMousePosition.Y > bar.TopLocation.Left.Y & LocalMousePosition.Y < bar.BottomLocation.Left.Y)
                    {
                        if (LocalMousePosition.X > bar.TopLocation.Left.X & LocalMousePosition.X < bar.TopLocation.Right.X)
                        {
                            // If the current bar is the one where the mouse is above, the rowText and rowValue needs to be set correctly

                            rowText            = bar.Text;
                            rowValue           = bar.Value;
                            mouseHoverBarIndex = index;

                            if (mouseHoverPart != MouseOverPart.BarLeftSide & mouseHoverPart != MouseOverPart.BarRightSide)
                            {
                                mouseHoverPart = MouseOverPart.Bar;
                            }
                        }

                        // If mouse pointer is near the edges of the bar it will open up for editing the bar

                        if (AllowManualEditBar == true)
                        {
                            int areaSize = 5;

                            if (e.Button == System.Windows.Forms.MouseButtons.Left)
                            {
                                areaSize = 50;
                            }

                            if (LocalMousePosition.X > bar.TopLocation.Left.X - areaSize & LocalMousePosition.X < bar.TopLocation.Left.X + areaSize & mouseHoverPart != MouseOverPart.BarRightSide)
                            {
                                Cursor             = Cursors.VSplit;
                                mouseHoverPart     = MouseOverPart.BarLeftSide;
                                mouseHoverBarIndex = index;
                            }
                            else if (LocalMousePosition.X > bar.TopLocation.Right.X - areaSize & LocalMousePosition.X < bar.TopLocation.Right.X + areaSize & mouseHoverPart != MouseOverPart.BarLeftSide)
                            {
                                Cursor             = Cursors.VSplit;
                                mouseHoverPart     = MouseOverPart.BarRightSide;
                                mouseHoverBarIndex = index;
                            }
                            else
                            {
                                Cursor = Cursors.Default;
                            }
                        }
                    }
                }

                index += 1;
            }

            // Sets the mouseover row value and text

            _mouseOverRowText  = rowText;
            _mouseOverRowValue = rowValue;

            if (e.Button == System.Windows.Forms.MouseButtons.Left)
            {
                if (MouseDragged != null)
                {
                    MouseDragged(sender, e);
                }
            }
            else
            {
                // A simple test to see if the mousemovement has caused any changes to how it should be displayed
                // It only redraws if mouse moves from a bar to blank area or from blank area to a bar
                // This increases performance compared to having a redraw every time a mouse moves

                if ((_mouseOverRowValue == null & (rowValue != null)) | ((_mouseOverRowValue != null) & rowValue == null) | scrollBarStatusChanged == true)
                {
                    PaintChart();
                }
            }
        }
예제 #3
0
 public void SetOffset(int offset)
 {
     TimeOffset = offset;
     ToDate     = ToDate.AddMinutes(-1 * TimeOffset);
     FromDate   = FromDate.AddMinutes(-1 * TimeOffset);
 }