Private Sub Button1_Click ( ByVal sender As System.Object , ByVal e As System.EventArgs ) Handles Button1.Click Dim p As System.Drawing.Drawing2D.GraphicsPath = New System.Drawing.Drawing2D.GraphicsPath ( ) Dim Width As Integer = Me.ClientSize.Width Dim Height As Integer = Me.ClientSize.Height p.AddEllipse ( 0 , 20 , Width - 50 , Height - 100 ) '根据要绘制椭圆的形状来填写AddEllipse方法中椭圆对应的相应参数 Region = New Region ( p ) End Sub
Private Sub Button2_Click ( ByVal sender As System.Object , ByVal e As System.EventArgs ) Handles Button2.Click Dim p As System.Drawing.Drawing2D.GraphicsPath = New System.Drawing.Drawing2D.GraphicsPath ( ) p.AddPie ( 10 , 10 , 250 , 250 , 5 , 150 ) '根据要实现的扇形形状来填写AddPie方法中的相应参数 Me.Region = New Region ( p ) End Sub
Private Sub Button3_Click ( ByVal sender As System.Object , ByVal e As System.EventArgs ) Handles Button3.Click Dim p As System.Drawing.Drawing2D.GraphicsPath = New System.Drawing.Drawing2D.GraphicsPath ( ) Dim Width As Integer = Me.ClientSize.Width Dim Height As Integer = Me.ClientSize.Height p.AddEllipse ( 0 , 0 , Height , Height ) Me.Region = New Region ( p ) '圆形即是椭圆的一种特例, End Sub 11. 用下列代码替换Form1.vb中的Button4的Click事件对应的处理代码,下列代码功能是改变当前窗体形状为环形:
Private Sub Button4_Click ( ByVal sender As System.Object , ByVal e As System.EventArgs ) Handles Button4.Click Dim p As System.Drawing.Drawing2D.GraphicsPath = New System.Drawing.Drawing2D.GraphicsPath ( ) Dim Height As Integer = Me.ClientSize.Height Dim width As Integer = 100 p.AddEllipse ( 0 , 0 , Height , Height ) p.AddEllipse ( width , width , Height - ( width * 2 ) , Height - ( width * 2 ) ) '根据环形的形状来分别填写AddEllipse方法中相应的参数 Me.Region = New Region ( p ) End Sub
Private Sub Button5_Click ( ByVal sender As System.Object , ByVal e As System.EventArgs ) Handles Button5.Click Dim p As System.Drawing.Drawing2D.GraphicsPath = New System.Drawing.Drawing2D.GraphicsPath ( ) p.AddLine ( 0 , 0 , 250 , 150 ) p.AddLine ( 250 , 150 , 0 , 300 ) p.AddLine ( 0 , 0 , 0 , 300 ) '根据三角形的形状特征来分别填写AddLine方法中相应的参数 Me.Region = New Region ( p ) End Sub