【问题标题】:Drawing a rectangle in vb.net在 vb.net 中绘制一个矩形
【发布时间】:2016-07-29 18:45:56
【问题描述】:

我想在表单上绘制一个简单的二维矩形。

因为我从未在 vb.net 中做过任何图形操作,所以我在网上搜索并找到了许多实例,它们提供了与此类似的解决方案。

Public Sub DrawRectangleRectangle(ByVal e As PaintEventArgs)

    ' Create pen. 
    Dim blackPen As New Pen(Color.Black, 3)

    ' Create rectangle. 
    Dim rect As New Rectangle(0, 0, 200, 200)

    ' Draw rectangle to screen.
    e.Graphics.DrawRectangle(blackPen, rect)
End Sub

然而,我不明白这是怎么回事.. 这是什么e As PaintEventArgs?这个子需要什么输入?如何画一个简单的矩形?

对于初学者,我想要一些简单的东西,这样我就可以对其进行试验并最终学习更高级的东西。

【问题讨论】:

    标签: vb.net drawrectangle


    【解决方案1】:

    好的这段代码之前运行良好,你可以测试学习

        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    
       'dimension variables of local scope
    
        Dim myGraphics As Graphics
    
        Dim myRectangle As Rectangle
    
        Dim myPen As New Pen(Color.Blue)
    
       'return the current form as a drawing surface
    
        myGraphics = Graphics.FromHwnd(ActiveForm().Handle)
    
        'create a rectangle based on x,y coordinates, width, & height
    
        myRectangle = New Rectangle(x:=5, y:=5, Width:=10, Height:=40)
    
       'draw rectangle from pen and rectangle objects
    
        myGraphics.DrawRectangle(pen:=myPen, rect:=myRectangle)
    
        'create a rectangle based on Point and Size objects
    
        myRectangle = New Rectangle(Location:=New Point(10, 10), Size:=New Size(Width:=20, Height:=60))
    
        'draw another rectangle from Pen and new Rectangle object
    
        myGraphics.DrawRectangle(pen:=myPen, rect:=myRectangle)
    
        'draw a rectangle from a Pen object, a rectangle's x & y, 
    
          ' width, & height
    
       myGraphics.DrawRectangle(pen:=myPen, x:=20, y:=20, Width:=30, Height:=80)
    
     End Sub
    

    【讨论】:

    • 谢谢。这正是我所需要的。
    猜你喜欢
    • 1970-01-01
    • 2014-05-04
    • 2020-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多