Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi

 

I'm having problem getting a class to be referenced from several forms.

 

The class in question is a simple class to log output to a file. So at any point i can write

 

LogEvent("12 rows were returned")

 

and this will be written out to a log file. I would like to instigate the class when the main screen loads and have every other form call this class with just using the above code. Can someone please tell me how i can do this?

 

Thanks

 

Jay

  • *Experts*
Posted

You could build the log class using static methods if you only need one log application wide. Then you would be able to access it like you want:

ClassName.LogEvent("Hello World")

Posted

option/idea 1. Make it a static class with a LogEvent(string) method?

 

option/idea 2. Initialize the Logger class in your main form (with a file name, etc) and pass it to each of the classes that might use it.

 

option/idea 3. Do the same as 2, but pass a delegate to the LogEven(string) method instead of the Logger Class.

Posted

Thanks guys. I've finally got my head around sharing classes. Or at least i think i have.

 

I'm going to be using one of two methods.

 

1) For classes such as the LogEvent one, which will be accessed from all frames, i'll use shared

2) For classed which will just be used between 2 frames, i'll pass the instance of the class between the two frames.

 

Thanks

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...