VB.NET, Graphics. Subroutine DrawGradientLine creates a LinearGradientBrush that lies between the line's start and end points. It then uses the Brush to make a Pen and draws with the Pen. ' Draw a line from (x1, y1) to (x2, y2) fading from ' color1 to color2.
I have the need to create VB.NET form buttons with a Gradient effect. I have located some code to do this with the Form itself and that works perfectly, however when I try it with the Button within that form it does not work as expected. The buttons either have the gradient with no Text (the gradient disappears and the Text re-appears on Button Mouse Hover or Click) or no gradient at all. The codes is as follows:Private Sub Button1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Button1.Paint
'Create the Metallic gradient affect on Button1 ....
'
Dim g As Graphics = Button1.CreateGraphics
Dim intWidth As Integer = Button1.Width - 3
Dim intHeight As Integer = Button1.Height - 3
Dim lgBrush As New LinearGradientBrush(New Point(1, 1), New Point(intWidth, intHeight), _
Color.White, Color.FromArgb(190, 190, 190))
g.FillRectangle(lgBrush, 0, 0, intWidth, intHeight)
End Sub
The same code as I said works perfectly with the forms itself but not the buttons and the results on the buttons vary depending on the Flatstyle setting. Can anyone help with some advice on what is wrong OR provide some code that might do the job? -->
This example shows how to use the RadialGradientBrush class to paint an area with a radial gradient.
Example
The following example uses a RadialGradientBrush to paint a rectangle with a radial gradient that transitions from yellow to red to blue to lime green.
The following illustration shows the gradient from the preceding example. The gradient's stops have been highlighted.
Note
The examples in this topic use the default coordinate system for setting control points. The default coordinate system is relative to a bounding box: 0 indicates 0 percent of the bounding box, and 1 indicates 100 percent of the bounding box. You can change this coordinate system by setting the MappingMode property to the value Absolute. An absolute coordinate system is not relative to a bounding box. Values are interpreted directly in local space.
For additional RadialGradientBrush examples, see the Brushes Sample. For more information about gradients and other types of brushes, see Painting with Solid Colors and Gradients Overview.