2010-08-26 36 views
1

J'essaie de convertir un projet C# en un projet vb.net mais j'ai quelques difficultés.Conversion de projet C# en VB.net

Ce qui suit est l'événement d'un simple clic:

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(); 
     } 

qui invoque alors les suivantes:

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); 
} 

J'ai converti chaque section au code VB.net:

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 

Mais il n'invoque pas automatiquement:

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 
+1

* pourquoi * essayez-vous de changer C# pour VB. NET? Curieuse. –

+2

Non !!! Ne fais pas ça! –

+0

lol quoi de mal à changer C# en VB.NET? – Azza

Répondre

3

Il existe un utilitaire de conversion gratuit en ligne developerfusion

+0

+1 très bon lien. En outre, SharpDevelop pour Mono propose des conversions C#/VB.NET: http://stackoverflow.com/questions/3453890/c-vb-net-syntax-conversion-advice/3496281#3496281 – JohnB

+1

Ou charger l'assembly dans Reflector http://www.red-gate.com/products/reflector/ et sortie en plusieurs langues. –

+0

Yeah developerfusion c'est génial, c'est ce que j'ai utilisé pour convertir le projet page par page, mais ça ne marche pas tout à fait bien! – Azza

1

Au lieu de passer outre l'événement OnPaint, essayez le déclarant comme suit:

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

End Sub