I have some code that some one help me with. Its just that theres a new part that I added to my software. And the code I have doesn't want to work right.
What I'm trying to do is, I have whats called a Terrain. The Terrain has 3 parts (Images) A color image. B&W image and a 3D image.
C = Color
D = 3d
H = B&W
I have a 3 buttons that says C H D. What I want to do is scroll threw the color images and when I come to a Terrain that I want to view the D and H images. I just click the D and H buttons.
The problem is that they roll back one (1) or two (2) images, So you not really viewing the right image.
The code I have is below. I tried to explain this as best as I can.
VC# 2008 in NET 3.5.
I have a textbox1 that displays the file name. with a C D H buttons and a Next and Prev Bottons on one (1) form.
Code:
public partial class Terrain : Form
{
public Terrain()
{
InitializeComponent();
}
public List<string> list;
public int count;
public int index = 0;
private void Terrain_Load(object sender, EventArgs e)
{
string[] fl = Directory.GetFiles(@"images\ViewC\");
list = new List<string>();
foreach (string str in fl)
{
if (str.EndsWith(".jpg"))
{
list.Add(str);
}
}
count = list.Count;
if (count != 0)
{
this.pictureBox1.ImageLocation = list[0];
index = 0;
textBox1.Text = list[0];
}
}
private void btnC_Click(object sender, EventArgs e)
{
string[] fl = Directory.GetFiles(@"images\ViewC\");
list = new List<string>();
foreach (string str in fl)
{
if (str.EndsWith(".jpg"))
{
list.Add(str);
}
}
count = list.Count;
if (count != 0)
{
this.pictureBox1.ImageLocation = list[0];
index = 0;
}
}
private void btnNext_Click(object sender, EventArgs e)
{
if (count > 1)
{
if (index == 0)
{
index = count - 1;
}
else
{
index--;
}
}
this.pictureBox1.ImageLocation = list[index];
//textBox1.Text =
textBox1.Text = list[index];
}
private void btnPrev_Click(object sender, EventArgs e)
{
if (count > 1)
{
if (index == count - 1)
{
index = 0;
}
else
{
index++;
}
}
this.pictureBox1.ImageLocation = list[index];
//textBox1.Text =
textBox1.Text = list[index];
}
private void btnD_Click(object sender, EventArgs e)
{
string[] fl = Directory.GetFiles(@"images\ViewD\");
list = new List<string>();
foreach (string str in fl)
{
if (str.EndsWith(".jpg"))
{
list.Add(str);
}
}
count = list.Count;
if (count != 0)
{
this.pictureBox1.ImageLocation = list[0];
index = 0;
}
}
private void btnH_Click(object sender, EventArgs e)
{
string[] fl = Directory.GetFiles(@"images\ViewH\");
list = new List<string>();
foreach (string str in fl)
{
if (str.EndsWith(".jpg"))
{
list.Add(str);
}
}
count = list.Count;
if (count != 0)
{
this.pictureBox1.ImageLocation = list[0];
index = 0;
}
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
}
Just what I said. When you see a color image that your like. I wanted to add 2 More images. 1 is a black and white image and a 3D image. from the same color Image. When I click in the H or D buttons the code seems to reset it self to the next or prev image. So you not really looking at the right image.
What happens when you step through the code in a debugger? Have you tried using Debug.Write statements to log the index value to the Output window when you click the various buttons?
A couple of suggestions...
Rather than just allocate a new list each time you populate it, I recommend that you call list.Clear( ). In fact, you have a lot of redundant code, so why don't you clean that up by creating some helper methods? Lastly, may I suggest that you prefix your class field names with an underscore (i.e. '_')? It makes it easier to determine if it's a class field or a method variable.
Well If I under stand you right. More then likely I don't Thats not what I'm trying to do.
Ok, I have a terrain called "DBF1"
The terrain has 3 files (images) for just this one (1) terrain.
C, D and H.
The C = the color terrain
The D = The 3D terrain
and
the H = Is Black and white image of the terrain.
I have it setup so that it scrolls thew the color (C) terrains. What I want to do is when the file name of the current terrain is in the textbox1 is that I have 2 buttons. One called H and one called D. When I click on one if the buttons. It displays that image from that terrain.
Sorry I have no other way of explaining this so you can under stand
Well If I under stand you right. More then likely I don't Thats not what I'm trying to do.
What my code did is remove your redundant code. If what you had code wasn't close to what you need, then obviously my code isn't code to help.
Also, I think we've been through this before, but please answer the questions that I or anyone else ask when replying to your posts.
I've asked two questions that you haven't answered:
What happens when you step through the code in a debugger? Have you tried using Debug.Write statements to log the index value to the Output window when you click the various buttons?
I have another question for you. Are the terrain files named the same in each of the terrain directories? In other words, there are 3 files name "DBF1[.jpg]" in each of the C, D, and H directories. Is this correct?
What my code did is remove your redundant code. If what you had code wasn't close to what you need, then obviously my code isn't code to help.
Also, I think we've been through this before, but please answer the questions that I or anyone else ask when replying to your posts.
I've asked two questions that you haven't answered:
I have another question for you. Are the terrain files named the same in each of the terrain directories? In other words, there are 3 files name "DBF1[.jpg]" in each of the C, D, and H directories. Is this correct?
That's what I thought. Ok, Debugger won't tell me how to write code. So since the program doesn't crash or error out. I don't see how that will help.
I have it setup so that it writes a index
[list] or a list[0] to textbox1. You should see that in my code.
textBox1.Text = list[0];
The code above is what I'm using now. Well all I'm trying to do is find out how I can get the current file name from this and use that
the Output window when you click the various buttons? I have another question for you. Are the terrain files named the same in each of the terrain directories? In other words, there are 3 files name "DBF1[.jpg]" in each of the C, D, and H directories. Is this correct? Today 12:45 PM
Yes. and No. The Color terrains are in same folder called terrains. and each color terrain has 2 files related to it. So that makes 3 files for each terrain. I have each D and H images in a terrains/DBF1/DBF1.jpg folder. Each folder has only 2 images in it. The D and H images.
I don't think I explain my last post. I attached a image of the folders and what I have in each one.
I have it setup to view the color terrains with no problem. When I have a color terrain selected in the textbox1. I want to view the other 2 images related to the color terrain
As far as the earlier debugging questions. Please answer the questions even if you don't think it's applicable. Debugging can be useful even if a program doesn't crash. You can take a look at the values in the program to see why the wrong image is being displayed.
At any rate, what I am trying to understand is the relationship between the files (if there is one).
I understand that there is a folder that contains the 'C' files and there are two child folders that contain the 'D' and 'H' files.
Can you list the files in each folder?
For example:
Code:
\Terrain folder>
DFB3.JPG
DFD1.JPG
DFD2.JPG
DFD3.JPG
DFD4.JPG
DFG1.JPG
DFG3.JPG
DFG4.JPG
DFG6.JPG
DGM1.JPG
L Dfolder
What files are here?
L Hfolder
What files are here?
Last edited by Arjay; July 19th, 2009 at 08:31 PM.
As far as the earlier debugging questions. Please answer the questions even if you don't think it's applicable. Debugging can be useful even if a program doesn't crash. You can take a look at the values in the program to see why the wrong image is being displayed.
At any rate, what I am trying to understand is the relationship between the files (if there is one).
I understand that there is a folder that contains the 'C' files and there are two child folders that contain the 'D' and 'H' files.
Can you list the files in each folder?
For example:
Code:
root folder
L Dfolder
What files are here?
L Hfolder
What files are here?
DFB3.JPG
DFD1.JPG
DFD2.JPG
DFD3.JPG
DFD4.JPG
DFG1.JPG
DFG3.JPG
DFG4.JPG
DFG6.JPG
DGM1.JPG
Only in the terrain folder. That's where the code from my 1st post comes from. It lets me view the color terrains. and in the folders.
ViewH and ViewD Theres one (1) image is each folder that relates to one (1) image in the terrain folder.
maybe this mite help
/terrain
DGM1.JPG // color image of teerain
/terrain/viewH
DGM1.JPG // 3D image of the color terrian
/terain/ViewD
DGM1.JPG //Black and white image of the color terrain
I can view the color images for the terrains just fine.
I'm trying to think of a way to view the other images too.
that relate to the color image.
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.