| | |
[how to]Call functions of one Class from another class
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Mar 2007
Posts: 16
Reputation:
Solved Threads: 0
Hello,
I know it may be silly to ask this
but I m stuck with this: so please help
I have two classes in the same namespace
Now, what I want to do is on Form_Load Event I want to call all the functions present in the Setting_Layer_Path class
One way of doing is by creating object of the Setting_Layer_Path Class and working with the functions within it
Can someone tell me, is there any other way of calling the functions directly without creating object
Attach is the codes
Setting_Layer_Path Class
Form frmDT_selection.cs
Any help would be deeply appreciated
Thanks in advance
I know it may be silly to ask this
but I m stuck with this: so please help
I have two classes in the same namespace
•
•
•
•
1. Setting_Layers_Path class files
Which helps in establishing connection to the layers(GIS connections). It contains number of functions which return an object of specific datatype
2. Form Class
One way of doing is by creating object of the Setting_Layer_Path Class and working with the functions within it
Can someone tell me, is there any other way of calling the functions directly without creating object
Attach is the codes
Setting_Layer_Path Class
C# Syntax (Toggle Plain Text)
namespace RELGIS_DT_Load_Calculation { public sealed class Setting_Layers_Path { #region User Defined Variables IMxDocument pMxDoc; IMap pMap; #endregion public Setting_Layers_Path() { } private static IFeatureLayer get_DivsionFeatureLayer() { return null; } private static IFeatureLayer get_SubDivisionFeatureLayer() { } private static IFeatureLayer get_EHVStnFeatureLayer() { } private static IFeatureLayer get_SubStnFeatureLayer() { return CommonGISFunc.FirstFeatureLayerWithMN(pMap, "AU_SUBSTATION"); } private static IFeatureLayer get_DistributedTransformerFeatureLayer() { return CommonGISFunc.FirstFeatureLayerWithMN(pMap, "DISTRIBUTIONTRANSFORMER"); } } }
Form frmDT_selection.cs
namespace RELGIS_DT_Load_Calculation
{
public partial class frmDT_selection : Form
{
#region variable declaration
IMxDocument pMxDoc;
#endregion
public frmDT_selection(IApplication m_app)
{
InitializeComponent();
}
private void frmDT_selection_Load(object sender, EventArgs e)
{
//This is where i want to call the functions of the Setting_Layers_Path class without creating an object
}Any help would be deeply appreciated
Thanks in advance
•
•
Join Date: Feb 2008
Posts: 46
Reputation:
Solved Threads: 4
this is claa example
[/code=c#]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace DaniWebtest3
{
class time
{
public static void GetIt()
{
MessageBox.Show(DateTime.Now.ToString());
}
}
}
[/code]
so u must declar ur methode public static this means that only the class will acceses this function and u will not create instance for ur class .
read this :
http://msdn.microsoft.com/en-us/libr...s3(VS.80).aspx
bye
[/code=c#]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace DaniWebtest3
{
class time
{
public static void GetIt()
{
MessageBox.Show(DateTime.Now.ToString());
}
}
}
[/code]
so u must declar ur methode public static this means that only the class will acceses this function and u will not create instance for ur class .
read this :
http://msdn.microsoft.com/en-us/libr...s3(VS.80).aspx
bye
•
•
Join Date: Dec 2008
Posts: 15
Reputation:
Solved Threads: 1
Make the methods as Public Static.Then you can call the methods using the classname itself without creating obect.
namespace RELGIS_DT_Load_Calculation
{
public sealed class Setting_Layers_Path
{
#region User Defined Variables
IMxDocument pMxDoc;
IMap pMap;
#endregion
public Setting_Layers_Path()
{
}
public static IFeatureLayer get_DivsionFeatureLayer()
{
return null;
}
public static IFeatureLayer get_SubDivisionFeatureLayer()
{
}
public static IFeatureLayer get_EHVStnFeatureLayer()
{
}
public static IFeatureLayer get_SubStnFeatureLayer()
{
return CommonGISFunc.FirstFeatureLayerWithMN(pMap, "AU_SUBSTATION");
}
public static IFeatureLayer get_DistributedTransformerFeatureLayer()
{
return CommonGISFunc.FirstFeatureLayerWithMN(pMap, "DISTRIBUTIONTRANSFORMER");
}
}
}
namespace RELGIS_DT_Load_Calculation
{
public sealed class Setting_Layers_Path
{
#region User Defined Variables
IMxDocument pMxDoc;
IMap pMap;
#endregion
public Setting_Layers_Path()
{
}
public static IFeatureLayer get_DivsionFeatureLayer()
{
return null;
}
public static IFeatureLayer get_SubDivisionFeatureLayer()
{
}
public static IFeatureLayer get_EHVStnFeatureLayer()
{
}
public static IFeatureLayer get_SubStnFeatureLayer()
{
return CommonGISFunc.FirstFeatureLayerWithMN(pMap, "AU_SUBSTATION");
}
public static IFeatureLayer get_DistributedTransformerFeatureLayer()
{
return CommonGISFunc.FirstFeatureLayerWithMN(pMap, "DISTRIBUTIONTRANSFORMER");
}
}
}
![]() |
Similar Threads
- newbie needs assatance with breaking code into class (C++)
- python function call for a noob (Python)
- including class??? (ASP.NET)
- how to call these functions? (C#)
- Class Vectorization requirements (C++)
- help with "disabling" a button (C)
- Two-way class communication (C++)
- writing a class without the class declaration? (C++)
- Bank account class (C++)
Other Threads in the C# Forum
- Previous Thread: Pass value to another form
- Next Thread: Automatially move data
| Thread Tools | Search this Thread |
.net access ado.net algorithm array barchart bitmap box broadcast buttons c# chat check checkbox client color combobox control conversion csharp custom database datagrid datagridview dataset datetime degrees development draganddrop drawing encryption enum event excel file files form format formatting forms function gdi+ httpwebrequest image index input install java label list listbox listener mandelbrot marshalbyrefobject math mouseclick mysql networking object operator path photoshop picturebox pixelinversion post prime programming radians regex remote remoting richtextbox save saving serialization server sleep socket sql statistics stream string table tcp text textbox thread time timer treeview update usercontrol validation view visualstudio webbrowser windows winforms wpf xml






