GDI

来源:互联网 发布:基金有什么软件 编辑:程序博客网 时间:2024/06/16 10:47

'绘制空心图形

Private Sub DrawEllipse()    '绘制椭圆    Dim myPen As New System.Drawing.Pen(System.Drawing.Color.Red)    Dim formGraphics As System.Drawing.Graphics    formGraphics = Me.CreateGraphics()    formGraphics.DrawEllipse(myPen, New Rectangle(0, 0, 200, 300))    myPen.Dispose()    formGraphics.Dispose()End SubPrivate Sub DrawRectangle()  '绘制矩形    Dim myPen As New System.Drawing.Pen(System.Drawing.Color.Red)    Dim formGraphics As System.Drawing.Graphics    formGraphics = Me.CreateGraphics()    formGraphics.DrawRectangle(myPen, New Rectangle(0, 0, 200, 300))    myPen.Dispose()    formGraphics.Dispose()End SuB

Public Sub DrawString()  '绘制文本    Dim formGraphics As System.Drawing.Graphics = Me.CreateGraphics()    Dim drawString As String = "Sample Text"    Dim drawFont As New System.Drawing.Font("Arial", 16)    Dim drawBrush As New _       System.Drawing.SolidBrush(System.Drawing.Color.Black)    Dim x As Single = 150.0    Dim y As Single = 50.0    Dim drawFormat As New System.Drawing.StringFormat    formGraphics.DrawString(drawString, drawFont, drawBrush, _        x, y, drawFormat)    drawFont.Dispose()    drawBrush.Dispose()    formGraphics.Dispose()End Sub


Private Sub RenderText6(ByVal e As PaintEventArgs)   '绘制多行文本    Dim flags As TextFormatFlags = TextFormatFlags.Bottom Or _        TextFormatFlags.EndEllipsis    TextRenderer.DrawText(e.Graphics, _    "This is some text that will be clipped at the end.", _    Me.Font, New Rectangle(10, 10, 100, 50), SystemColors.ControlText, flags)End Sub

Private Sub Form1_Paint(ByVal sender As Object, ByVal e As _    System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint    ' Draw a circle with a bar on top.
'在 Windows 窗体中复制像素以减少闪烁        e.Graphics.FillEllipse(Brushes.DarkBlue, New Rectangle _             (10, 10, 60, 60))        e.Graphics.FillRectangle(Brushes.Khaki, New Rectangle _             (20, 30, 60, 10))    ' Copy the graphic to a new location.        e.Graphics.CopyFromScreen(New Point(10, 10), New Point _             (100, 100), New Size(70, 70))End Sub


'绘制实心椭圆

Dim myBrush As New System.Drawing.SolidBrush(System.Drawing.Color.Red)Dim formGraphics As System.Drawing.GraphicsformGraphics = Me.CreateGraphics()formGraphics.FillEllipse(myBrush, New Rectangle(0, 0, 200, 300))myBrush.Dispose()formGraphics.Dispose()

’创建特定形状的 Windows 窗体

 Protected Overrides Sub OnPaint( _ByVal e As System.Windows.Forms.PaintEventArgs)     Dim shape As New System.Drawing.Drawing2D.GraphicsPath     shape.AddEllipse(0, 0, Me.Width, Me.Height)     Me.Region = New System.Drawing.Region(shape) End Sub

0 0
原创粉丝点击