تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
كيفيه التعامل من ال ImageList Class
#1
كاتب الموضوع : AhmedEssawy

how to select, remove, and display images.

vb.net

كود :
[color=blue]Imports[/color] System
[color=blue]Imports[/color] System.Drawing
[color=blue]Imports[/color] System.ComponentModel
[color=blue]Imports[/color] System.Windows.Forms

[color=blue]Public[/color] [color=blue]Class[/color] Form1
[color=blue]Inherits[/color] System.Windows.Forms.Form
[color=blue]Private[/color] listBox1 [color=blue]As[/color] System.Windows.Forms.ListBox
[color=blue]Private[/color] label3 [color=blue]As[/color] System.Windows.Forms.Label
[color=blue]Private[/color] [color=blue]WithEvents[/color] button1 [color=blue]As[/color] System.Windows.Forms.Button
[color=blue]Private[/color] [color=blue]WithEvents[/color] button2 [color=blue]As[/color] System.Windows.Forms.Button
[color=blue]Private[/color] [color=blue]WithEvents[/color] button3 [color=blue]As[/color] System.Windows.Forms.Button
[color=blue]Private[/color] [color=blue]WithEvents[/color] button4 [color=blue]As[/color] System.Windows.Forms.Button
[color=blue]Private[/color] pictureBox1 [color=blue]As[/color] System.Windows.Forms.PictureBox
[color=blue]Private[/color] imageList1 [color=blue]As[/color] System.Windows.Forms.ImageList
[color=blue]Private[/color] openFileDialog1 [color=blue]As[/color] System.Windows.Forms.OpenFileDialog
[color=blue]Protected[/color] myGraphics [color=blue]As[/color] Graphics
[color=blue]Private[/color] panel1 [color=blue]As[/color] System.Windows.Forms.Panel
[color=blue]Private[/color] label5 [color=blue]As[/color] System.Windows.Forms.Label
[color=blue]Private[/color] currentImage [color=blue]As[/color] [color=blue]Integer[/color] = 0

[color=blue]Public[/color] [color=blue]Sub[/color] [color=blue]New[/color]()
imageList1 = [color=blue]New[/color] ImageList()

InitializeComponent()
[color=green]' The default image size is 16 x 16, which sets up a larger[/color]
[color=green]' image size. [/color]
imageList1.ImageSize = [color=blue]New[/color] Size(255, 255)
imageList1.TransparentColor = Color.White

[color=green]' Assigns the graphics object to use in the draw options.[/color]
myGraphics = Graphics.FromHwnd(panel1.Handle)

[color=blue]End[/color] [color=blue]Sub[/color] [color=green]'New[/color]

[color=blue]Private[/color] [color=blue]Sub[/color] InitializeComponent()

[color=blue]Me[/color].listBox1 = [color=blue]New[/color] System.Windows.Forms.ListBox()
[color=blue]Me[/color].label3 = [color=blue]New[/color] System.Windows.Forms.Label()
[color=blue]Me[/color].button1 = [color=blue]New[/color] System.Windows.Forms.Button()
[color=blue]Me[/color].button2 = [color=blue]New[/color] System.Windows.Forms.Button()
[color=blue]Me[/color].button3 = [color=blue]New[/color] System.Windows.Forms.Button()
[color=blue]Me[/color].button4 = [color=blue]New[/color] System.Windows.Forms.Button()
[color=blue]Me[/color].pictureBox1 = [color=blue]New[/color] System.Windows.Forms.PictureBox()
[color=blue]Me[/color].openFileDialog1 = [color=blue]New[/color] System.Windows.Forms.OpenFileDialog()
[color=blue]Me[/color].panel1 = [color=blue]New[/color] System.Windows.Forms.Panel()
[color=blue]Me[/color].label5 = [color=blue]New[/color] System.Windows.Forms.Label()
[color=blue]Me[/color].SuspendLayout()

[color=blue]Me[/color].listBox1.Location = [color=blue]New[/color] System.Drawing.Point(16, 16)
[color=blue]Me[/color].listBox1.Size = [color=blue]New[/color] System.Drawing.Size(400, 95)
[color=blue]Me[/color].listBox1.TabIndex = 0

[color=blue]Me[/color].label3.Location = [color=blue]New[/color] System.Drawing.Point(24, 168)
[color=blue]Me[/color].label3.Text = [color=maroon]"label3"[/color]

[color=blue]Me[/color].button1.Location = [color=blue]New[/color] System.Drawing.Point(96, 128)
[color=blue]Me[/color].button1.Size = [color=blue]New[/color] System.Drawing.Size(104, 23)
[color=blue]Me[/color].button1.Text = [color=maroon]"Show Next Image"[/color]

[color=blue]Me[/color].button2.Location = [color=blue]New[/color] System.Drawing.Point(208, 128)
[color=blue]Me[/color].button2.Size = [color=blue]New[/color] System.Drawing.Size(104, 23)
[color=blue]Me[/color].button2.Text = [color=maroon]"Remove Image"[/color]

[color=blue]Me[/color].button3.Location = [color=blue]New[/color] System.Drawing.Point(320, 128)
[color=blue]Me[/color].button3.Text = [color=maroon]"Clear List"[/color]

[color=blue]Me[/color].button4.Location = [color=blue]New[/color] System.Drawing.Point(16, 128)
[color=blue]Me[/color].button4.Text = [color=maroon]"Open Image"[/color]

[color=blue]Me[/color].pictureBox1.Location = [color=blue]New[/color] System.Drawing.Point(328, 232)
[color=blue]Me[/color].pictureBox1.Size = [color=blue]New[/color] System.Drawing.Size(336, 192)

[color=blue]Me[/color].imageList1.ImageSize = [color=blue]New[/color] System.Drawing.Size(16, 16)
[color=blue]Me[/color].imageList1.TransparentColor = System.Drawing.Color.Transparent

[color=blue]Me[/color].panel1.Location = [color=blue]New[/color] System.Drawing.Point(8, 240)
[color=blue]Me[/color].panel1.Size = [color=blue]New[/color] System.Drawing.Size(296, 184)

[color=blue]Me[/color].label5.Location = [color=blue]New[/color] System.Drawing.Point(168, 168)
[color=blue]Me[/color].label5.Size = [color=blue]New[/color] System.Drawing.Size(312, 40)
[color=blue]Me[/color].label5.Text = [color=maroon]"label5"[/color]

[color=blue]Me[/color].ClientSize = [color=blue]New[/color] System.Drawing.Size(672, 461)
[color=blue]Me[/color].Controls.Add(label5)
[color=blue]Me[/color].Controls.Add(panel1)
[color=blue]Me[/color].Controls.Add(pictureBox1)
[color=blue]Me[/color].Controls.Add(button4)
[color=blue]Me[/color].Controls.Add(button3)
[color=blue]Me[/color].Controls.Add(button2)
[color=blue]Me[/color].Controls.Add(button1)
[color=blue]Me[/color].Controls.Add(label3)
[color=blue]Me[/color].Controls.Add(listBox1)
[color=blue]Me[/color].ResumeLayout([color=blue]False[/color])
[color=blue]End[/color] [color=blue]Sub[/color]

[color=green]' Display the image.[/color]
[color=blue]Private[/color] [color=blue]Sub[/color] button1_Click([color=blue]ByVal[/color] sender [color=blue]As[/color] [color=blue]Object[/color], _
[color=blue]ByVal[/color] e [color=blue]As[/color] System.EventArgs) [color=blue]Handles[/color] button1.Click

[color=blue]If[/color] imageList1.Images.Empty <> [color=blue]True[/color] [color=blue]Then[/color]
[color=blue]If[/color] imageList1.Images.Count - 1 > currentImage [color=blue]Then[/color]
currentImage += 1
[color=blue]Else[/color]
currentImage = 0
[color=blue]End[/color] [color=blue]If[/color]
panel1.Refresh()

[color=green]' Draw the image in the panel.[/color]
imageList1.Draw(myGraphics, 10, 10, currentImage)

[color=green]' Show the image in the PictureBox.[/color]
pictureBox1.Image = imageList1.Images(currentImage)
label3.Text = [color=maroon]"Current image is "[/color] + currentImage.ToString
listBox1.SelectedIndex = currentImage
label5.Text = [color=maroon]"Image is "[/color] + listBox1.Text
[color=blue]End[/color] [color=blue]If[/color]
[color=blue]End[/color] [color=blue]Sub[/color]

[color=green]' Remove the image.[/color]
[color=blue]Private[/color] [color=blue]Sub[/color] button2_Click([color=blue]ByVal[/color] sender [color=blue]As[/color] [color=blue]Object[/color], _
[color=blue]ByVal[/color] e [color=blue]As[/color] System.EventArgs) [color=blue]Handles[/color] button2.Click

imageList1.Images.RemoveAt(listBox1.SelectedIndex)
listBox1.Items.Remove(listBox1.SelectedItem)
[color=blue]End[/color] [color=blue]Sub[/color]

[color=green]' Clear all images.[/color]
[color=blue]Private[/color] [color=blue]Sub[/color] button3_Click([color=blue]ByVal[/color] sender [color=blue]As[/color] [color=blue]Object[/color], _
[color=blue]ByVal[/color] e [color=blue]As[/color] System.EventArgs) [color=blue]Handles[/color] button3.Click
imageList1.Images.Clear()
listBox1.Items.Clear()
[color=blue]End[/color] [color=blue]Sub[/color]

[color=green]' Find an image.[/color]
[color=blue]Private[/color] [color=blue]Sub[/color] button4_Click([color=blue]ByVal[/color] sender [color=blue]As[/color] [color=blue]Object[/color], _
[color=blue]ByVal[/color] e [color=blue]As[/color] System.EventArgs) [color=blue]Handles[/color] button4.Click

openFileDialog1.Multiselect = [color=blue]True[/color]
[color=blue]If[/color] openFileDialog1.ShowDialog() = DialogResult.OK [color=blue]Then[/color]
[color=blue]If[/color] (openFileDialog1.FileNames IsNot [color=blue]Nothing[/color]) [color=blue]Then[/color]
[color=blue]Dim[/color] i [color=blue]As[/color] [color=blue]Integer[/color]
[color=blue]For[/color] i = 0 [color=blue]To[/color] openFileDialog1.FileNames.Length - 1
addImage(openFileDialog1.FileNames(i))
[color=blue]Next[/color] i
[color=blue]Else[/color]
addImage(openFileDialog1.FileName)
[color=blue]End[/color] [color=blue]If[/color]
[color=blue]End[/color] [color=blue]If[/color]
[color=blue]End[/color] [color=blue]Sub[/color]

[color=blue]Private[/color] [color=blue]Sub[/color] addImage([color=blue]ByVal[/color] imageToLoad [color=blue]As[/color] [color=blue]String[/color])
[color=blue]If[/color] imageToLoad <> [color=maroon]""[/color] [color=blue]Then[/color]
imageList1.Images.Add(Image.FromFile(imageToLoad))
listBox1.BeginUpdate()
listBox1.Items.Add(imageToLoad)
listBox1.EndUpdate()
[color=blue]End[/color] [color=blue]If[/color]
[color=blue]End[/color] [color=blue]Sub[/color]

<StaThread()> _
[color=blue]Public[/color] [color=blue]Shared[/color] [color=blue]Sub[/color] Main([color=blue]ByVal[/color] args() [color=blue]As[/color] [color=blue]String[/color])
Application.Run([color=blue]New[/color] Form1())
[color=blue]End[/color] [color=blue]Sub[/color]
[color=blue]End[/color] [color=blue]Class[/color]
}}}}
تم الشكر بواسطة:


المواضيع المحتمل أن تكون متشابهة .
الموضوع : الكاتب الردود : المشاهدات : آخر رد
  احتراف التعامل مع ( ملفات التهية ini ) باسهل الطرق مكتبه كاملة من صنعى : اصدار 1.0.1 ali.alfoly 0 711 21-08-13, 08:34 AM
آخر رد: ali.alfoly
  احتراف التعامل مع ( ملفات التهية ini ) باسهل الطرق مكتبه كاملة من صنعى : اصدار 1.0.0 ali.alfoly 9 1,748 20-08-13, 12:53 AM
آخر رد: ali.alfoly
  التعامل مع الملفات RaggiTech 0 450 17-10-12, 09:16 PM
آخر رد: RaggiTech
  التعامل مع المجلدات RaggiTech 0 399 17-10-12, 09:11 PM
آخر رد: RaggiTech
  (لعبة الذاكرة Memory Game) لتفهم التعامل مع مصفوفة الادوات RaggiTech 0 564 17-10-12, 09:05 PM
آخر رد: RaggiTech
  مثال رائع من مايكروسوفت يوضح اكواد التعامل مع الملفات و بتصميم ممتاز(80ك ب) RaggiTech 0 417 17-10-12, 07:19 PM
آخر رد: RaggiTech
  التعامل مع البرامج والتطبيقات الخارجية RaggiTech 0 401 17-10-12, 06:54 PM
آخر رد: RaggiTech
  لعمل نسخة من Class دون استعمال الكلمة new RaggiTech 0 294 17-10-12, 06:14 PM
آخر رد: RaggiTech
  لانشاء قاعده بيانات و التعامل معها من خلال الكود RaggiTech 0 518 17-10-12, 05:24 PM
آخر رد: RaggiTech
  كيفيه عمل اسطر مرقمه لل RichTextBox RaggiTech 0 263 17-10-12, 05:20 PM
آخر رد: RaggiTech

التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم