Click here to Skip to main content
15,892,965 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi there.. i have problems on creating a sub on a class and calling it on the other form.. this is a sample on a class that i have created,

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WindowsFormsApplication1
{
    class Class1
    {
        public void sample_sub()
        {
            //this is a sample sub
        }
    }
}


and whenever i call the sub on a form.. for example form1., if i type in the sub that i have created, the name of the sub wont appear.. is there any solution for this? sorry for my bad english..
Posted

Please make your class public
public class Class1
{
...
}
 
Share this answer
 
Comments
lalar18 4-Jun-13 2:40am    
thanks.. i have tried it.. but still the name of the sub doesn't seem to appear on the other form.. :(.. is there other solution for it?
Sergey Alexandrovich Kryukov 4-Jun-13 2:59am    
Sorry, no. It's enough to make the class internal. It's a good idea to give as little access as possible.
—SA
lalar18 4-Jun-13 4:32am    
but is that posible to access class code on the form? like for example on vb.net on a module.. all you have to put is just this codes..

Module Module1
Public Sub sample_sub()
'this is a sample sub
End Sub
End Module

and you can just simply call the sub on whenever form you use, for example "call sample_sub()".. is it posible on c# .net?
You are not yet prepared to ask productive questions here. You should first read about the basics. If this can provide you with some hints, look here:
C#
internal class SomeClass {
    internal static void StaticMethod() {/* ... */}
    internal void InstanceMethod() {
        this.A = 5; // you can only do it in instance methods
        // same as
        A = 5; // but "this" can resolve name conflict and important 
               // for understanding of what's going on; see also below
    }
    //...
    int A;
}

// ...

SomeClass.StaticMethod();

someInstance SomeClass = new SomeClass();
someInstance.InstanceMethod(); // the reference "someInstance" becomes "this" passed to the method
                               // as an implicit parameter, see above


—SA
 
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