C# 到 VB.net 项目转换

发布于 2024-09-16 18:36:30 字数 2590 浏览 3 评论 0原文

我正在尝试将 C# 项目转换为 vb.net 项目,但遇到一些困难。

以下是按钮的单击事件:

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

然后调用以下内容:

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

我已将每个部分转换为 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

但它不会自动调用:

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

天煞孤星 2024-09-23 18:36:30

有一个免费的在线转换实用程序 developerfusion

There are a free on-line conversion utility developerfusion

中性美 2024-09-23 18:36:30

不要重写 OnPaint 事件,而是尝试按如下方式声明它:

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

End Sub

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文