我有一个包含项目的列表框,我需要图片框来根据列表框中的选择更改图像。
列表框由Binding source display member填充。
using System.IO;
namespace CapstoneProject
{
public partial class capstoneProjectForm : Form
{
string picName;
public capstoneProjectForm()
{
InitializeComponent();
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
//string[] a = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceNames();
string resFolder = System.IO.Path.Combine(System.Windows.Forms.Application.StartupPath, "Resources");
foreach (string s in Directory.EnumerateFiles(resFolder, "*.jpg"))
{
using (Bitmap bmp = new Bitmap(s))
{
dictionaryDataSet1.Tables[0].Rows.Add("Some caption about" + Path.GetFileName(s), s);
}
}
////foreach(string pic in a){
// MessageBox.Show(pic);
//}
// listBox.SelectedItem.ToString() =
// pictureBox.Image = CapstoneProject.Properties.Resources.batchat;
// string dir = System.AppDomain.CurrentDomain.BaseDirectory;
// string imagePath = Path.GetDirectoryName(dir);
// pictureBox.Image =
}
private void textBox_TextChanged(object sender, EventArgs e) {
}
private void btnAddWord_Click(object sender, EventArgs e)
{
Form addWord = new addWord();
addWord.ShowDialog();
}
private void btnEditWord_Click(object sender, EventArgs e)
{
Form editWord = new editWord(listBox.SelectedIndex);
editWord.ShowDialog();
this.tableAdapterManager.UpdateAll(this.dictionaryDataSet1);
}
private void btnDeleteWord_Click(object sender, EventArgs e)
{
DialogResult dr = MessageBox.Show("Are you sure you want to delete the selected Word?","Delete Word", MessageBoxButtons.YesNo);
if (dr == DialogResult.Yes)
{
this.dictionaryBindingSource.RemoveCurrent();
this.Validate();
this.dictionaryBindingSource.EndEdit();
this.tableAdapterManager.UpdateAll(this.dictionaryDataSet1);
}
}
private void capstoneProjectForm_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'dictionaryDataSet1.Dictionary' table. You can move, or remove it, as needed.
this.dictionaryTableAdapter.Fill(this.dictionaryDataSet1.Dictionary);
picName = (dictionaryDataSet1.Tables[0].Rows[listBox.SelectedIndex]["Image Name"].ToString());
}
private void listBox_SelectedIndexChanged_1(object sender, EventArgs e)
{
string description = (dictionaryDataSet1.Tables[0].Rows[listBox.SelectedIndex]["Description"].ToString());
textBox.Text = description;
}
private void pictureBox_Click(object sender, EventArgs e)
{
}
}
}