当前位置:编程学习 > C#/ASP.NET >>

求教,如何将下段画圆代码从C#转化为vb.net

    这段代码实现的功能和windows画图里的一样,鼠标画圆并且画完后可以拖动,改变大小。。
有没有高人能把它转化为vb.net的,小弟在这拜谢了!
    代码如下:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DrawRect
{
    public partial class Form1 : Form
    {
        Point startPoint = new Point(0, 0);
        Point endPoint = new Point(0, 0);

        MyRect myRect = new MyRect();

        bool isPressed = false;
        eLocation curLoc = eLocation.outside;


        public Form1()
        {
            InitializeComponent();
            this.DoubleBuffered = true;
        }

        private void Draw()
        {
            Graphics graph = this.CreateGraphics();
            graph.Clear(Color.White);
            Pen pen = new Pen(Color.Black);

            //画矩形
            //graph.DrawRectangle(pen, myRect.rect);
            //画圆
            graph.DrawEllipse(pen, myRect.rect);
        }


        private void Form1_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == System.Windows.Forms.MouseButtons.Left)
            {
                isPressed = true;
                startPoint.X = e.X;
                startPoint.Y = e.Y;

                curLoc = myRect.JudgeLocation(e.X, e.Y);
            }
        }


        private void Form1_MouseMove(object sender, MouseEventArgs e)
        {
            if (!isPressed)
            {
                eLocation mouseLoc = myRect.JudgeLocation(e.X, e.Y);
                switch (mouseLoc)
                {
                    case eLocation.outside:
                        this.Cursor = System.Windows.Forms.Cursors.Default;
                        break;
                    case eLocation.inside:
                        this.Cursor = System.Windows.Forms.Cursors.SizeAll;
                        break;
                    case eLocation.leftborder:
                        this.Cursor = System.Windows.Forms.Cursors.SizeWE;
                        break;
                    case eLocation.rightborder:
                        this.Cursor = System.Windows.Forms.Cursors.SizeWE;
                        break;
                    case eLocation.topborder:
                        this.Cursor = System.Windows.Forms.Cursors.SizeNS;
                        break;
                    case eLocation.bottomborder:
                        this.Cursor = System.Windows.Forms.Cursors.SizeNS;
                        break;
                }
 
            }
            else
            {
                endPoint.X = e.X;
                endPoint.Y = e.Y;

                switch (curLoc)
                {
                    case eLocation.outside:
                        myRect.setRect(startPoint, endPoint);
                        break;
                    case eLocation.inside:
                        myRect.rect.X += (e.X - startPoint.X);
                        myRect.rect.Y += (e.Y - startPoint.Y);
                        startPoint.X = e.X;
                        startPoint.Y = e.Y;
                        break;
                    case eLocation.leftborder:
                        myRect.rect.X = e.X;
                        myRect.rect.Width -= e.X - startPoint.X;
                        startPoint.X = e.X;
                        break;
                    case eLocation.rightborder:
                        //myRect.rect.X = e.X;
                        myRect.rect.Width += e.X - startPoint.X;
                        startPoint.X = e.X;
                        break;
                    case eLocation.topborder:
                        myRect.rect.Y = e.Y;
                        myRect.rect.Height -= e.Y - startPoint.Y;
                        startPoint.Y = e.Y;
                        break;
                    case eLocation.bottomborder:
                        myRect.rect.Height += e.Y - startPoint.Y;
                        startPoint.Y = e.Y;
                        break;
                }
                Draw();
            }
        }

        private void Form1_MouseUp(object sender, MouseEventArgs e)
        {
            isPressed = false;
        }

    }
} --------------------编程问答-------------------- 基本的语法的东西,自己看msdn吧,上面 c# 和 Vb.net 实例都有代码 --------------------编程问答--------------------
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Windows.Forms

Namespace DrawRect
    Partial Public Class Form1
        Inherits Form
        Private startPoint As New Point(0, 0)
        Private endPoint As New Point(0, 0)

        Private myRect As New MyRect

        Private isPressed As Boolean = False
        Private curLoc As eLocation = eLocation.outside


        Public Sub New()
            InitializeComponent()
            Me.DoubleBuffered = True
        End Sub

        Private Sub Draw()
            Dim graph As Graphics = Me.CreateGraphics()
            graph.Clear(Color.White)
            Dim pen As New Pen(Color.Black)

            '画矩形
            'graph.DrawRectangle(pen, myRect.rect);
            '画圆
            graph.DrawEllipse(pen, myRect.rect)
        End Sub


        Private Sub Form1_MouseDown(sender As Object, e As MouseEventArgs)
            If e.Button = System.Windows.Forms.MouseButtons.Left Then
                isPressed = True
                startPoint.X = e.X
                startPoint.Y = e.Y

                curLoc = myRect.JudgeLocation(e.X, e.Y)
            End If
        End Sub


        Private Sub Form1_MouseMove(sender As Object, e As MouseEventArgs)
            If Not isPressed Then
                Dim mouseLoc As eLocation = myRect.JudgeLocation(e.X, e.Y)
                Select Case mouseLoc
                    Case eLocation.outside
                        Me.Cursor = System.Windows.Forms.Cursors.[Default]
                        Exit Select
                    Case eLocation.inside
                        Me.Cursor = System.Windows.Forms.Cursors.SizeAll
                        Exit Select
                    Case eLocation.leftborder
                        Me.Cursor = System.Windows.Forms.Cursors.SizeWE
                        Exit Select
                    Case eLocation.rightborder
                        Me.Cursor = System.Windows.Forms.Cursors.SizeWE
                        Exit Select
                    Case eLocation.topborder
                        Me.Cursor = System.Windows.Forms.Cursors.SizeNS
                        Exit Select
                    Case eLocation.bottomborder
                        Me.Cursor = System.Windows.Forms.Cursors.SizeNS
                        Exit Select

                End Select
            Else
                endPoint.X = e.X
                endPoint.Y = e.Y

                Select Case curLoc
                    Case eLocation.outside
                        myRect.setRect(startPoint, endPoint)
                        Exit Select
                    Case eLocation.inside
                        myRect.rect.X += (e.X - startPoint.X)
                        myRect.rect.Y += (e.Y - startPoint.Y)
                        startPoint.X = e.X
                        startPoint.Y = e.Y
                        Exit Select
                    Case eLocation.leftborder
                        myRect.rect.X = e.X
                        myRect.rect.Width -= e.X - startPoint.X
                        startPoint.X = e.X
                        Exit Select
                    Case eLocation.rightborder
                        'myRect.rect.X = e.X;
                        myRect.rect.Width += e.X - startPoint.X
                        startPoint.X = e.X
                        Exit Select
                    Case eLocation.topborder
                        myRect.rect.Y = e.Y
                        myRect.rect.Height -= e.Y - startPoint.Y
                        startPoint.Y = e.Y
                        Exit Select
                    Case eLocation.bottomborder
                        myRect.rect.Height += e.Y - startPoint.Y
                        startPoint.Y = e.Y
                        Exit Select
                End Select
                Draw()
            End If
        End Sub

        Private Sub Form1_MouseUp(sender As Object, e As MouseEventArgs)
            isPressed = False
        End Sub

    End Class
End Namespace
--------------------编程问答-------------------- 猛击 --------------------编程问答--------------------

Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Windows.Forms

Namespace DrawRect
Public Partial Class Form1
Inherits Form
Private startPoint As New Point(0, 0)
Private endPoint As New Point(0, 0)

Private myRect As New MyRect()

Private isPressed As Boolean = False
Private curLoc As eLocation = eLocation.outside


Public Sub New()
InitializeComponent()
Me.DoubleBuffered = True
End Sub

Private Sub Draw()
Dim graph As Graphics = Me.CreateGraphics()
graph.Clear(Color.White)
Dim pen As New Pen(Color.Black)

'画矩形
'graph.DrawRectangle(pen, myRect.rect);
'画圆
graph.DrawEllipse(pen, myRect.rect)
End Sub


Private Sub Form1_MouseDown(sender As Object, e As MouseEventArgs)
If e.Button = System.Windows.Forms.MouseButtons.Left Then
isPressed = True
startPoint.X = e.X
startPoint.Y = e.Y

curLoc = myRect.JudgeLocation(e.X, e.Y)
End If
End Sub


Private Sub Form1_MouseMove(sender As Object, e As MouseEventArgs)
If Not isPressed Then
Dim mouseLoc As eLocation = myRect.JudgeLocation(e.X, e.Y)
Select Case mouseLoc
Case eLocation.outside
Me.Cursor = System.Windows.Forms.Cursors.[Default]
Exit Select
Case eLocation.inside
Me.Cursor = System.Windows.Forms.Cursors.SizeAll
Exit Select
Case eLocation.leftborder
Me.Cursor = System.Windows.Forms.Cursors.SizeWE
Exit Select
Case eLocation.rightborder
Me.Cursor = System.Windows.Forms.Cursors.SizeWE
Exit Select
Case eLocation.topborder
Me.Cursor = System.Windows.Forms.Cursors.SizeNS
Exit Select
Case eLocation.bottomborder
Me.Cursor = System.Windows.Forms.Cursors.SizeNS
Exit Select

End Select
Else
endPoint.X = e.X
endPoint.Y = e.Y

Select Case curLoc
Case eLocation.outside
myRect.setRect(startPoint, endPoint)
Exit Select
Case eLocation.inside
myRect.rect.X += (e.X - startPoint.X)
myRect.rect.Y += (e.Y - startPoint.Y)
startPoint.X = e.X
startPoint.Y = e.Y
Exit Select
Case eLocation.leftborder
myRect.rect.X = e.X
myRect.rect.Width -= e.X - startPoint.X
startPoint.X = e.X
Exit Select
Case eLocation.rightborder
'myRect.rect.X = e.X;
myRect.rect.Width += e.X - startPoint.X
startPoint.X = e.X
Exit Select
Case eLocation.topborder
myRect.rect.Y = e.Y
myRect.rect.Height -= e.Y - startPoint.Y
startPoint.Y = e.Y
Exit Select
Case eLocation.bottomborder
myRect.rect.Height += e.Y - startPoint.Y
startPoint.Y = e.Y
Exit Select
End Select
Draw()
End If
End Sub

Private Sub Form1_MouseUp(sender As Object, e As MouseEventArgs)
isPressed = False
End Sub

End Class
End Namespace
--------------------编程问答-------------------- 三楼的工具不错。 --------------------编程问答-------------------- 疯狂猛击此万能工具 --------------------编程问答-------------------- 猛击楼上12 --------------------编程问答-------------------- 吓尿了 --------------------编程问答-------------------- 用工具转也可以;c#.net和VB.net相似的地方还是很多的,劝你自己查查语法,自己写一遍,也不是坏事;或者知己吧c#的写成dll,用VB调。。。。 --------------------编程问答-------------------- http://www.developerfusion.com/tools/convert/csharp-to-vb/ --------------------编程问答-------------------- http://www.developerfusion.com/tools/convert/csharp-to-vb/ 
同楼上,这个非常好用。建议收藏。
补充:.NET技术 ,  VB.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,