[ vb 2008] DrawArc 예제. 본문

[PL]/VB & VB.NET

[ vb 2008] DrawArc 예제.

객과 함께. 2010. 1. 8. 21:51

Imports System.Windows.Forms
Imports System.Drawing
Imports System.Drawing.Graphics

Public Class DrawArc

    ' 프로그램명 : 원 그리기
    ' 제작일 : 2010. 01. 08
    ' 제작자 : 객과 함께.

    Dim RcDraw As Rectangle
    Dim Rc As New Rectangle
    Dim startAngle As Integer = 45
    Dim sweepAngle As Integer = 360


    Private Sub Form3_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
        RcDraw.X = e.X
        RcDraw.Y = e.Y
    End Sub

    Private Sub Form3_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp

        If e.X < RcDraw.X Then
            Rc.Width = RcDraw.X - e.X
            RcDraw.X = e.X
        Else
            Rc.Width = e.X - RcDraw.X
        End If

        If e.Y < RcDraw.Y Then
            Rc.Height = RcDraw.Y - e.Y
            RcDraw.Y = e.Y
        Else
            Rc.Height = e.Y - RcDraw.Y
        End If

        If Rc.Width = 0 And Rc.Height = 0 Then Exit Sub
        Form3Paint()
    End Sub

    Private Sub Form3Paint()
        Dim redPen As New Pen(Color.Red, 1)
        Dim G As Graphics = Me.CreateGraphics()

        G.DrawArc(redPen, RcDraw.X, RcDraw.Y, Rc.Width, Rc.Height, startAngle, sweepAngle)
    End Sub

    Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Me.WindowState = FormWindowState.Maximized
        Me.Text = " DrawArc 예제 "
    End Sub

End Class

 

[ 실행 화면 ]