Esempio n. 1
0
  /// <summary>Called to create calculate the header height, when the header is horizontally oriented. The default
  /// implementation measures the height of the title and subtitle text to determine the height of the header.
  /// </summary>
  protected virtual int CalculateHeaderHeight()
  {
    using(Graphics g = Graphics.FromHwnd(Handle))
    {
      int xOffset = 0, height = 0;

      if(!string.IsNullOrEmpty(Title))
      {
        int fontHeight = (int)Math.Ceiling(TitleFont.GetHeight(g)), halfHeight = fontHeight/2;
        xOffset += halfHeight;
        height  += fontHeight + halfHeight;

        if(string.IsNullOrEmpty(Subtitle)) height += halfHeight;
      }

      if(!string.IsNullOrEmpty(Subtitle))
      {
        int fontHeight = (int)Math.Ceiling(SubtitleFont.GetHeight(g)), halfHeight = fontHeight/2;
        int textHeight = (int)Math.Ceiling(g.MeasureString(Subtitle, SubtitleFont,
                                           new Size(Width-xOffset-halfHeight*2, Height-height-halfHeight)).Height);
        height += textHeight + halfHeight*2;
      }

      return Math.Max(60, height);
    }
  }
Esempio n. 2
0
  /// <summary>Draws the title and subtitle text. The default implementation places the text within the header if the
  /// header is horizontal, or to the right of the header if the header is vertical.
  /// </summary>
  protected virtual void PaintTitleText(PaintEventArgs e)
  {
    using(Brush brush = new SolidBrush(TitleColor))
    {
      int xOffset = HeaderOrientation == Orientation.Horizontal ? 0 : HeaderSize, yOffset = 0;

      if(!string.IsNullOrEmpty(Title))
      {
        int height = (int)Math.Ceiling(TitleFont.GetHeight(e.Graphics)), shift = height/2;
        xOffset += shift;
        yOffset += shift;
        e.Graphics.DrawString(Title, TitleFont, brush, new Point(xOffset, yOffset));
        yOffset += height;
      }

      if(!string.IsNullOrEmpty(Subtitle))
      {
        int shift = (int)Math.Ceiling(SubtitleFont.GetHeight(e.Graphics)) / 2;
        xOffset += shift;
        yOffset += shift;
        e.Graphics.DrawString(Subtitle, SubtitleFont, brush,
                              new Rectangle(xOffset, yOffset, Width-xOffset-shift, Height-yOffset));
      }
    }
  }
 /// <summary>
 /// Draw the minor title under the major title.
 /// </summary>
 /// <param name="grfx"></param>
 /// <param name="fastestTurnRatePlot"></param>
 private void DrawMinorTitle(Graphics grfx, TurnPerformancePlot fastestTurnRatePlot)
 {
     if (plots != null && plots.Count > 0)
     {
         string elapsedTimeMinorTitle = string.Format("After {0} elapsed seconds", Math.Round(this.displayTurnDegrees / fastestTurnRatePlot.TurnRateInDegPerSecond, 1));
         Point  minorTitlePoint       = GetTitleLocationPoint(grfx);
         minorTitlePoint.Y += (int)TitleFont.GetHeight();
         minorTitlePoint.X  = (int)(this.Width / 2 - grfx.MeasureString(elapsedTimeMinorTitle, MinorTitleFont).Width / 2);
         grfx.DrawString(elapsedTimeMinorTitle, MinorTitleFont, MinorTitlePen.Brush, minorTitlePoint);
     }
 }