M
Mike Kitchen
I am writing an application in visual basic from a C# that I have already
written.
I am trying to convert the following line of code into VB, but I do not
completely understand the help pages. (I am not using visual studio).
linearBrush.LinearColors = new Color[] {Color.FromArgb(120, 120, 255),
Color.FromArgb(0, 0, 0)};
If anybody can rewrite this line in VB I would appreciate it.
Thanks
publicjoe.
Full code example with 2 lines commented in the paint method that will not
compile.
//---Code--- analog.vb
Imports System
Imports System.Drawing
Imports System.Windows.Forms
Imports System.Drawing.Drawing2D
Public Class AnalogClock : Inherits Form
Private components As System.ComponentModel.IContainer
Public Sub New()
MyBase.New()
InitializeComponent()
' Enable Double Buffering to remove flicker
Me.SetStyle(ControlStyles.AllPaintingInWmPaint, true)
Me.SetStyle(ControlStyles.UserPaint, true)
Me.SetStyle(ControlStyles.DoubleBuffer, true)
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
Private Sub InitializeComponent()
'
'Form1
'
Me.FormBorderStyle = FormBorderStyle.FixedSingle
Me.MaximizeBox = false
Me.Name = "AnalogClock"
Me.Text = "Analog Clock"
Me.ClientSize = New Size( 240, 240 )
Me.Font = New Font("Arial", 12F, FontStyle.Regular, GraphicsUnit.Point,
0)
End Sub
'Run the application
<STAThread()> Public Shared Sub Main()
Application.Run(New AnalogClock( ))
End Sub
Private Sub PathDemo_Paint( ByVal sender As Object, _
ByVal e As PaintEventArgs) _
Handles MyBase.Paint
' Get Graphics Object
Dim g As Graphics = e.Graphics
' Create Rectangle To Limit brush area.
Dim rect As New Rectangle(20, 20, 230, 230)
' Create Brush
Dim linearBrush As New LinearGradientBrush( _
rect, _
Color.FromArgb(0, 0, 0), _
Color.FromArgb(120, 120, 255), _
225 )
' Draw Outer Rim to screen.
g.FillEllipse( linearBrush, 20, 20, 200, 200 )
' linearBrush.LinearColors = New Color[] {Color.FromArgb(120, 120, 255),
Color.FromArgb(0, 0, 0)}
' Draw Inner Rim to screen.
' g.FillEllipse( linearBrush, 30, 30, 180, 180 )
' Now tidy up
linearBrush.Dispose()
End Sub
End Class
//-- End of Code---
I use a batch file to compile code
//---Batch File--- make.bat
vbc /t:winexe /r:system.dll,system.drawing.dll,system.windows.forms.dll
analog.vb
pause
// End of Batch File---
written.
I am trying to convert the following line of code into VB, but I do not
completely understand the help pages. (I am not using visual studio).
linearBrush.LinearColors = new Color[] {Color.FromArgb(120, 120, 255),
Color.FromArgb(0, 0, 0)};
If anybody can rewrite this line in VB I would appreciate it.
Thanks
publicjoe.
Full code example with 2 lines commented in the paint method that will not
compile.
//---Code--- analog.vb
Imports System
Imports System.Drawing
Imports System.Windows.Forms
Imports System.Drawing.Drawing2D
Public Class AnalogClock : Inherits Form
Private components As System.ComponentModel.IContainer
Public Sub New()
MyBase.New()
InitializeComponent()
' Enable Double Buffering to remove flicker
Me.SetStyle(ControlStyles.AllPaintingInWmPaint, true)
Me.SetStyle(ControlStyles.UserPaint, true)
Me.SetStyle(ControlStyles.DoubleBuffer, true)
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
Private Sub InitializeComponent()
'
'Form1
'
Me.FormBorderStyle = FormBorderStyle.FixedSingle
Me.MaximizeBox = false
Me.Name = "AnalogClock"
Me.Text = "Analog Clock"
Me.ClientSize = New Size( 240, 240 )
Me.Font = New Font("Arial", 12F, FontStyle.Regular, GraphicsUnit.Point,
0)
End Sub
'Run the application
<STAThread()> Public Shared Sub Main()
Application.Run(New AnalogClock( ))
End Sub
Private Sub PathDemo_Paint( ByVal sender As Object, _
ByVal e As PaintEventArgs) _
Handles MyBase.Paint
' Get Graphics Object
Dim g As Graphics = e.Graphics
' Create Rectangle To Limit brush area.
Dim rect As New Rectangle(20, 20, 230, 230)
' Create Brush
Dim linearBrush As New LinearGradientBrush( _
rect, _
Color.FromArgb(0, 0, 0), _
Color.FromArgb(120, 120, 255), _
225 )
' Draw Outer Rim to screen.
g.FillEllipse( linearBrush, 20, 20, 200, 200 )
' linearBrush.LinearColors = New Color[] {Color.FromArgb(120, 120, 255),
Color.FromArgb(0, 0, 0)}
' Draw Inner Rim to screen.
' g.FillEllipse( linearBrush, 30, 30, 180, 180 )
' Now tidy up
linearBrush.Dispose()
End Sub
End Class
//-- End of Code---
I use a batch file to compile code
//---Batch File--- make.bat
vbc /t:winexe /r:system.dll,system.drawing.dll,system.windows.forms.dll
analog.vb
pause
// End of Batch File---