Right now my current method of doing this is to have a listbox with the names of the tiles listed and when the listBox_SelectedIndexChanged() method is called, I set one PictureBox to display the image. Here is some code so that hopefully this will make more sense.
private void textureListBox_SelectedIndexChanged(object sender, EventArgs e)
{
if (textureListBox.SelectedItem != null)
{
texturePreviewBox1.Image = previewDict[textureListBox.SelectedItem as string];
}
}
The previewDict[] is a simple dictionary with <string, Image> for the <key, value>. Whenever I add a texture to the editor, I run this code for the previewDict[].
private void addTextureButton_Click(object sender, EventArgs e)
{
openFileDialog1.Filter = "PNG Image|*.png|JPG Image|*.jpg|TGA Image|*.tga";
openFileDialog1.InitialDirectory = contentPathTextBox.Text;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
string filename = openFileDialog1.FileName;
Texture2D texture = Texture2D.FromStream(GraphicsDevice, File.OpenRead(filename));
Image image = Image.FromFile(filename);
filename = filename.Replace(contentPathTextBox.Text + "\\", "");
filename = filename.Remove(filename.LastIndexOf("."));
textureListBox.Items.Add(filename);
textureDict.Add(filename, texture);
previewDict.Add(filename, image);
// THIS IS MY CURRENT TEST CODE TO GET A PICTURE BOX DYNAMICALLY
// CREATED ON THE FORM
PictureBox box = new PictureBox();
box.Image = image;
box.BorderStyle = BorderStyle.Fixed3D;
box.Location = new System.Drawing.Point(6, 6);
box.Width = Engine.TileWidth;
box.Height = Engine.TileHeight;
tileTab.Controls.Add(box);
}
}
As you can see, I'm using a textureDict and a previewDict for each image. Until now they have been completely separate things because I only had one PictureBox for the previewImage and the method of texture selection was based on choosing an item in the listBox. My goal is to change the method of texture selection to simply having a grid of loaded textures (PictureBoxes with the image of the texture) and the image that I click on is the image I currently have selected to draw with.
Does anyone have a suggestion on how to do this? I've spent way too much time on this lately and I would like for this feature to be done so I can get back to the engine for the game.
Thanks guys!

New Topic/Question
Reply




MultiQuote








|