 |
|
VB.NET นำรูปที่มีอยู่ในโฟลเดอร์ทั้งหมด มาแสดงบนหน้าจอ ครับ |
|
 |
|
|
 |
 |
|
     
|
 |
 |
 |
 |
Date :
2015-07-15 11:37:41 |
By :
golfgee12 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (VB.NET)
Directory.CreateDirectory("My Documents\test")
Dim dir As New DirectoryInfo("My Documents\test")
Dim files As FileInfo() = dir.GetFiles("*.jpg")
For Each file As FileInfo In files
ListView.Items.Add(file)
Next
อ่านลงได้แล้วลงเอา DataSource แล้วค่อยไปแสดงผลอีกทีครับ
|
 |
 |
 |
 |
Date :
2015-07-15 13:34:40 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (C#)
private void LoopImageCE()
{
string[] filePaths = Directory.GetFiles(@"\Program Files\SmartDeviceProject4\Image");
PictureBox[] PictureBox = new PictureBox[filePaths.Length];
CheckBox[] CheckBox = new CheckBox[filePaths.Length];
int begin = 0;
int beginChk = 0;
for (int i = 0; i < filePaths.Length; i++)
{
PictureBox[i] = new System.Windows.Forms.PictureBox();
PictureBox[i].BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(128)))), ((int)(((byte)(192)))), ((int)(((byte)(255)))));
PictureBox[i].Location = new System.Drawing.Point(begin, 0);
PictureBox[i].Name = "pictureBox1";
PictureBox[i].Size = new System.Drawing.Size(75, 55);
PictureBox[i].SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
this.Controls.Add(PictureBox[i]);
begin += 85;
CheckBox[i] = new System.Windows.Forms.CheckBox();
CheckBox[i].Location = new System.Drawing.Point(beginChk, 60);
CheckBox[i].Name = "checkBox1";
CheckBox[i].Size = new System.Drawing.Size(20, 20);
CheckBox[i].TabIndex = 3+i;
this.Controls.Add(CheckBox[i]);
beginChk += 85;
}
int c = 0;
foreach (string Path in filePaths)
{
Image myImage = new Bitmap(Path);
PictureBox[c].Image = myImage;
c++;
}
}
ลองดูตามตัวอย่างที่ผมเขียนใฝห้นี้ครับ แต่อย่าลืมเอารูปไปวางในตัว Device ด้วยนะครับ ถ้างั้นมันจะมองไม่เห็น
|
 |
 |
 |
 |
Date :
2015-07-15 15:54:28 |
By :
Thaidevelopment.NET |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
น้องเรียกใช้ Function หรือยังครับ ถ้าไม่เรียกใช้ มันคงไม่ออกนะคัรบ ต้องเขียนปุ่ม หรือ Even สักตัวเรียกใช้มันก่อน
รู้สึกว่า PictureBox1(i) = New System.Windows.Forms.PictureBox() ตรงนี้จะเขียนผิดด้วยนะ ไม่มี 1 นะครับ
รูปภาพด้านล่าง จากโค้ดที่น้องแปลงครับ

|
 |
 |
 |
 |
Date :
2015-07-15 21:21:47 |
By :
Thaidevelopment.NET |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
มีครับ Me.Controls.Add(CheckBox(i)) เปลี่ยนจากตรงนี้ เป็น Add เข้า Panel แทน
|
 |
 |
 |
 |
Date :
2015-07-16 08:39:58 |
By :
Thaidevelopment.NET |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ที่ผมหมายถึง ไม่ได้ให้สรา้ง Panel ขึ้นมาเองนะคัรบ ให้ลากเอามาวางตามตำแหน่งที่ต้องการนั่นแลหะ แล้ว Add Control ลง panel เช่น
panel1.Controls.Add(PictureBox(i));
|
 |
 |
 |
 |
Date :
2015-07-16 09:27:24 |
By :
Thaidevelopment.NET |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|