This sample demonstrates event handling in the context of opening a project. It shows how to set the parameters for opening the project, retrieve a project interface and then open the project. This example uses the IProject61 (Open) IApplication61 (ExecutablePath) and SGWorld (OnLoadFinished) interfaces.
privatevoid OpenProject()
{
string tMsg = String.Empty;
// A. Set Project "Open" Method parameters
string tAppRoot = Path.GetDirectoryName(Application.ExecutablePath);
string tProjectUrl = Path.Combine(SamplesDirectory,@"Resources\FlyFiles\simplefly.fly");
bool bIsAsync = false;
string tUser = String.Empty;
string tPassword = String.Empty;
// B. Instantiate Terra Explorer Globe and retrieve Project Interface
try
{
SGWorld61 sgworld = new SGWorld61();
// C. Register to OnLoadFinished globe event
sgworld.OnLoadFinished += new _ISGWorld61Events_OnLoadFinishedEventHandler(OnProjectLoadFinished);
// D. Open Project in synchronous mode
sgworld.Project.Open(tProjectUrl, bIsAsync, tUser, tPassword);
MessageBox.Show("Opening project " + tProjectUrl + " in async mode");
}
catch (Exception ex)
{
tMsg = String.Format("OpenProjectButton_Click Exception: {0}", ex.Message);
MessageBox.Show(tMsg);
}
}
void OnProjectLoadFinished()
{
string tMsg = String.Empty;
try
{
// OnLoadFinished event Received
MessageBox.Show("Received project loaded event");
}
catch (Exception ex)
{
tMsg = String.Format("OnProjectLoadFinished Exception: {0}", ex.Message);
MessageBox.Show(tMsg);