Beispiel #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);
    }
  }
Beispiel #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));
      }
    }
  }