Question Array of string path

steve15

New member
Joined
Feb 22, 2016
Messages
1
Programming Experience
Beginner
Hello,

I have a winform Form18News.cs with 18 PictureBox to fill with pictures.

In my MainForm.cs i create a class GenerateNews :

1public static class GenerateNews
2 {
3 public static string[] filesArray = Directory.GetFiles(@"\\mydomain.net\mycompany\myfolder\mysubfolder", "*.*", SearchOption.AllDirectories);
4 }

I send in a array filesArray all results of my GetFiles.

Then, in a class News.cs (separated file) i instance 1 variable for one news (picturebox) :

01public static string strInfo1 = MainForm.GenerateNews.filesArray[0];

02 public static string strInfo2 = MainForm.GenerateNews.filesArray[1];

03 public static string strInfo3 = MainForm.GenerateNews.filesArray[2];

04 public static string strInfo4 = MainForm.GenerateNews.filesArray[3];

05 public static string strInfo5 = MainForm.GenerateNews.filesArray[4];

06 public static string strInfo6 = MainForm.GenerateNews.filesArray[5];

07 public static string strInfo7 = MainForm.GenerateNews.filesArray[6];

08 public static string strInfo8 = MainForm.GenerateNews.filesArray[7];

09 public static string strInfo9 = MainForm.GenerateNews.filesArray[8];

10 public static string strInfo10 = MainForm.GenerateNews.filesArray[9];

11 public static string strInfo11 = MainForm.GenerateNews.filesArray[10];

12 public static string strInfo12 = MainForm.GenerateNews.filesArray[11];

13 public static string strInfo13 = MainForm.GenerateNews.filesArray[12];

14 public static string strInfo14 = MainForm.GenerateNews.filesArray[13];

15 public static string strInfo15 = MainForm.GenerateNews.filesArray[14];

16 public static string strInfo16 = MainForm.GenerateNews.filesArray[15];

17 public static string strInfo17 = MainForm.GenerateNews.filesArray[16];

18 public static string strInfo18 = MainForm.GenerateNews.filesArray[17];


Then in my second winform Form18News.cs in stance my 18 PictureBox :

01try

02 {

03 pbxL1C1.ImageLocation = News.strInfo1;

04 }

05 catch

06 {

07 pbxL1C1.Image = null;

08 }

09 pbxL1C1.BackColor = Color.White;

10 pbxL1C1.SizeMode = PictureBoxSizeMode.Zoom;

11 pbxL1C1.Width = iWidthBlock;

12 pbxL1C1.Height = iHeightBlock;

13 pbxL1C1.Top = iHeightBlock / iHeightBlock;

14 pbxL1C1.Left = iWidthBlock / iWidthBlock;

15

16IDEM FOR pbxL1C2, pbxL1C3...


I attribute the imagelocation of picturebox with my class variables News.cs

Problem :
- I need a count of my news, return my number of picture in my folder (12 news, 15 news...)
- If i have less than 18 news, all picturebox are white
- My getdirectory return also files thumbs.db and try to display this, i have a red cross in pbx.
- In my MainForm.cs i have a timer for close Form18News and open this about X time, for update display with the new pictures or delete, i will execute code of classe News.cs for assign path of files in string array.

Thank you for your help and i'm sorry for my bad english
 
Last edited:
You have made your code very hard to read. Please repost it like this:

[xcode=c#]your code here[/xcode]

Copy the code directly from your IDE if you can and paste it as plain text. That way you'll get syntax highlighting and, most importantly, indenting will be maintained. That is the most important factor for readability.
 
Back
Top Bottom