首页 > 编程 > .NET > 正文

VB.NET中使用GDI画图具体应用。

2024-07-10 13:03:40
字体:
来源:转载
供稿:网友

下面的例子通过重载form1窗体的onpaint()方法绘制gdi图形
protected overrides sub onpaint(byval e as system.windows.forms.painteventargs)
        '/////////////绘制任意直线
        dim g as graphics = e.graphics
        dim mypen as pen = new pen(color.red, 2)
        g.drawline(mypen, 100, 100, 10, 10)
        '/////////////绘制矩形(任意直线构成的封闭图形)
        dim point1 as pointf = new pointf(100f, 100f)
        dim point2 as pointf = new pointf(200f, 100f)
        dim point3 as pointf = new pointf(200f, 200f)
        dim point4 as pointf = new pointf(100f, 200f)
        dim curvepoints as pointf() = {point1, point2, point3, point4}
        g.drawpolygon(new pen(color.blue, 2), curvepoints)
        '////////////文本表示
        dim ffamily as fontfamily = new fontfamily("arial")
        dim font as font = new font(ffamily, "20", fontstyle.bold, fontstyle.italic, graphicsunit.pixel)
        dim text as string = "i love you!"
        dim solidbrush as solidbrush = new solidbrush(color.red)
        dim pr as pointf = new pointf(100, 10)
        e.graphics.drawstring(text, font, solidbrush, pr)
        '////////////平面绘制
        dim rec as rectanglef = new rectanglef(10, 10, 200, 100)
        g.drawpie(mypen, rec, 150, 150)
        '///////////封闭图形,0.7应该是个圆
        g.drawclosedcurve(mypen, curvepoints, 0.7, drawing.drawing2d.fillmode.alternate)
        '///////////大家自己试试看吧
        g.drawarc(mypen, 300, 300, 200, 200, 100, 100)
        g.drawcurve(mypen, curvepoints)
        g.drawbezier(mypen, 50, 50, 100, 50, 100, 100, 50, 100)
        g.drawbeziers(mypen, curvepoints)
        '//////////这可是一个圆
        dim rec1 as rectanglef = new rectanglef(10, 10, 100, 100)
        g.drawellipse(mypen, rec1)
        '//////////这是一个椭圆
        dim rec2 as rectanglef = new rectanglef(10, 10, 200, 100)
        g.drawellipse(mypen, rec2)

    end sub

这些是我自己试验出来的,当然了,还有好多,我只是开了一个头,大家要是发现什么好东东,别忘了通知一下:)
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表