Esempio n. 1
0
        private void drawBackround_DrawCustomContent(object sender, DrawBackroundImageEventArgs e)
        {
            Graphics canvas = e.Canvas;

            int pixels = this.horizontal ? this.Width : this.Height;

            linesPerPixel = (this.TotalLines > pixels) ? ((float)this.TotalLines / pixels) : ((float)pixels / this.TotalLines);

            Pen pen = new Pen(Brushes.Red);

            foreach (var marker in this.markers)
            {
                pen.Color = marker.Value;
                int position = (int)(this.TotalLines > pixels ? marker.Key / linesPerPixel : marker.Key * linesPerPixel);
                if (position > pixels)
                {
                    position = pixels;
                }

                if (this.horizontal)
                {
                    canvas.DrawLine(pen, position, 0, position, this.Height);
                }
                else
                {
                    canvas.DrawLine(pen, 0, position, this.Width, position);
                }
            }

            if (this.Horizontal)
            {
                canvas.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SystemDefault;
                canvas.DrawString(this.Text, new Font("Arial", 7), new SolidBrush(Color.FromArgb(100, 0, 0, 0)), new PointF(0, 0));
            }
        }
Esempio n. 2
0
        private void drawBackround_DrawCustomContent(object sender, DrawBackroundImageEventArgs e)
        {
            Graphics canvas = e.Canvas;

            canvas.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
            //Draw timeline
            Pen        pen        = new Pen(Brushes.Black);
            Font       font       = new Font("Microsoft Sans Serif", 8);
            SolidBrush brush      = new SolidBrush(Color.Black);
            float      textHeight = canvas.MeasureString("yX", font).Height;

            const int minimumPixelsBetweenMinutes = 6;
            int       numberOfMinutesToDraw       = (int)((this.PixelsPerHour / minimumPixelsBetweenMinutes));

            numberOfMinutesToDraw = this.minutePeaks.Keys.Where(m => m <= numberOfMinutesToDraw).FirstOrDefault();
            int   highlightMinute      = 0;
            float pixelsBetweenMinutes = 0;

            if (numberOfMinutesToDraw > 0)
            {
                highlightMinute      = this.minutePeaks[numberOfMinutesToDraw];
                pixelsBetweenMinutes = (float)PixelsPerHour / numberOfMinutesToDraw;
            }

            for (int hour = 0; hour <= this.hoursCount; hour++)
            {
                DateTime whereWeAre = this.DateStart.AddHours(hour);

                float positionX     = this.PixelsPerHour * hour;
                float positionY     = 0;
                float textPositionX = positionX;


                if (whereWeAre.Hour == 0 || hour == 0)
                {
                    //Draw day text
                    string dateTxt = whereWeAre.ToShortDateString();
                    canvas.DrawString(dateTxt, font, brush, new PointF(positionX, positionY));

                    /*
                     * //Draw day line
                     * pen.Width = 2;
                     * pen.Color = Color.Blue;
                     * canvas.DrawLine(pen, positionX, positionY, positionX, positionY + 10);
                     */
                }

                positionY = textHeight;

                //Draw hour text
                string hourTxt = whereWeAre.ToString("HH");
                //SizeF textSize = canvas.MeasureString(hourTxt, font);
                //textPositionX = (int)(positionX - (textSize.Width / 2));
                canvas.DrawString(hourTxt, font, brush, new PointF(positionX - 1, positionY));

                //Draw hour line
                positionY = positionY + textHeight + 2;
                pen.Color = Color.Black;
                canvas.DrawLine(pen, positionX, positionY, positionX, positionY + 5);

                //Draw minute lines
                int highilightCounter = 0;
                pen.Color = Color.DarkGray;
                for (int i = 0; i < numberOfMinutesToDraw - 1; i++)
                {
                    highilightCounter++;
                    if (highilightCounter == highlightMinute)
                    {
                        highilightCounter = 0;
                        pen.Width         = 2;
                    }
                    else
                    {
                        pen.Width = 1;
                    }
                    positionX += pixelsBetweenMinutes;

                    canvas.DrawLine(pen, positionX, positionY, positionX, positionY + 5);
                }
            }
        }