/// ------------------------------------------------------------------------------------ /// <summary> /// If the control has an image specified, this function paints it on the button portion /// of the control. /// </summary> /// <param name="g">A Graphics type passed from the OnPaint method.</param> /// <seealso cref="OnPaint"/> /// ------------------------------------------------------------------------------------ private void PutImageOnButton(Graphics g) { Point pt = ContentAlignmentHelper.ConAlignToImgPosition(ImageAlign, Image, m_rect, m_dpBorderWidth); g.DrawImageUnscaled(Image, pt); }
//******************************************************************************************* // // Helper Functions: This sections contains private functions. // //******************************************************************************************* //******************************************************************************************* //******************************************************************************************* private void PutTextOnButton(Graphics g) { using (var sf = new StringFormat()) { // Take the text's content alignment value and convert it into the individual // alignment types for horizontal and vertical alignment. sf.Alignment = ContentAlignmentHelper.ConAlignToHorizStrAlign(TextAlign); sf.LineAlignment = ContentAlignmentHelper.ConAlignToVertStrAlign(TextAlign); sf.Trimming = m_TextTrimming; sf.FormatFlags = StringFormatFlags.LineLimit; // Create a rectangle in which to align text that accounts for the buttons borders. // Multiplying by 2 accounts the combined thickness of the top and bottom borders, // and the combined thickness of the left and right borders. Rectangle rc = new Rectangle(m_dpBorderWidth, m_dpBorderWidth, this.Width - (m_dpBorderWidth * 2), this.Height - (m_dpBorderWidth * 2)); // If the text doesn't go on the button portion of the control and the button // portion of the control is actually shorter than the control, make the text's // rectangle the area below the button's rectangle. if (!m_fTextInButton) { if (TextPosition == TextLocation.Below && m_rect.Height < this.Height) { // Make the text's rectangle 2 pixels smaller so the text doesn't get // too close to the edges. ENHANCE: Should probably add a property // called TextMargin or Padding or something like that, instead of // hard coding the value to 2. rc.Height = this.Height - m_rect.Height - 2; rc.Y = m_rect.Height + 2; } else if (TextPosition == TextLocation.Right && m_rect.Width < this.Width) { // Make the text's rectangle 2 pixels smaller so the text doesn't get // too close to the edges. ENHANCE: Should probably add a property // called TextMargin or Padding or something like that, instead of // hard coding the value to 2. rc.Width = this.Width - m_rect.Width - 2; rc.X = m_rect.Width + 2; } } // Ensure that ellipsis draws for text if task bar is to small //if (Parent.Width < rc.Width) //{ // rc.Width = Parent.Width; //} g.DrawString(Text, this.Font, new SolidBrush(this.ForeColor), rc, sf); } }