GDI Code Conversion

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---
 
B

Bob Powell [MVP]

http://www.developerfusion.com/utilities/convertcsharptovb.aspx

The downloadable client utility is excellent.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.





Mike Kitchen said:
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---
 
C

Cor Ligthert

Mike,

Dont ask me what it does
linearBrush.LinearColors = new Color[] {Color.FromArgb(120, 120, 255),
Color.FromArgb(0, 0, 0)};
linearBrush.LinearColors = _
New Color() {Color.FromArgb(120, 120, 225), _
Color.FromArgb(0, 0, 0)}

It is almost complet the same excetp for the [] and the ;

Cor
 
M

Mike Kitchen

Thanks Cor.

That worked a treat, "I could not see the wood from the trees" as they say.
It shows this in the msdn help, I was just not paying enough attention.

Cor Ligthert said:
Mike,

Dont ask me what it does
linearBrush.LinearColors = new Color[] {Color.FromArgb(120, 120, 255),
Color.FromArgb(0, 0, 0)};
linearBrush.LinearColors = _
New Color() {Color.FromArgb(120, 120, 225), _
Color.FromArgb(0, 0, 0)}

It is almost complet the same excetp for the [] and the ;

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top