Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hello guys

anyone know how can i set the background color to a control like labels to have some effect like fading on the one side ?

 

and another question

 

how can i set the background picture to strech and not repeat ?

  • *Experts*
Posted
There's no built in way to have the gradient on the back of the label, but you can easily paint the control yourself. Here's an example:
Private Sub Label1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Label1.Paint
       Dim g As Graphics = e.Graphics
       Dim gradBrush As New Drawing2D.LinearGradientBrush( _
           New Point(0, Label1.Height / 2), _
           New Point(Label1.Width, Label1.Height / 2), _
           Color.PowderBlue, _
           Color.Green)

       g.FillRectangle(gradBrush, Label1.ClientRectangle)
       g.DrawString(Label1.Text, Label1.Font, _
           New Pen(Label1.ForeColor).Brush, 1, 1)
       gradBrush.Dispose()
End Sub

As for stretching the font's image, you'll need to do something similar to the label. You just get the Form's paint event and use the DrawImage method of the form's graphics object to draw the image over the entire window (DrawImage will scale it for you).

  • *Experts*
Posted
On second thought, that DrawString line should be this:
g.DrawString(Label1.Text, Label1.Font, _
           New Pen(Label1.ForeColor).Brush, New RectangleF(1, 1, Label1.Width, Label1.Height))

otherwise you won't get text wrapping.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...