This is a migrated thread and some comments may be shown as answers.

Shadows Me.Paint (Button)

1 Answer 92 Views
Buttons, RadioButton, CheckBox, etc
This is a migrated thread and some comments may be shown as answers.
Bryan Brannon
Top achievements
Rank 2
Bryan Brannon asked on 03 May 2007, 02:09 PM
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:

buttons.gif

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

Any thoughts for improvement or somewhere that might be more efficient?

1 Answer, 1 is accepted

Sort by
0
Jordan
Telerik team
answered on 03 May 2007, 03:02 PM
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,
Jordan
the telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
Buttons, RadioButton, CheckBox, etc
Asked by
Bryan Brannon
Top achievements
Rank 2
Answers by
Jordan
Telerik team
Share this question
or