|登录 |注册

查看: 1999|回复: 2
打印 上一主题 下一主题

VB.NET 要如何用键盘控制画出来图案?

[复制链接]
Iceleafleave
2009-10-5 04:38 PM
Imports System.Drawing.Drawing2D
Imports System.Drawing.Graphics


Public Class Form1
   Dim circle As New Rectangle(12, 208, 28, 23)
   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
      Me.KeyPreview = True
   End Sub


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

      Dim graphicsObjectC As Graphics = e.Graphics

      Dim carbody As SolidBrush = New SolidBrush(Color.BlueViolet)
      Dim carbodypen As Pen = New Pen(carbody)

      Dim carcover As SolidBrush = New SolidBrush(Color.White)
      Dim carcoverpen As Pen = New Pen(carcover)

      Dim carwin As SolidBrush = New SolidBrush(Color.White)
      Dim carwinpen As Pen = New Pen(carwin)

      Dim cartyback As New Rectangle(23, 65, 20, 20)
      Dim cartybrush As New SolidBrush(Color.Black)
      Dim cartypen As New Pen(Color.Black, 8)

      Dim cartyfront As New Rectangle(100, 65, 20, 20)
      Dim cartyfrontbrush As New SolidBrush(Color.Black)
      Dim cartyfrontpen As New Pen(Color.Black, 8)

      carbodypen.Color = Color.DarkCyan
      carbodypen.Width = 60
      carbodypen.DashCap = LineCap.Round
      carbodypen.DashStyle = DashStyle.Solid
      graphicsObjectC.DrawLine(carbodypen, 10, 45, 145, 45)

      carcoverpen.Color = Color.White
      carcoverpen.Width = 33
      carcoverpen.DashCap = LineCap.Round
      carcoverpen.DashStyle = DashStyle.Solid
      graphicsObjectC.DrawLine(carcoverpen, 90, 29, 150, 29)

      carwinpen.Color = Color.White
      carwinpen.Width = 13
      carwinpen.DashCap = LineCap.Round
      carwinpen.DashStyle = DashStyle.Solid
      graphicsObjectC.DrawLine(carwinpen, 22, 30, 75, 30)

      e.Graphics.FillEllipse(cartybrush, cartyback)
      e.Graphics.DrawEllipse(cartypen, cartyback)

      e.Graphics.FillEllipse(cartyfrontbrush, cartyfront)
      e.Graphics.DrawEllipse(cartyfrontpen, cartyfront)

   End Sub



   Public Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
      'spike=========================================================================================================
      Dim graphicsObject As Graphics = e.Graphics
      'Line Drawed --------------------------------------------------------------------------------------------------
      Dim straight As SolidBrush = New SolidBrush(Color.Black)
      Dim straightPen As Pen = New Pen(straight)

      Dim left As SolidBrush = New SolidBrush(Color.Black)
      Dim leftPen As Pen = New Pen(left)

      Dim right As SolidBrush = New SolidBrush(Color.Black)
      Dim rightPen As Pen = New Pen(right)
      '--------------------------------------------------------------------------------------------------------------

      'Circle drawed

      Dim circlebrush As New SolidBrush(Color.Blue)
      Dim circlepen As New Pen(Color.Blue, 8)
      '--------------------------------------------------------------------------------------------------------------

      'eyes drawed
      Dim eyel As New Rectangle(16, 212, 6, 6)
      Dim eyelbrush As New SolidBrush(Color.Black)
      Dim eyelpen As New Pen(Color.Black, 3)

      Dim eyer As New Rectangle(28, 212, 6, 6)
      Dim eyerbrush As New SolidBrush(Color.Black)
      Dim eyerpen As New Pen(Color.Black, 3)

      'Rectangle drawed
      Dim rect As New RectangleF(18, 226, 16, 3)
      Dim rectbrush As New SolidBrush(Color.Red)


      straightPen.Color = Color.Black
      straightPen.Width = 4
      straightPen.DashCap = LineCap.Round
      straightPen.DashStyle = DashStyle.Solid
      graphicsObject.DrawLine(straightPen, 2, 220, 53, 220)


      leftPen.Color = Color.Black
      leftPen.Width = 4
      leftPen.DashCap = LineCap.Round
      leftPen.DashStyle = DashStyle.Solid
      graphicsObject.DrawLine(leftPen, 10, 238, 40, 202)

      rightPen.Color = Color.Black
      rightPen.Width = 4
      rightPen.DashCap = LineCap.Round
      rightPen.DashStyle = DashStyle.Solid
      graphicsObject.DrawLine(rightPen, 13, 202, 40, 238)

      e.Graphics.FillEllipse(circlebrush, circle)
      e.Graphics.DrawEllipse(circlepen, circle)

      e.Graphics.FillEllipse(eyelbrush, eyel)
      e.Graphics.DrawEllipse(eyelpen, eyel)

      e.Graphics.FillEllipse(eyerbrush, eyer)
      e.Graphics.DrawEllipse(eyerpen, eyer)

      e.Graphics.FillRectangle(rectbrush, rect)
      'spike=========================================================================================================

   End Sub





   Public Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
      Dim Loc As Point
      Select Case e.KeyCode
         Case Keys.Left
            If Not circle.Location.X - 5 < 0 Then
               Loc = New Point(circle.Location.X - 5, circle.Location.Y)
               circle.Location = Loc
            End If
         Case Keys.Right
            If Not circle.Location.X + 5 > Me.Width - circle.Width - 5 Then
               Loc = New Point(circle.Location.X + 5, circle.Location.Y)
               circle.Location = Loc
            End If
         Case Keys.Up
            If Not circle.Location.Y - 5 < 0 Then
               Loc = New Point(circle.Location.X, circle.Location.Y - 5)
               circle.Location = Loc
            End If
         Case Keys.Down
            If Not circle.Location.Y - 5 > Me.Height - circle.Height * 1.5 Then
               Loc = New Point(circle.Location.X, circle.Location.Y + 5)
               circle.Location = Loc
            End If
      End Select


   End Sub


End Class
Iceleafleave
2009-10-5 04:40 PM
这些是我得coding不过不能移图案~谁能帮帮我?

回复 #2 Iceleafleave 的帖子

lord14383
2009-10-7 04:18 PM
我能帮你^^
如果还有什么不懂的话,可以问我^^如果我会的话
您需要登录后才可以回帖 登录 | 注册

JBTALKS.CC |联系我们 |隐私政策 |Share

GMT+8, 2026-1-1 05:36 AM , Processed in 0.103483 second(s), 26 queries .

Powered by Discuz! X2.5 © 2001-2012 Comsenz Inc.

本论坛言论纯属发表者个人意见,与本论坛立场无关
Copyright © 2003-2012 JBTALKS.CC All Rights Reserved

Dedicated Server powered by iCore Technology Sdn. Bhd.

合作联盟网站:
JBTALKS 马来西亚中文论坛 | JBTALKS我的空间 | ICORE TECHNOLOGY SDN. BHD.
回顶部