DOBON.NET DOBON.NETプログラミング掲示板過去ログ

保存されている全ての写真を表示する方法

環境/言語:[WinXP・VisualStudio 2008 Professional]
分類:[.NET]

C#を使用して写真を整理・編集・印刷をするソフトを作成していますが、最初からつまずいています。
画面構成としては、Formに「メニューに戻る」ボタンだけがある状態で保存されています。
このFormを開いた時(Form_Load)に動的にボタンが隠れない程度に動的にPanelを配置し、そのPanel上に写真の枚数分GroupBoxを表示させます。
GroupBoxの中身は、「PictureBox」×1個、「TextBox(写真のファイル名入力用)」×1個、「CheckBox」×1個です。
現在の状況は、Panel上にGroupBoxが写真の枚数分表示されているが、GroupBoxの中身が表示されているのは1つ目のGroupBoxだけです。(写真は、配列の最初に入っているものだけ表示されています)
全てのGroupBoxの中身を表示させるには、どのようにしたらよろしいでしょうか?
どなたかご教示下さい。
よろしくお願いします。
最後に、現状のコードを提示します。



<現状のコード>

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace 写真管理システム
{
public partial class form写真選択 : Form
{
public form写真選択()
{
InitializeComponent();
}

private void button戻る_Click(object sender, EventArgs e)
{
formMenu MenuForm = new formMenu();
MenuForm.Show();
this.Hide();
}

// 各コントロールのフィールドを作成
private Panel PanelPicture; // パネルコントロール
private GroupBox[] GroupBoxPictures; // グループボックスコントロール
private PictureBox[] PictureBoxPictures; // ピクチャーボックスコントロール
private TextBox[] TextBoxFileNames; // テキストボックスコントロール
private CheckBox[] CheckBoxSelects; // チェックボックスコントロール

private void form写真選択_Load(object sender, EventArgs e)
{
int x_pos = 10, y_pos = 10, index = 0, FileCount = 0, count = 0, row = 0;
const string PicCardDirectory = "G:\\DCIM\\100CDPFP\\";
string[] CardFile = new string[5];

// "G:\DCIM\100CDPFP"以下のファイルをすべて取得
string[] Cardfiles = Directory.GetFiles(PicCardDirectory, "*", SearchOption.AllDirectories);

// ファイル数をカウントする
foreach (string CardN in Cardfiles)
{
//CardFile = CardN.Split('\\');
FileCount++;
}

// 各コントロール/コントロール配列の作成
this.PanelPicture = new Panel(); // パネルコントロール
this.GroupBoxPictures = new GroupBox[FileCount]; // グループボックスコントロール配列
this.PictureBoxPictures = new PictureBox[FileCount]; // ピクチャーボックスコントロール配列
this.TextBoxFileNames = new TextBox[FileCount]; // テキストボックスコントロール配列
this.CheckBoxSelects = new CheckBox[FileCount]; // チェックボックスコントロール配列

this.SuspendLayout();

// パネルコントロールのインスタンスを作成し、プロパティを作成する
this.PanelPicture.Controls.AddRange(GroupBoxPictures);
PanelPicture.AutoScrollMargin = new Size(10, 10);
PanelPicture.AutoScroll = true;
PanelPicture.BackColor = Color.LightGray;
PanelPicture.Location = new Point(0, 0);
PanelPicture.Size = new Size(1016, 600);
this.Controls.Add(this.PanelPicture);

for (index = 0; index < FileCount; index++)
{
CardFile = Cardfiles[index].Split('\\');

// グループボックスコントロール配列のインスタンスを作成し、プロパティを作成する
this.GroupBoxPictures[index] = new GroupBox();
this.GroupBoxPictures[index].Controls.Add(PictureBoxPictures[index]);
this.GroupBoxPictures[index].Controls.Add(TextBoxFileNames[index]);
this.GroupBoxPictures[index].Controls.Add(CheckBoxSelects[index]);
this.GroupBoxPictures[index].BackColor = Color.White;
this.GroupBoxPictures[index].Font = new Font("MS Pゴシック", 12F, FontStyle.Bold, GraphicsUnit.Point, ((byte)(128)));
this.GroupBoxPictures[index].Size = new Size(240, 200);
this.GroupBoxPictures[index].Location = new Point(x_pos, y_pos);
this.GroupBoxPictures[index].Text = "Picture" + Convert.ToString(index + 1);
this.GroupBoxPictures[index].Name = "GroupBoxPicture" + Convert.ToString(index + 1);
PanelPicture.Controls.Add(GroupBoxPictures[index]);

// ピクチャーボックスコントロール配列のインスタンスを作成し、プロパティを作成する
this.PictureBoxPictures[index] = new PictureBox();
this.PictureBoxPictures[index].BorderStyle = BorderStyle.Fixed3D;
this.PictureBoxPictures[index].BackgroundImage = Image.FromFile(Cardfiles[index]);
this.PictureBoxPictures[index].Size = new Size(200, 130);
this.PictureBoxPictures[index].SizeMode = PictureBoxSizeMode.StretchImage;
this.PictureBoxPictures[index].Location = new Point(x_pos + 10, y_pos + 10);
this.PictureBoxPictures[index].BackgroundImageLayout = ImageLayout.Stretch;
this.PictureBoxPictures[index].Name = "PictureBoxPicture" + Convert.ToString(index + 1);
GroupBoxPictures[index].Controls.Add(PictureBoxPictures[index]);

// テキストボックスコントロール配列のインスタンスを作成し、プロパティを作成する
this.TextBoxFileNames[index] = new TextBox();
this.TextBoxFileNames[index].BackColor = Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(192)))), ((int)(((byte)(192)))));
this.TextBoxFileNames[index].Font = new Font("MS Pゴシック", 12F, FontStyle.Regular, GraphicsUnit.Point, ((byte)(128)));
this.TextBoxFileNames[index].Location = new Point(x_pos + 10, y_pos + 150);
this.TextBoxFileNames[index].Size = new Size(150, 51);
this.TextBoxFileNames[index].Text = CardFile[3];
this.TextBoxFileNames[index].TextAlign = HorizontalAlignment.Center;
this.TextBoxFileNames[index].Name = "TextBoxFileName" + Convert.ToString(index + 1);
GroupBoxPictures[index].Controls.Add(TextBoxFileNames[index]);

// チェックボックスコントロール配列のインスタンスを作成し、プロパティを作成する
this.CheckBoxSelects[index] = new CheckBox();
this.CheckBoxSelects[index].AutoSize = true;
this.CheckBoxSelects[index].Location = new Point(x_pos + 178, y_pos + 155);
this.CheckBoxSelects[index].Size = new Size(80, 16);
this.CheckBoxSelects[index].UseVisualStyleBackColor = true;
this.CheckBoxSelects[index].Name = "CheckBoxSelect" + Convert.ToString(index + 1);
GroupBoxPictures[index].Controls.Add(CheckBoxSelects[index]);

x_pos += 246;
count++;

if (count > 3)
{
count = 0;
x_pos = 10;
++row;
y_pos = row * 210 + 10;
}
}
this.ResumeLayout(false);
}
}
}
■No25791に返信(はっちゃんさんの記事)

  マルチポスト
  http://bbs.wankuma.com/index.cgi?mode=al2&namber=43573

DOBON.NET | プログラミング道 | プログラミング掲示板