Visual Basic 2005程序设计 教学课件 ppt 作者 丁爱萍 第11章 多媒体程序设计

上传人:E**** 文档编号:89400169 上传时间:2019-05-24 格式:PPT 页数:36 大小:966KB
返回 下载 相关 举报
Visual Basic 2005程序设计 教学课件 ppt 作者  丁爱萍 第11章  多媒体程序设计_第1页
第1页 / 共36页
Visual Basic 2005程序设计 教学课件 ppt 作者  丁爱萍 第11章  多媒体程序设计_第2页
第2页 / 共36页
Visual Basic 2005程序设计 教学课件 ppt 作者  丁爱萍 第11章  多媒体程序设计_第3页
第3页 / 共36页
Visual Basic 2005程序设计 教学课件 ppt 作者  丁爱萍 第11章  多媒体程序设计_第4页
第4页 / 共36页
Visual Basic 2005程序设计 教学课件 ppt 作者  丁爱萍 第11章  多媒体程序设计_第5页
第5页 / 共36页
点击查看更多>>
资源描述

《Visual Basic 2005程序设计 教学课件 ppt 作者 丁爱萍 第11章 多媒体程序设计》由会员分享,可在线阅读,更多相关《Visual Basic 2005程序设计 教学课件 ppt 作者 丁爱萍 第11章 多媒体程序设计(36页珍藏版)》请在金锄头文库上搜索。

1、第11章 多媒体程序设计,11.1 图形和图像,11.1.1 绘图基础 绘制图形需要创建Graphics对象和Pen对象。 1. 创建Graphics对象 创建Graphics对象,最常用的方法是在窗体的Paint事件中编写代码。Paint事件是在绘制窗体时发生。例如: Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint Dim myGraphics1 As System.Drawing.Graphics = e.Grap

2、hics End Sub,绘制图形时,可以调用Graphics对象的方法。常用的方法 :,2. 创建Pen对象 绘制图形时,除创建Graphics对象,还必须创建Pen对象。Pen对象用于绘制线条、勾勒形状轮廓或呈现其他几何表示形式,存储要绘制项的属性,并且将Pen对象作为参数之一传递给绘制方法。例如: Dim myPen As New Pen(Brushes.DeepSkyBlue) 创建完Pen对象,也可以使用Pen对象的属性。,常用的属性,11.1.2 在窗体上绘图,1. 绘制直线 绘制直线需要创建Graphics对象和Pen对象。 Graphics对象提供进行绘制直线的DrawLine

3、方法。其常用语法格式如下: Graphics.DrawLines (Pen, Point) 或 Graphics. DrawLines (Pen,起点坐标,终点坐标) 说明:指明直线的起点坐标(即起点列、行坐标)和终点坐标(即终点列、行坐标)。 Pen对象设定线条的样式,如直线的颜色、宽度和线型。,【例11-1】在窗体上绘制3条直线。一条从点(20,20)到(20,200),宽度为5的红色虚直线;一条从点(40,30)到(200,30),宽度为8的蓝色直线;一条从点(40,50)到(250,200),宽度为3的绿色直线。,(1)编写事件代码。 Imports System.Drawing.Dr

4、awing2D 引用System.Drawing命名空间 Public Class Form1 Private Sub Form1_Paint(ByVal sender As Object, ByVal e As _ System.Windows.Forms.PaintEventArgs) Handles Me.Paint 第1条直线 Dim redPen As New Pen(Color.Red) 创建Pen对象,并设置直线颜色 Dim myGraphics1 As Graphics = Me.CreateGraphics() 创建Graphics对象 redPen.DashStyle =

5、DashStyle.Dash 设置直线样式为虚线 redPen.Width = 5 设置直线宽度 myGraphics1.DrawLine(redPen, 20, 20, 20, 200) 绘制直线 第2条直线 Dim p1 As Point = New Point(40, 30) 创建Point对象数组,设置直线起点和终点 Dim p2 As Point = New Point(200, 30) Dim bluePen As New Pen(Color.Blue, 8) 创建Pen对象,并设置直线颜色和宽度 Dim myGraphics2 As Graphics = Me.CreateGra

6、phics() bluePen.StartCap = LineCap.RoundAnchor 设置直线起点样式 bluePen.EndCap = LineCap.ArrowAnchor 设置直线终点样式 myGraphics2.DrawLine(bluePen, p1, p2) 第3条直线 Dim greenPen As New Pen(Color.Green, 3) Dim myGraphics3 As Graphics = Me.CreateGraphics() myGraphics3.SmoothingMode = SmoothingMode.AntiAlias 消除直线锯齿 myGra

7、phics3.DrawLine(greenPen, 40, 50, 250, 200) End Sub End Class,2. 绘制矩形 绘制矩形与绘制直线类似。Graphics对象提供进行绘制矩形的DrawRectangle方法。常用语法格式如下: Graphics.DrawRectangle (Pen, Rectangle) 或 Graphics.DrawRectangle (Pen,起点坐标,终点坐标) 说明:指明矩形的左上角顶点的坐标(即左上角顶点列、行坐标),以及矩形的宽和高。Rectangle存储一组整数,共四个,表示一个矩形的位置和大小。Pen对象设定线条的样式。,【例11-2

8、】绘制2个矩形,1个为蓝色边框,另1个为红色边框。 Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint Dim bluePen As New Pen(Color.Blue, 5) Dim redPen As New Pen(Color.Red, 5) Dim myRectangle As New Rectangle(50, 80, 200, 100) Dim Graphics1 As Graphics = Me.Creat

9、eGraphics() Dim Graphics2 As Graphics = Me.CreateGraphics() Graphics1.DrawRectangle(bluePen, 30, 50, 200, 100) Graphics2.DrawRectangle(redPen, myRectangle) End Sub,3. 绘制椭圆 Graphics对象提供了进行绘制椭圆的DrawEllipse方法。语法格式如下: Graphics.DrawEllipse (Pen, Rectangle) 或 Graphics.DrawEllipse (Pen,起点坐标,终点坐标) 说明:DrawEl

10、lipse方法中的参数与DrawRectangle方法中的参数一样。当宽和高的取值相同时,椭圆就成为圆了。Rectangle存储一组整数,共4个,表示一个矩形的位置和大小。Pen对象设定椭圆的线条属性。,【例11-3】如图11-3所示,绘制3个相切的椭圆,其中两个内切、两个外切。 Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint Dim redPen As New Pen(Color.Red, 3) Dim Graphi

11、cs1 As Graphics = Me.CreateGraphics() Graphics1.DrawEllipse(redPen, 20, 20, 200, 100) Dim bluePen As New Pen(Color.Blue, 3) Dim Graphics2 As Graphics = Me.CreateGraphics() Graphics2.DrawEllipse(bluePen, 70, 20, 100, 50) Dim greenPen As New Pen(Color.Green, 3) Dim Graphics3 As Graphics = Me.CreateGra

12、phics() Graphics3.DrawEllipse(greenPen, 70, 120, 100, 100) End Sub,4. 绘制弧线 弧线其实就是椭圆的一部分。Graphics对象提供进行绘制弧线的DrawArc方法。DrawArc方法除了需要绘制椭圆的参数,还需要有起始角度和仰角参数。语法格式如下: Graphics.DrawArc (Pen,起点坐标,终点坐标,起始角度,仰角参数) 说明:最后两个参数是弧线的起始角度和仰角参数。,【例11-4】如图11-4所示,绘制2段弧线。 Private Sub Form1_Paint(ByVal sender As Object, B

13、yVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint Dim redPen As New Pen(Color.Red, 3) Dim yellowPen As New Pen(Color.Yellow, 3) Dim Graphics1 As Graphics = Me.CreateGraphics() Dim Graphics2 As Graphics = Me.CreateGraphics() Graphics1.DrawArc(redPen, 50, 50, 140, 70, 30, 180) Graphics2.

14、DrawArc(yellowPen, 100, 50, 140, 70, 60, 270) End Sub,5. 绘制多边形 多边形是有三条以上直边组成的闭合图形。若要绘制多边形,需要Graphics对象、Pen对象和Point(或PointF)对象数组。Graphics对象提供进行绘制多边形的DrawPolygon方法。其常用语法格式如下: Graphics.DrawPolygon (Pen,Point ) 说明:由一组Point结构定义的多边形。 Pen设定多边形的线条属性,Point对象数组存储将由直线连接的点。,【例11-5】绘制一个直角三角形和一个六边形。 Private Sub F

15、orm1_Paint(ByVal sender As Object, ByVal e As _ System.Windows.Forms.PaintEventArgs) Handles Me.Paint Dim redPen As New Pen(Color.Red, 3) Dim Graphics1 As Graphics = Me.CreateGraphics() Dim PointArray1 As Point() = New Point(20, 20), New Point(20, 80), New Point(100, 80) Graphics1.DrawPolygon(redPen

16、, PointArray1) Dim BlackPen As New Pen(Color.Black, 3) Dim Graphics2 As Graphics = Me.CreateGraphics() Dim PointArray2 As Point() = New Point(150, 10), New Point(120, 50), _ New Point(150, 90), New Point(200, 90), _ New Point(230, 50), New Point(200, 10) Graphics2.DrawPolygon(BlackPen, PointArray2) End Sub,6. 填充图形 对于封闭图形(如矩形、椭圆、多边形),可以设置图形颜色、背景样式等属性。Pen对象定义轮廓线的属性,而内部区域的属性

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 高等教育 > 大学课件

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号