vb除了画正规的直线、圆形、长方形有没其他一些图案的代码,比如五角星,红旗等,最好用鼠标画,鼠标一拖拉就出来效果,谢谢各位先了。

解决方案 »

  1.   

        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            DrawStar(Me.CreateGraphics, New System.Drawing.Point(100, 100), 100, False)
            DrawStar(Me.CreateGraphics, New System.Drawing.Point(300, 100), 100, True)
        End Sub
        Sub DrawStar(ByVal g As Graphics, ByVal center As Point, ByVal radius As Integer, ByVal isSolid As Boolean)
            Dim pts(9) As Point
            pts(0) = New Point(center.X, center.Y - radius)
            pts(1) = RotateTheta(pts(0), center, 36.0)
            Dim len As Double = radius * Math.Sin((18.0 * Math.PI / 180.0)) / Math.Sin((126.0 * Math.PI / 180.0))
            pts(1).X = CInt(center.X + len * (pts(1).X - center.X) / radius)
            pts(1).Y = CInt(center.Y + len * (pts(1).Y - center.Y) / radius)
            Dim i As Integer
            For i = 1 To 4
                pts((2 * i)) = RotateTheta(pts((2 * (i - 1))), center, 72.0)
                pts((2 * i + 1)) = RotateTheta(pts((2 * i - 1)), center, 72.0)
            Next i
            If isSolid = False Then
                Dim mPen As New Pen(New SolidBrush(Color.Blue))
                g.DrawPolygon(mPen, pts) '画一个空心五角星 
            Else
                Dim mBrush As New SolidBrush(Color.Blue)
                g.FillPolygon(mBrush, pts) '画一个实心的五角星 
            End If
        End Sub    Function RotateTheta(ByVal pt As Point, ByVal center As Point, ByVal theta As Double) As Point
            Dim x As Integer = CInt(center.X + (pt.X - center.X) * Math.Cos((theta * Math.PI / 180)) - (pt.Y - center.Y) * Math.Sin((theta * Math.PI / 180)))
            Dim y As Integer = CInt(center.Y + (pt.X - center.X) * Math.Sin((theta * Math.PI / 180)) + (pt.Y - center.Y) * Math.Cos((theta * Math.PI / 180)))
            Return New Point(x, y)
        End Function以上是展示二个五角星的图形,至于五星红旗,则你得先这五个星的位置和大小
      

  2.   

    先谢了楼上朋友了,我希望的是根据鼠标前后点击记取坐标,然后简单画取图形。图案不求很标准,只要新奇好玩就可以,比如一只老鼠,一条鱼,一个简装版的米老鼠等或其他新奇图案。
    Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single) '记录起始点
         X1 = x
        Y1 = y
    End SubPrivate Sub Picture1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
      If Button = 1 Then     
      Select Case DongZuo  
                Case "画笔"
                    Picture1.Line (X1, Y1)-(x, y) 
                    X1 = x
                    Y1 = y
                Case "划线"
                    Line1.X2 = x
                    Line1.Y2 = y
                    Line1.X1 = X1
                    Line1.Y1 = Y1
    end subPrivate Sub Picture1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
     Case "线"  Picture1.Line (X1, Y1)-(x, y) '划线 
     Case "长方形"  Picture1.Line (X1, Y1)-(x, y), , B
    end sub类似于这样。
    ps:语言需求,vb6.