Menu

#19 ImageAlign and TextAlign properties for CloudStartMenuButton

open
None
5
2008-11-01
2008-10-31
No

Read the caption.

Discussion

  • SubsonicDesign

    SubsonicDesign - 2008-11-01
    • assigned_to: nobody --> dudedesign
    • summary: ImageAlign and TextAlign properties for Cloud StartMenuButto --> ImageAlign and TextAlign properties for CloudStartMenuButton
     
  • mn_progr

    mn_progr - 2009-05-01

    We added the ImageAlign and TextAlign properties and functionality for the CloudStartMenuButton. Below is the code that we added/modified.

    //Declarations Added
    public enum Alignment_Enum
    {
    Left,
    Center,
    Right
    }
    Alignment_Enum mTextAlign = Alignment_Enum.Center;
    Alignment_Enum mImageAlign = Alignment_Enum.Left;

    //Methods updated:
    private void drawIcon(Graphics e)
    {
    // This is either normal icon or disabled icon, depending on the enabled property
    Bitmap iconToDraw;
    float lWidthLeft = 0;
    if (this.Enabled == true)
    {
    iconToDraw = icon;
    }
    else
    {
    iconToDraw = disabledIcon;
    }

    // If there's an icon it will be drawn
    if (iconToDraw != null)
    {
    if (this.mImageAlign == Alignment_Enum.Left)
    {
    lWidthLeft = 5;
    }
    else if (this.mImageAlign == Alignment_Enum.Center)
    {
    lWidthLeft = this.Width / 2 - iconToDraw.Width / 2;
    }
    else if (this.mImageAlign == Alignment_Enum.Right)
    {
    lWidthLeft = this.Width - 5 - iconToDraw.Width;
    }
    //// If there's only an icon, it's placed in the middle of the button
    //if (text.Length == 0)
    //{
    // e.DrawImage(iconToDraw, this.Width / 2 - iconToDraw.Width / 2, this.Height / 2 - iconToDraw.Height / 2, iconToDraw.Width, iconToDraw.Height);
    //}
    //else
    //{
    // e.DrawImage(iconToDraw, 5, this.Height / 2 - iconToDraw.Height / 2, iconToDraw.Width, iconToDraw.Height);
    //}
    e.DrawImage(iconToDraw, lWidthLeft, this.Height / 2 - iconToDraw.Height / 2, iconToDraw.Width, iconToDraw.Height);
    }
    }
    private void drawText(Graphics e)
    {
    float lWidthLeft = 0;
    float lImageWidth =0;
    if (icon != null)
    {
    lImageWidth = this.icon.Width;
    }
    if (this.mTextAlign == Alignment_Enum.Left)
    {
    lWidthLeft = textDistanceFromBorder + lImageWidth;
    }
    else if (this.mTextAlign == Alignment_Enum.Center)
    {
    lWidthLeft = this.Width / 2 - e.MeasureString(text, this.Font).Width / 2;
    }
    else if (this.mTextAlign == Alignment_Enum.Right)
    {
    lWidthLeft = this.Width - textDistanceFromBorder - e.MeasureString(text, this.Font).Width;
    }
    e.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
    //if (centeredText == true)
    //{
    // e.DrawString(text, this.Font, textBrush, new PointF(this.Width / 2 - e.MeasureString(text, this.Font).Width / 2, this.Height / 2 - this.Font.Height / 2));
    //}
    //else
    //{
    //if (icon == null)
    //{
    // e.DrawString(text, this.Font, textBrush, new PointF(lWidthLeft , this.Height / 2 - this.Font.Height / 2));
    //}
    //else
    //{
    e.DrawString(text, this.Font, textBrush, new PointF(lWidthLeft, this.Height / 2 - this.Font.Height / 2));
    //}
    //}
    }

    //Properties Add:
    [Description("Alignment of the Text")]
    [Browsable(true)]
    public Alignment_Enum TextAlign
    {
    get
    {
    return this.mTextAlign;
    }
    set
    {
    this.mTextAlign = value;
    this.Invalidate();
    }
    }
    [Description("Alignment of the Image")]
    [Browsable(true)]
    public Alignment_Enum ImageAlign
    {
    get
    {
    return this.mImageAlign;
    }
    set
    {
    this.mImageAlign = value;
    this.Invalidate();
    }
    }

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.