HighTechTalks DotNet Forums  

Trap a build start event from designer

Dotnet Framework (WinForms DesignTime) microsoft.public.dotnet.framework.windowsforms.designtime


Discuss Trap a build start event from designer in the Dotnet Framework (WinForms DesignTime) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #11  
Old   
Linda Liu [MSFT]
 
Posts: n/a

Default Re: Trap a build start event from designer - 10-08-2007 , 06:11 AM






Hi Boris,

I did some research on the EnvDTE.

I tried to get the current VS IDE instance and subscribe the OnBuildBegin
event in a derived control designer. But when I add the custom control onto
a form, I get an exception, which is about COM interop.

In my opinion, EnvDTE is usually used in developing VS IDE add-ins and is
not intended to be used in a custom designer.

If your original problem is still not solved, I'm still willing to have a
look at the code of your custom designer.

Sincerely,
Linda Liu
Microsoft Online Community Support


Reply With Quote
  #12  
Old   
Linda Liu[MSFT]
 
Posts: n/a

Default Re: Trap a build start event from designer - 10-12-2007 , 04:31 AM






Hi Boris,

After doing more research on EnvDTE, I manage to get the current running VS
IDE instance in a custom designer and get notified when the build starts.
Please ignore my previous reply about EnvDTE.

The following are the steps of my test.

1. Create a Visual C++ CLR Windows Forms Control Library project.
2. Add references to EnvDTE, EnvDTE80 and System.Design assemblies in this
project.
3. Add the following code in the custom UserControl.h file:

using namespace EnvDTE;
using namespace EnvDTE80;
namespace CControl {

public ref class MyDesigner:
System::Windows::Forms:esign::ControlDesigner
{
public:
virtual void Initialize(System::ComponentModel::IComponent^ component)
override
{
ControlDesigner::Initialize(component);
DTE2^ dte2;
dte2 =
(DTE2^)System::Runtime::InteropServices::Marshal:: GetActiveObject("VisualStu
dio.DTE.8.0");
dte2->Events->BuildEvents->OnBuildBegin += gcnew
_dispBuildEvents_OnBuildBeginEventHandler(this,&My Designer::BuildEvents_OnBu
ildBegin);

}

void BuildEvents_OnBuildBegin(vsBuildScope Scope, vsBuildAction Action)
{
System::Windows::Forms::MessageBox::Show("Build Starts...");
}

};

[Designer(CControl::MyDesigner::typeid)]
public ref class CControlControl : System::Windows::Forms::UserControl
{
....
};
}

4. Build the project.
5. Add a new Visual C++ CLR Windows Forms Application project in the same
solution and drag the custom UserControl from the Toolbox onto the form in
the WinForm application project.
6. Build the solution. A messge box saying "Build Starts..." pops up.

Please try it on your side to see if it works and let me know the result.

Sincerely,
Linda Liu
Microsoft Online Community Support


Reply With Quote
  #13  
Old   
bmelt
 
Posts: n/a

Default Re: Trap a build start event from designer - 10-15-2007 , 11:16 AM



Hi Linda,
Thank you for confirmation DTE works for this purpose.
I managed to get my control working either with GetActiveObject or
DTE ^dte = (DTE^)GetService(DTE::typeid); (this looks like a more stright
way).

Best regards,

Boris


"Linda Liu[MSFT]" wrote:

Quote:
Hi Boris,

After doing more research on EnvDTE, I manage to get the current running VS
IDE instance in a custom designer and get notified when the build starts.
Please ignore my previous reply about EnvDTE.

The following are the steps of my test.

1. Create a Visual C++ CLR Windows Forms Control Library project.
2. Add references to EnvDTE, EnvDTE80 and System.Design assemblies in this
project.
3. Add the following code in the custom UserControl.h file:

using namespace EnvDTE;
using namespace EnvDTE80;
namespace CControl {

public ref class MyDesigner:
System::Windows::Forms:esign::ControlDesigner
{
public:
virtual void Initialize(System::ComponentModel::IComponent^ component)
override
{
ControlDesigner::Initialize(component);
DTE2^ dte2;
dte2 =
(DTE2^)System::Runtime::InteropServices::Marshal:: GetActiveObject("VisualStu
dio.DTE.8.0");
dte2->Events->BuildEvents->OnBuildBegin += gcnew
_dispBuildEvents_OnBuildBeginEventHandler(this,&My Designer::BuildEvents_OnBu
ildBegin);

}

void BuildEvents_OnBuildBegin(vsBuildScope Scope, vsBuildAction Action)
{
System::Windows::Forms::MessageBox::Show("Build Starts...");
}

};

[Designer(CControl::MyDesigner::typeid)]
public ref class CControlControl : System::Windows::Forms::UserControl
{
....
};
}

4. Build the project.
5. Add a new Visual C++ CLR Windows Forms Application project in the same
solution and drag the custom UserControl from the Toolbox onto the form in
the WinForm application project.
6. Build the solution. A messge box saying "Build Starts..." pops up.

Please try it on your side to see if it works and let me know the result.

Sincerely,
Linda Liu
Microsoft Online Community Support



Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.