Paint в VB

Пейнт в ВБ. Работает почти все. Кроме рисования прямоугольника вверх и влево. Вывода текст. Все остальное вроде работает. Код без комментариев.
Imports System.Drawing.Drawing2D
Imports System.Drawing.Graphics
Imports System.IO
Public Class Form1
    Private xOld, yOld As Integer
    Dim x1, x2, y1, y2, a, b, a3, b3 As Integer
    Dim gr As Graphics
    Dim a1, b1, a2, b2 As Int16
    Dim ijTochka() As Point
    Dim ijtochka1, ijtochka2, ijkrapka As Point
    Dim ris, dvig, pryamoug, ellips, risfig, active, f1, f2, text1 As Boolean
    Dim figura As String
    Dim fnt As New Font("Times New Roman", 20, FontStyle.Bold)
    Dim sb As New SolidBrush(Color.Red)
    Dim p As New Pen(Color.Black, 1)
    Dim pn As New Pen(Color.White, 1)
    Dim Image1 As New Bitmap(820, 521)
    Dim kadr As New Bitmap(Me.Width, Me.Height)
    Dim bmp As Bitmap
    Dim g As Graphics, grap As Graphics
    Dim st1 As String
    Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click

        If text1 = True Then
            gr.DrawString(st1, fnt, Brushes.Black, 50, 50)
        End If
        gr = Graphics.FromImage(kadr)
        'gr = PictureBox1.CreateGraphics
        active = True
        figura = ""
        f1 = False
        f2 = False
       
    End Sub
    Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
        p.Width = TextBox1.Text
        pn.Width = TextBox1.Text
        x1 = e.X
        x2 = e.X
        y1 = e.Y
        y2 = e.Y
        a = 0
        b = 0
        a3 = 0
        b3 = 0
        ijtochka1.X = e.X
        ijtochka1.Y = e.Y
        If active = True Then
            ris = True
        End If
        If (figura = "pryamoug") Or (figura = "ellips") Then
            risfig = True
            ijtochka1.X = e.X
            ijtochka1.Y = e.Y
        End If
        If f2 Then
            f1 = True
            ris = False
            risfig = False
            xOld = e.X() : yOld = e.Y()
        End If
        If text1 = True Then
            gr.DrawString(st1, fnt, Brushes.Black, ijtochka1.X = e.X, ijtochka1.Y = e.Y)
        End If
    End Sub

    Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove

        If ris Then
            a1 = e.X - x1
            b1 = e.Y - y1
            'If a1 >= 0 And b1 >= 0 Then
            gr.DrawLine(pn, x1, y1, a, b)
            gr.DrawLine(p, x1, y1, e.X, e.Y)
            'Else
            '    ris = False
            ' End If
            a = e.X
            b = e.Y
            PictureBox1.Image = kadr
        End If
        If risfig = True Then
            If figura = "pryamoug" Then
                gr.DrawRectangle(pn, ijtochka1.X, ijtochka1.Y, a1, b1)
                a2 = e.X - ijtochka1.X
                b2 = e.Y - ijtochka1.Y

                gr.DrawRectangle(p, ijtochka1.X, ijtochka1.Y, a2, b2)
                a1 = a2
                b1 = b2
                PictureBox1.Image = kadr
            End If
        End If
        If risfig = True Then
            If figura = "ellips" Then
                gr.DrawEllipse(pn, ijtochka1.X, ijtochka1.Y, a1, b1)
                a2 = e.X - ijtochka1.X
                b2 = e.Y - ijtochka1.Y

                gr.DrawEllipse(p, ijtochka1.X, ijtochka1.Y, a2, b2)
                a1 = a2
                b1 = b2
                PictureBox1.Image = kadr
            End If
        End If
        If f1 Then
            Dim x As Integer = e.X
            Dim y As Integer = e.Y
            gr.DrawLine(p, xOld, yOld, x, y)
            xOld = x : yOld = y
            PictureBox1.Image = kadr
        End If
    End Sub
    Private Sub PictureBox1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp
        ris = False
        risfig = False
        'active = False
        f1 = False
    

    End Sub

    Private Sub ToolStripButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton2.Click
        gr = Graphics.FromImage(kadr)
        'gr = PictureBox1.CreateGraphics
        f1 = False
        f2 = False
        figura = "pryamoug"
        ris = False
        active = False
    End Sub

    Private Sub ToolStripButton3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton3.Click
        gr = Graphics.FromImage(kadr)
        'gr = PictureBox1.CreateGraphics
        f1 = False
        f2 = False
        figura = "ellips"
        ris = False
        active = False
    End Sub

    Private Sub ToolStripButton4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton4.Click
        gr = Graphics.FromImage(kadr)
        'gr = PictureBox1.CreateGraphics
        f2 = True
        ris = False
    End Sub

    Private Sub ToolStripLabel1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripLabel1.Click
        '        Dim rec As New Rectangle(0, 0,
        'MyClass.ClientSize.Width, MyClass.ClientSize.Height)
        '        Dim bp As Brush
        '        bp = New SolidBrush(Color.White)
        '        gr.FillRectangle(bp, rec)
       gr.Clear(Color.White)
        PictureBox1.Image = kadr
    End Sub

    Private Sub ToolStripButton6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton6.Click

        Dim color As New Color
        CD1.Color = CD1.Color.Black
        CD1.FullOpen = True
        If CD1.ShowDialog = DialogResult.OK Then ToolStripButton6.BackColor = CD1.Color
        p.Color = CD1.Color
    End Sub

    Private Sub ToolStripLabel2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripLabel2.Click
        'SFD1.InitialDirectory = "C\"
        'SFD1.Title = "Paint"
        'SFD1.Filter = "Png|*.png; *.htm|Jpg (*.JPG)|*.txt|Все файлы (*.*)|*.*"
        'SFD1.FilterIndex = 2
        'If SFD1.ShowDialog = DialogResult.OK Then MsgBox(SFD1.FileName)
        'Saves the Image Captured
        Image1 = PictureBox1.Image
        SFD1.Filter = "bmp (*.BMP)|*.BMP"
        If SFD1.ShowDialog = DialogResult.OK Then MsgBox(SFD1.FileName)
        Image1.Save(SFD1.FileName, System.Drawing.Imaging.ImageFormat.Bmp)
    End Sub

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Image1 = PictureBox1.Image
        p.Width = TextBox1.Text
        pn.Width = TextBox1.Text
        kadr = New Bitmap(PictureBox1.Width, PictureBox1.Height)
        kadr.MakeTransparent(Color.White)
        gr = Graphics.FromImage(kadr)
        'gr.Clear(Color.White)
        PictureBox1.Image = kadr
    End Sub

    Private Sub ToolStripButton5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton5.Click
        openfile.Filter = "Image Png|*.png|Image Jpg|*.jpg"
        If openfile.ShowDialog = DialogResult.Cancel Then Exit Sub
        PictureBox1.Image = Image.FromFile(openfile.FileName) : Me.Text = ("Paint : " & openfile.SafeFileName)
        bmp = New Bitmap(PictureBox1.Width, PictureBox1.Height)
        g = Graphics.FromImage(bmp)
        gr = Graphics.FromImage(kadr)
        'grap = PictureBox1.CreateGraphics
        p.StartCap = Drawing2D.LineCap.Round
        p.EndCap = Drawing2D.LineCap.Round
        g.DrawImage(New Bitmap(openfile.FileName), 0, 0)
        gr.DrawImage(New Bitmap(openfile.FileName), 0, 0)
        PictureBox1.Image = bmp
    End Sub

    Private Sub ToolStripButton7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton7.Click
        'Dim wid As Integer
        'Dim hgt As Integer
        'Dim X As Integer
        'Dim Y As Integer

        '' Make a Bitmap representing the input image.
        'Dim bm_in As New Bitmap(PictureBox1.Image)
        'wid = bm_in.Width
        'hgt = bm_in.Height

        '' Make the output bitmap.
        'Dim bm_out As New Bitmap(hgt, wid)

        '' Copy the pixel values.
        'For Y = 0 To wid - 1
        '    For X = 0 To hgt - 1
        '        bm_out.SetPixel(hgt - X - 1, Y, _
        '                        bm_in.GetPixel(Y, X))
        '    Next X
        'Next Y

        '' Display the result.
        'PictureBox1.Image = bm_out
        If kadr IsNot Nothing Then
            kadr.RotateFlip(RotateFlipType.Rotate270FlipXY)
            PictureBox1.Image = kadr
        End If
    End Sub

    Private Sub ToolStripButton8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton8.Click
        If kadr IsNot Nothing Then
            kadr.RotateFlip(RotateFlipType.Rotate90FlipXY)
            PictureBox1.Image = kadr
        End If
    End Sub

    Private Sub ToolStripButton9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton9.Click
        If kadr IsNot Nothing Then
            kadr.RotateFlip(RotateFlipType.Rotate180FlipX)
            PictureBox1.Image = kadr
        End If
    End Sub

    Private Sub ToolStripButton10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton10.Click
        If kadr IsNot Nothing Then
            kadr.RotateFlip(RotateFlipType.Rotate180FlipY)
            PictureBox1.Image = kadr
        End If
    End Sub

    Private Sub ToolStripLabel3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripLabel3.Click
        st1 = InputBox("", "", "Введите текст")
        text1 = True
    End Sub
End Class
Добавлено: 10 Августа 2013 11:46:24 Добавил: Андрей Ковальчук Нравится 0
Добавить
Комментарии:
Нету комментариев для вывода...