views:

61

answers:

3

I am trying to convert a C# project to a vb.net project but am having some difficulties.

The following is the click event of a button:

private void button2_Click(object
sender, EventArgs e)
        {
            Appointment m_App = new Appointment();
            m_App.StartDate = dayView1.SelectionStart;
            m_App.EndDate = dayView1.SelectionEnd;
            m_App.BorderColor = Color.Red;

            m_Appointments.Add(m_App);

            dayView1.Invalidate();
        }

Which then invokes the following:

protected override void
    OnPaint(PaintEventArgs e)
{
            e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

            // resolve appointments on visible date range.
            ResolveAppointmentsEventArgs args = new
        ResolveAppointmentsEventArgs(this.StartDate,
        this.StartDate.AddDays(daysToShow));
            ResolveAppointments(args);

            using (SolidBrush backBrush = new
          SolidBrush(renderer.BackColor))
                  e.Graphics.FillRectangle(backBrush,
          this.ClientRectangle);

            // Visible Rectangle            Rectangle
        rectangle = new Rectangle(0, 0,
              this.Width - VScrollBarWith,
              this.Height);

            DrawDays(ref e, rectangle);

            DrawHourLabels(ref e, rectangle);

            DrawDayHeaders(ref e, rectangle);
}

I have converted each section to VB.net code:

 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)  Handles Button1.Click
         Dim m_App As New Appointment()
         m_App.StartDate = DayView1.SelectionStart
         m_App.EndDate = DayView1.SelectionEnd
         m_App.BorderColor = Color.Red

         m_Appointments.Add(m_App)

         DayView1.Invalidate()

 End Sub

But it does not automatically invoke:

Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
            e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias

            ' resolve appointments on visible date range.'
            Dim args As New ResolveAppointmentsEventArgs(Me.StartDate, >Me.StartDate.AddDays(m_daysToShow))
            ResolveAppointments(args)

            Using backBrush As New SolidBrush(m_renderer.BackColor)
                e.Graphics.FillRectangle(backBrush, Me.ClientRectangle)
            End Using

            ' Visible Rectangle '
            Dim rectangle As New Rectangle(0, 0, Me.Width - VScrollBarWith, Me.Height)

            DrawDays(e, rectangle)

            DrawHourLabels(e, rectangle)

            DrawDayHeaders(e, rectangle)
 End Sub
+2  A: 

There are a free on-line conversion utility developerfusion

volody
+1 great link. Also, SharpDevelop for Mono offers C#/VB.NET conversions: http://stackoverflow.com/questions/3453890/c-vb-net-syntax-conversion-advice/3496281#3496281
JohnB
Or load the assembly into Reflector http://www.red-gate.com/products/reflector/ and output in several languages.
Mikael Svenson
Yeah developerfusion is great, thats what i used to convert the project page by page, but it just isn't quite working right!
Azza
Had a go with the other two tools also. They yield pretty much the same results. Does anyone know why the Invalidate() command is not invoking the Paint Handler as per the above code?
Azza
A: 

http://converter.telerik.com/

Amit Ranjan
+1  A: 

Instead of overriding the OnPaint event, try declaring it as follows:

Private Sub form_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint

End Sub
geoff