0

I'm facing this problem (i'll make it short and easy) In form1 i need to create an instance of Login form and be able to access it in the class abc and use it's(login's) method.However, it appears to be inaccessible.

I hope i said all the relevant in an understandable.

Thanks in advance

Releis
  • 27
  • 1
  • 5

2 Answers2

1

If you're calling actual functionality belonging to another form explicitly, it is possibly time to look at your design. You should probably have a class or assembly dealing with authentication which is decoupled from any form. Use it in both your login form and class ABC.

Jeff Watkins
  • 6,343
  • 16
  • 19
1

Fundamentally to do exactly what you ask, you need to provide an instance of Login to abc, for example by passing it in through the abc constructor.

You may wish to consider refactoring some of the functionality currently in Login form to make it useful in all places it's needed.

I suggest having a look at the MVC pattern. While WPF, Silverlight and ASP.Net MVC provide strong support for that pattern, you can certainly apply it in a WinForms scenario as well.

Using a pattern like MVC will make your code far easier to evolve and maintain over time.

Community
  • 1
  • 1
Eric J.
  • 147,927
  • 63
  • 340
  • 553