Click here to Skip to main content
15,894,142 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello,

I am writing a software application that I want to update the Status Strips Label with a value passed from one function(class) to another. The problem is the new function does not recognize the tool strip as an object. Is there anyway around this issue?
Posted
Comments
George Jonsson 11-Jul-14 11:15am    
Really?
I'm not sure how you expect anyone to help you with the information you provide.
Please improve the question.
Retro617 11-Jul-14 12:02pm    
Thank you George. You are right my question was terribly vague. So this is what I want to do, I am creating a back up program. I found the only way to get the file names from all the sub directories was to create a function call to my ShowAllFolders(). Inside of that I created a queue so that I do not have to wait forever for the files to be searched. A basic in and out if you will.

At this point I want to show the file names being queued in my status strip label(which I have created). Unfortunately, the status strip is not available to write to, I will put the threee functions I want to work together with here:


private void backgroundWorker2_DoWork(object sender, DoWorkEventArgs e)
{
// System.Threading.Thread.Sleep(60000);

foreach(string s in Directory.GetLogicalDrives())
{
ShowAllFoldersUnder(s, 0);
}

}

public static void ShowAllFoldersUnder(string path, int indent)
{
workingFolder localWorkingFolder;

Queue folderListQueue = new Queue();
int keyCounter = 0;
try
{
foreach (string folder in Directory.GetDirectories(path))
{
localWorkingFolder.completeWorkingPath = folder;
folderListQueue.Enqueue(localWorkingFolder);
Console.WriteLine("Count of Items in the Queue: " + folderListQueue.Count);
Console.WriteLine("{0}{1}", new string(' ', indent), Path.GetFullPath(folder));
localWorkingFolder = (workingFolder)folderListQueue.Dequeue();
string PathToSearch = localWorkingFolder.completeWorkingPath;
//Console.WriteLine(localWorkingFolder);
try
{ foreach(string f in Directory.GetFiles(PathToSearch,"*.*"))
{
UpdateStatus(f);
Console.WriteLine(f);
}
}
catch (System.Exception excpt)
{
Console.WriteLine(excpt.Message);
}


ShowAllFoldersUnder(folder, +2);
keyCounter++;
}
}
catch (UnauthorizedAccessException) { }
Console.WriteLine("There were " + keyCounter + " files to be searched");
}

public static void UpdateStatus(string fileSearched)
{
string updatedFile = fileSearched;
//MessageBox.Show(updatedFile);
return;


}Thank you George. You are right my question was terribly vague. So this is what I want to do, I am creating a back up program. I found the only way to get the file names from all the sub directories was to create a function call to my ShowAllFolders(). Inside of that I created a queue so that I do not have to wait forever for the files to be searched. A basic in and out if you will.

At this point I want to show the file names being queued in my status strip label(which I have created). Unfortunately, the status strip is not available to write to, I will put the threee functions I want to work together with here:


private void backgroundWorker2_DoWork(object sender, DoWorkEventArgs e)
{
// System.Threading.Thread.Sleep(60000);

foreach(string s in Directory.GetLogicalDrives())
{
ShowAllFoldersUnder(s, 0);
}

}

public static void ShowAllFoldersUnder(string path, int indent)
{
workingFolder localWorkingFolder;

Queue folderListQueue = new Queue();
int keyCounter = 0;
try
{
foreach (string folder
CHill60 11-Jul-14 11:41am    
Post the code in the function, tell us where that function is. I suspect it's out of scope.
Retro617 11-Jul-14 12:02pm    
Thank you George. You are right my question was terribly vague. So this is what I want to do, I am creating a back up program. I found the only way to get the file names from all the sub directories was to create a function call to my ShowAllFolders(). Inside of that I created a queue so that I do not have to wait forever for the files to be searched. A basic in and out if you will.

At this point I want to show the file names being queued in my status strip label(which I have created). Unfortunately, the status strip is not available to write to, I will put the threee functions I want to work together with here:


private void backgroundWorker2_DoWork(object sender, DoWorkEventArgs e)
{
// System.Threading.Thread.Sleep(60000);

foreach(string s in Directory.GetLogicalDrives())
{
ShowAllFoldersUnder(s, 0);
}

}

public static void ShowAllFoldersUnder(string path, int indent)
{
workingFolder localWorkingFolder;

Queue folderListQueue = new Queue();
int keyCounter = 0;
try
{
foreach (string folder in Directory.GetDirectories(path))
{
localWorkingFolder.completeWorkingPath = folder;
folderListQueue.Enqueue(localWorkingFolder);
Console.WriteLine("Count of Items in the Queue: " + folderListQueue.Count);
Console.WriteLine("{0}{1}", new string(' ', indent), Path.GetFullPath(folder));
localWorkingFolder = (workingFolder)folderListQueue.Dequeue();
string PathToSearch = localWorkingFolder.completeWorkingPath;
//Console.WriteLine(localWorkingFolder);
try
{ foreach(string f in Directory.GetFiles(PathToSearch,"*.*"))
{
UpdateStatus(f);
Console.WriteLine(f);
}
}
catch (System.Exception excpt)
{
Console.WriteLine(excpt.Message);
}


ShowAllFoldersUnder(folder, +2);
keyCounter++;
}
}
catch (UnauthorizedAccessException) { }
Console.WriteLine("There were " + keyCounter + " files to be searched");
}

public static void UpdateStatus(string fileSearched)
{
string updatedFile = fileSearched;
//MessageBox.Show(updatedFile);
return;


}

1 solution

Let me see if I've got what you are trying to do:
You have two classes, one called Class1 and the Class2.
Class1 contains a StatusStripLabel.
Class1 calls a function in Class2:
C#
Class2 c2 = new Class2();
c2.Method(666);

From the instance of Class2, you want to update the the label in Class1.

You can't access anything from Class1 in Class2 unless it is public (assuming Class2 is not derived from Class1), and even if it was, you would need the actual instance of Class1 to be sure of getting the right control within the displayed instance - creating a new one will not work.

If you have to do this, then it's likely that you should read this: Transferring information between two forms, Part 2: Child to Parent[^] - it's based around doing everything in Forms, but the same technique works for all classes.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900