Shadows Me.Paint (Button)

2 posts, 0 answers
  1. Bryan Brannon
    Bryan Brannon avatar
    65 posts
    Member since:
    Aug 2012

    Posted 03 May 2007 Link to this post

    I am extending one of your button controls to have more properties and am including the following code to "Shadow" the Paint event to further draw a string below the main string.  This works but would like to know if there is a better way of doing this, because when i change the text or hide and show the button, the text messes up during paint until it gets focus causing it to re-paint.  Here is what the buttons looks like painted:


    and here is my code in my extended class:
    1     Private Shadows Sub ExtendedPaint(ByVal sender As ObjectByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint  
    2         If Not String.IsNullOrEmpty(Me._alt_text) Then  '_alt_text (string property)  
    3             Dim f1 As Font = New Font("Arial", 8.0F, FontStyle.Bold)  
    4             Dim sf As New StringFormat()  
    5             Dim brush As System.Drawing.Brush = New SolidBrush(Me._alt_text_color)  
    7             Dim rect As Rectangle = New Rectangle(e.ClipRectangle.X, e.ClipRectangle.Y, e.ClipRectangle.Width, e.ClipRectangle.Height - 7)  
    10             sf.Alignment = StringAlignment.Center  
    11             sf.LineAlignment = StringAlignment.Far  
    13             e.Graphics.DrawString(Me._alt_text, f1, brush, rect, sf)  
    15             brush.Dispose()  
    16             sf.Dispose()  
    17             f1.Dispose()  
    18         End If 
    19     End Sub 

    Any thoughts for improvement or somewhere that might be more efficient?
  2. Jordan
    Jordan avatar
    547 posts

    Posted 03 May 2007 Link to this post

    Hello Bryan,

    You could consider invalidating the button (by calling the Invalidate method) when the alternate text is set to a different value.

    Kind regards,
    the telerik team

    Instantly find answers to your questions at the new Telerik Support Center
Back to Top