Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '-------------------------------------------------------------------------------
- 'Designer Part:
- 'Add a new Form to a Project, then click the "components as IContainer" element
- 'in Solution Explorer. This opens the Form.Designer. Substitute all the existing
- 'code with the First Part of this code.
- '-------------------------------------------------------------------------------
- <Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
- Partial Class PaintForm
- Inherits System.Windows.Forms.Form
- <System.Diagnostics.DebuggerNonUserCode()> _
- Protected Overrides Sub Dispose(ByVal disposing As Boolean)
- Try
- If disposing AndAlso components IsNot Nothing Then
- components.Dispose()
- End If
- Finally
- MyBase.Dispose(disposing)
- End Try
- End Sub
- Private components As System.ComponentModel.IContainer
- <System.Diagnostics.DebuggerStepThrough()> _
- Private Sub InitializeComponent()
- Me.TrackBar1 = New System.Windows.Forms.TrackBar()
- Me.TextBox2 = New System.Windows.Forms.TextBox()
- Me.TextBox1 = New System.Windows.Forms.TextBox()
- Me.ComboBox1 = New System.Windows.Forms.ComboBox()
- Me.Label1 = New System.Windows.Forms.Label()
- Me.Label3 = New System.Windows.Forms.Label()
- Me.Panel1 = New System.Windows.Forms.Panel()
- Me.btnOpenFile = New System.Windows.Forms.Button()
- Me.Label4 = New System.Windows.Forms.Label()
- Me.Label5 = New System.Windows.Forms.Label()
- Me.TextBox3 = New System.Windows.Forms.TextBox()
- Me.TextBox4 = New System.Windows.Forms.TextBox()
- Me.TrackBar2 = New System.Windows.Forms.TrackBar()
- Me.btnUp = New System.Windows.Forms.Button()
- CType(Me.TrackBar1, System.ComponentModel.ISupportInitialize).BeginInit()
- CType(Me.TrackBar2, System.ComponentModel.ISupportInitialize).BeginInit()
- Me.SuspendLayout()
- '
- 'TrackBar1
- '
- Me.TrackBar1.LargeChange = 200
- Me.TrackBar1.Location = New System.Drawing.Point(36, 86)
- Me.TrackBar1.Maximum = 1000
- Me.TrackBar1.Name = "TrackBar1"
- Me.TrackBar1.Size = New System.Drawing.Size(135, 45)
- Me.TrackBar1.SmallChange = 20
- Me.TrackBar1.TabIndex = 5
- Me.TrackBar1.TabStop = False
- Me.TrackBar1.TickFrequency = 20
- Me.TrackBar1.Value = 300
- '
- 'TextBox2
- '
- Me.TextBox2.Location = New System.Drawing.Point(462, 460)
- Me.TextBox2.Name = "TextBox2"
- Me.TextBox2.Size = New System.Drawing.Size(34, 20)
- Me.TextBox2.TabIndex = 4
- Me.TextBox2.Text = "100"
- Me.TextBox2.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
- '
- 'TextBox1
- '
- Me.TextBox1.Location = New System.Drawing.Point(399, 460)
- Me.TextBox1.Name = "TextBox1"
- Me.TextBox1.Size = New System.Drawing.Size(34, 20)
- Me.TextBox1.TabIndex = 3
- Me.TextBox1.Text = "100"
- Me.TextBox1.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
- '
- 'ComboBox1
- '
- Me.ComboBox1.Font = New System.Drawing.Font("Segoe UI", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
- Me.ComboBox1.ForeColor = System.Drawing.Color.Black
- Me.ComboBox1.FormattingEnabled = True
- Me.ComboBox1.Location = New System.Drawing.Point(135, 459)
- Me.ComboBox1.Name = "ComboBox1"
- Me.ComboBox1.Size = New System.Drawing.Size(159, 23)
- Me.ComboBox1.TabIndex = 1
- '
- 'Label1
- '
- Me.Label1.AutoSize = True
- Me.Label1.Font = New System.Drawing.Font("Segoe UI", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
- Me.Label1.ForeColor = System.Drawing.Color.White
- Me.Label1.Location = New System.Drawing.Point(376, 462)
- Me.Label1.Name = "Label1"
- Me.Label1.Size = New System.Drawing.Size(17, 15)
- Me.Label1.TabIndex = 12
- Me.Label1.Text = "X:"
- '
- 'Label3
- '
- Me.Label3.AutoSize = True
- Me.Label3.Font = New System.Drawing.Font("Segoe UI", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
- Me.Label3.ForeColor = System.Drawing.Color.White
- Me.Label3.Location = New System.Drawing.Point(439, 462)
- Me.Label3.Name = "Label3"
- Me.Label3.Size = New System.Drawing.Size(17, 15)
- Me.Label3.TabIndex = 13
- Me.Label3.Text = "Y:"
- '
- 'Panel1
- '
- Me.Panel1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
- Me.Panel1.Location = New System.Drawing.Point(42, 128)
- Me.Panel1.Name = "Panel1"
- Me.Panel1.Size = New System.Drawing.Size(454, 315)
- Me.Panel1.TabIndex = 14
- '
- 'btnOpenFile
- '
- Me.btnOpenFile.FlatAppearance.MouseDownBackColor = System.Drawing.Color.FromArgb(CType(CType(128, Byte), Integer), CType(CType(64, Byte), Integer), CType(CType(64, Byte), Integer))
- Me.btnOpenFile.FlatAppearance.MouseOverBackColor = System.Drawing.Color.FromArgb(CType(CType(192, Byte), Integer), CType(CType(64, Byte), Integer), CType(CType(0, Byte), Integer))
- Me.btnOpenFile.FlatStyle = System.Windows.Forms.FlatStyle.Flat
- Me.btnOpenFile.Font = New System.Drawing.Font("Segoe UI", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
- Me.btnOpenFile.ForeColor = System.Drawing.Color.White
- Me.btnOpenFile.Location = New System.Drawing.Point(42, 456)
- Me.btnOpenFile.Name = "btnOpenFile"
- Me.btnOpenFile.Size = New System.Drawing.Size(74, 27)
- Me.btnOpenFile.TabIndex = 0
- Me.btnOpenFile.Text = "Open new"
- Me.btnOpenFile.UseVisualStyleBackColor = True
- '
- 'Label4
- '
- Me.Label4.AutoSize = True
- Me.Label4.Font = New System.Drawing.Font("Segoe UI", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
- Me.Label4.ForeColor = System.Drawing.Color.White
- Me.Label4.Location = New System.Drawing.Point(277, 95)
- Me.Label4.Name = "Label4"
- Me.Label4.Size = New System.Drawing.Size(42, 15)
- Me.Label4.TabIndex = 19
- Me.Label4.Text = "Width:"
- '
- 'Label5
- '
- Me.Label5.AutoSize = True
- Me.Label5.Font = New System.Drawing.Font("Segoe UI", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
- Me.Label5.ForeColor = System.Drawing.Color.White
- Me.Label5.Location = New System.Drawing.Point(176, 95)
- Me.Label5.Name = "Label5"
- Me.Label5.Size = New System.Drawing.Size(46, 15)
- Me.Label5.TabIndex = 18
- Me.Label5.Text = "Height:"
- '
- 'TextBox3
- '
- Me.TextBox3.Location = New System.Drawing.Point(226, 93)
- Me.TextBox3.Name = "TextBox3"
- Me.TextBox3.Size = New System.Drawing.Size(34, 20)
- Me.TextBox3.TabIndex = 6
- Me.TextBox3.Text = "100"
- Me.TextBox3.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
- '
- 'TextBox4
- '
- Me.TextBox4.Location = New System.Drawing.Point(322, 93)
- Me.TextBox4.Name = "TextBox4"
- Me.TextBox4.Size = New System.Drawing.Size(34, 20)
- Me.TextBox4.TabIndex = 7
- Me.TextBox4.Text = "100"
- Me.TextBox4.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
- '
- 'TrackBar2
- '
- Me.TrackBar2.LargeChange = 200
- Me.TrackBar2.Location = New System.Drawing.Point(367, 86)
- Me.TrackBar2.Maximum = 1000
- Me.TrackBar2.Name = "TrackBar2"
- Me.TrackBar2.Size = New System.Drawing.Size(135, 45)
- Me.TrackBar2.SmallChange = 20
- Me.TrackBar2.TabIndex = 8
- Me.TrackBar2.TabStop = False
- Me.TrackBar2.TickFrequency = 20
- Me.TrackBar2.Value = 300
- '
- 'btnUp
- '
- Me.btnUp.FlatAppearance.MouseDownBackColor = System.Drawing.Color.FromArgb(CType(CType(128, Byte), Integer), CType(CType(64, Byte), Integer), CType(CType(64, Byte), Integer))
- Me.btnUp.FlatAppearance.MouseOverBackColor = System.Drawing.Color.FromArgb(CType(CType(192, Byte), Integer), CType(CType(64, Byte), Integer), CType(CType(0, Byte), Integer))
- Me.btnUp.FlatStyle = System.Windows.Forms.FlatStyle.Flat
- Me.btnUp.Font = New System.Drawing.Font("Segoe UI", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
- Me.btnUp.ForeColor = System.Drawing.Color.White
- Me.btnUp.Location = New System.Drawing.Point(300, 458)
- Me.btnUp.Name = "btnUp"
- Me.btnUp.Size = New System.Drawing.Size(32, 25)
- Me.btnUp.TabIndex = 2
- Me.btnUp.Text = "Up"
- Me.btnUp.UseVisualStyleBackColor = True
- '
- 'PaintForm
- '
- Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
- Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
- Me.BackColor = System.Drawing.Color.FromArgb(CType(CType(32, Byte), Integer), CType(CType(32, Byte), Integer), CType(CType(32, Byte), Integer))
- Me.ClientSize = New System.Drawing.Size(522, 463)
- Me.Controls.Add(Me.btnUp)
- Me.Controls.Add(Me.Panel1)
- Me.Controls.Add(Me.TrackBar2)
- Me.Controls.Add(Me.Label4)
- Me.Controls.Add(Me.Label5)
- Me.Controls.Add(Me.TextBox3)
- Me.Controls.Add(Me.TextBox4)
- Me.Controls.Add(Me.btnOpenFile)
- Me.Controls.Add(Me.Label3)
- Me.Controls.Add(Me.Label1)
- Me.Controls.Add(Me.ComboBox1)
- Me.Controls.Add(Me.TextBox1)
- Me.Controls.Add(Me.TextBox2)
- Me.Controls.Add(Me.TrackBar1)
- Me.DoubleBuffered = True
- Me.Name = "PaintForm"
- Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
- Me.Text = "PaintForm"
- CType(Me.TrackBar1, System.ComponentModel.ISupportInitialize).EndInit()
- CType(Me.TrackBar2, System.ComponentModel.ISupportInitialize).EndInit()
- Me.ResumeLayout(False)
- Me.PerformLayout()
- End Sub
- Friend WithEvents TrackBar1 As System.Windows.Forms.TrackBar
- Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
- Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
- Friend WithEvents ComboBox1 As System.Windows.Forms.ComboBox
- Friend WithEvents Label1 As System.Windows.Forms.Label
- Friend WithEvents Label3 As System.Windows.Forms.Label
- Friend WithEvents Panel1 As System.Windows.Forms.Panel
- Friend WithEvents btnOpenFile As System.Windows.Forms.Button
- Friend WithEvents Label4 As System.Windows.Forms.Label
- Friend WithEvents Label5 As System.Windows.Forms.Label
- Friend WithEvents TextBox3 As System.Windows.Forms.TextBox
- Friend WithEvents TextBox4 As System.Windows.Forms.TextBox
- Friend WithEvents TrackBar2 As System.Windows.Forms.TrackBar
- Friend WithEvents btnUp As System.Windows.Forms.Button
- End Class
- '-------------------------------------------------------------------------------
- 'Designer Part: End of file
- '-------------------------------------------------------------------------------
- '-------------------------------------------------------------------------------
- 'Code Part:
- 'Insert the following code in the Code Section of the new Form.
- 'Substitute all of the pre-defined code with this.
- '-------------------------------------------------------------------------------
- Imports System.Drawing
- Imports System.Drawing.Drawing2D
- Imports System.Drawing.Imaging
- Imports System.IO
- Public Class PaintForm
- Public Class BitmapObject
- Public Property Name As String
- Public Property Image As Bitmap
- Public Property Position As Point
- Public Property Size As Size
- Public Property Order As Integer
- End Class
- Public MyBitmaps As List(Of BitmapObject) = New List(Of BitmapObject)
- Private Sub btnOpenFile_Click(sender As Object, e As EventArgs) Handles btnOpenFile.Click
- Dim fd As OpenFileDialog = New OpenFileDialog()
- fd.InitialDirectory = "d:\images\"
- Dim dr As DialogResult = fd.ShowDialog()
- If dr = Windows.Forms.DialogResult.OK Then
- Dim BitmapName As String = New FileInfo(fd.FileName).Name
- Using tmpBitmap As Bitmap = New Bitmap(fd.FileName)
- MyBitmaps.Add(New BitmapObject With {
- .Image = New Bitmap(tmpBitmap),
- .Position = New Point(Integer.Parse(TextBox1.Text), Integer.Parse(TextBox2.Text)),
- .Size = New Size(tmpBitmap.Height, tmpBitmap.Width),
- .Order = MyBitmaps.Count,
- .Name = BitmapName})
- ComboBox1.Items.Add(BitmapName)
- ComboBox1.SelectedIndex = MyBitmaps.Count - 1
- TrackBar1.Value = tmpBitmap.Height
- TrackBar2.Value = tmpBitmap.Width
- Panel1.Invalidate()
- End Using
- End If
- End Sub
- Private Sub Panel1_Paint(sender As Object, e As PaintEventArgs) Handles Panel1.Paint
- If MyBitmaps.Count > 0 Then
- MyBitmaps.OrderBy(Function(item) item.Order).
- Select(Function(item)
- e.Graphics.DrawImage(item.Image, New Rectangle(item.Position, item.Size))
- Return item
- End Function).ToList()
- End If
- End Sub
- Private Sub TBoxPosition_KeyDown(sender As Object, e As KeyEventArgs) Handles TextBox1.KeyDown, TextBox2.KeyDown
- If (e.KeyValue = Keys.Enter) AndAlso (MyBitmaps.Count > 0) Then
- MyBitmaps(ComboBox1.SelectedIndex).Position = New Point(Integer.Parse(TextBox1.Text), Integer.Parse(TextBox2.Text))
- Panel1.Invalidate()
- End If
- End Sub
- Private Sub TBox_Enter(sender As Object, e As EventArgs) Handles TextBox1.Enter, TextBox2.Enter, TextBox3.Enter, TextBox4.Enter
- CType(sender, TextBox).SelectAll()
- End Sub
- Private Sub TBar_ChangeSize(sender As Object, e As EventArgs) Handles TrackBar1.Scroll, TrackBar2.Scroll
- TextBox3.Text = TrackBar1.Value.ToString
- TextBox4.Text = TrackBar2.Value.ToString
- MyBitmaps(ComboBox1.SelectedIndex).Size = New Size(TrackBar1.Value, TrackBar2.Value)
- Panel1.Invalidate()
- End Sub
- Private Sub TBar_ValueChanged(sender As Object, e As EventArgs) Handles TrackBar1.ValueChanged, TrackBar2.ValueChanged
- TextBox3.Text = TrackBar1.Value.ToString
- TextBox4.Text = TrackBar2.Value.ToString
- End Sub
- Private Sub ComboBox1_SelectionChangeCommitted(sender As Object, e As EventArgs) Handles ComboBox1.SelectionChangeCommitted
- TrackBar1.Value = MyBitmaps(ComboBox1.SelectedIndex).Size.Height
- TrackBar2.Value = MyBitmaps(ComboBox1.SelectedIndex).Size.Width
- TextBox1.Text = MyBitmaps(ComboBox1.SelectedIndex).Position.X.ToString
- TextBox2.Text = MyBitmaps(ComboBox1.SelectedIndex).Position.Y.ToString
- End Sub
- Private Sub btnUp_Click_1(sender As Object, e As EventArgs) Handles btnUp.Click
- Dim CurrentImageOrder As Integer = MyBitmaps(ComboBox1.SelectedIndex).Order
- For Each Item As BitmapObject In MyBitmaps
- If Item.Order = MyBitmaps.Count - 1 Then
- Item.Order = CurrentImageOrder
- Exit For
- End If
- Next
- MyBitmaps(ComboBox1.SelectedIndex).Order = MyBitmaps.Count - 1
- Panel1.Invalidate()
- End Sub
- End Class
- '-------------------------------------------------------------------------------
- 'Code Part: End of file.
- '-------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment