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
  #1  
Old   
bmelt
 
Posts: n/a

Default Trap a build start event from designer - 09-20-2007 , 06:28 PM






I'm developing a custom .Net control (in C++), in which I can set values in
Designer.
I need to validate those values before build started, so I would like to
trap event when I click on "Build" or "Start debugging" (press F7 or F5).
Could you please provide any advice how to do it.



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

Default RE: Trap a build start event from designer - 09-21-2007 , 04:01 AM






Hi Boris,

Based on my understanding, you'd like to validate the value of some custom
properties of your custom control before build starts. If I'm off base,
please feel free to let me know.

In fact, you needn't trap the build start event from designer to get what
you want. Instead, you could put the validating code in the set accessor of
the custom property.

The following is a sample:

public ref class MyControl: public System::Windows::Forms::UserControl
{
private: System::String^ s;
public :
property System::String^ S
{
System::String ^ get()
{
return s;
}
void set(System::String ^ value)
{
if(value=="123")
{
throw gcnew Exception("invalid data");
}
s = value;
}
}
}

Build the project and add the custom control on your form. If you set the
value of the property S in the Properties window to "123", a dialog pops up
saying "Property value is not valid" and forces you to change the value.

Hope this helps.
If you have any question, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.


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

Default RE: Trap a build start event from designer - 09-21-2007 , 11:20 AM



Hi Linda,
I apologize I simplified the problem so it became unclear. Unfortunately the
problem is more complex and I still need to trap a build start event.
My custom control is a grid, it is possible to type value into a grid cell
at design time and this value is saved by custom Serializer when I click on
another cell (or use tab). If I type a value in a cell and begin build/run
the WinForm with my grid on it, the value get lost. To validate and save this
value I need to click another cell before build/run, but it would be rather
better to trap a build start event to save value typed into the last cell.

Regards,
Boris

"Linda Liu [MSFT]" wrote:

Quote:
Hi Boris,

Based on my understanding, you'd like to validate the value of some custom
properties of your custom control before build starts. If I'm off base,
please feel free to let me know.

In fact, you needn't trap the build start event from designer to get what
you want. Instead, you could put the validating code in the set accessor of
the custom property.

The following is a sample:

public ref class MyControl: public System::Windows::Forms::UserControl
{
private: System::String^ s;
public :
property System::String^ S
{
System::String ^ get()
{
return s;
}
void set(System::String ^ value)
{
if(value=="123")
{
throw gcnew Exception("invalid data");
}
s = value;
}
}
}

Build the project and add the custom control on your form. If you set the
value of the property S in the Properties window to "123", a dialog pops up
saying "Property value is not valid" and forces you to change the value.

Hope this helps.
If you have any question, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.



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

Default RE: Trap a build start event from designer - 09-23-2007 , 01:01 PM



Hi Boris,

Thank you for your prompt reply!

Generally speaking, if we make some changes in design time and then build
the project directly, VS IDE saves the changes first which serializes the
changes to code and then begin the compilation.

Could you provide more information about your custom control and custom
serializer? If it is difficult to describe, you may send me a simple
project that could just reproduce the problem.

To get my actual email address, remove 'online' from my displayed email
address.


Sincerely,
Linda Liu
Microsoft Online Community Support


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

Default RE: Trap a build start event from designer - 09-26-2007 , 05:12 PM



Hi Linda,

In my app, custom control is a grid. If I set value in grid cell using
properties, yes, IDE saves changes before compilation. It looks more
convenient for users to type values in grid cells directly, and update
properties when cell value is stored (serializer is called in my code). The
problem is that cell's new value is not stored with each character typed, but
only when moving to another cell. If user types new value and forget to move
to another cell before pressing F5, new value is not stored before
compilation. From this point, it would be convenient to trap build start
event and store the last cell value before compilation. If you'll not be able
to help me trap this event, I'll try to find a workaround in control itself
changing value store code.

I see that using MenuCommandService class we can handle some menu commands
in Designer. Is it possible to solve my problem with this or with something
similar? Commands that I need are not in StandardCommands so it seems I just
need a GUID and command ID for "Build" menu item to use MenuCommandService ?
If this should work, where can I find GUID and command ID for menu items I'm
interested in?

Regards,
Boris


"Linda Liu [MSFT]" wrote:

Quote:
Hi Boris,

Thank you for your prompt reply!

Generally speaking, if we make some changes in design time and then build
the project directly, VS IDE saves the changes first which serializes the
changes to code and then begin the compilation.

Could you provide more information about your custom control and custom
serializer? If it is difficult to describe, you may send me a simple
project that could just reproduce the problem.

To get my actual email address, remove 'online' from my displayed email
address.


Sincerely,
Linda Liu
Microsoft Online Community Support



Reply With Quote
  #6  
Old   
Jack Jackson
 
Posts: n/a

Default Re: Trap a build start event from designer - 09-26-2007 , 06:03 PM



If you are using a DataGridView, you can force changes to be committed
immediately instead of when leaving the field. Maybe that would help.

Protected Overrides Sub onCurrentCellDirtyStateChanged(ByVal e As
System.EventArgs)
MyBase.OnCurrentCellDirtyStateChanged(e)

If IsCurrentCellDirty Then
CommitEdit(DataGridViewDataErrorContexts.Commit)
End If
End Sub


On Wed, 26 Sep 2007 14:12:02 -0700, bmelt
<bmelt12345 (AT) community (DOT) nospam> wrote:

Quote:
Hi Linda,

In my app, custom control is a grid. If I set value in grid cell using
properties, yes, IDE saves changes before compilation. It looks more
convenient for users to type values in grid cells directly, and update
properties when cell value is stored (serializer is called in my code). The
problem is that cell's new value is not stored with each character typed, but
only when moving to another cell. If user types new value and forget to move
to another cell before pressing F5, new value is not stored before
compilation. From this point, it would be convenient to trap build start
event and store the last cell value before compilation. If you'll not be able
to help me trap this event, I'll try to find a workaround in control itself
changing value store code.

I see that using MenuCommandService class we can handle some menu commands
in Designer. Is it possible to solve my problem with this or with something
similar? Commands that I need are not in StandardCommands so it seems I just
need a GUID and command ID for "Build" menu item to use MenuCommandService ?
If this should work, where can I find GUID and command ID for menu items I'm
interested in?

Regards,
Boris


"Linda Liu [MSFT]" wrote:

Hi Boris,

Thank you for your prompt reply!

Generally speaking, if we make some changes in design time and then build
the project directly, VS IDE saves the changes first which serializes the
changes to code and then begin the compilation.

Could you provide more information about your custom control and custom
serializer? If it is difficult to describe, you may send me a simple
project that could just reproduce the problem.

To get my actual email address, remove 'online' from my displayed email
address.


Sincerely,
Linda Liu
Microsoft Online Community Support



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

Default Re: Trap a build start event from designer - 09-26-2007 , 06:52 PM



Hi Jack,
Thanks for your suggestion. Grid used is not the DataGridView, but I believe
the problem should be similar.
There are 3 possible events when changes in the last modified cell could be
commited:
--on typing each character,
--on end editing (like pressing enter or leaving the cell),
--on start compilation
To avoid lost of the latest change in case user miss the 2nd type of event,
we can use 1st or 3rd ones.
I would prefer the 3rd one - it looks more efficient. If it is impossible,
I'll work on the 1st one, similar to your suggestion - as I actually
mentioned in my previous update. I hope there is a way to trap build start
event from Designer using MenuCommandService class or something similar, it
just not clearly documented.

Regards,
Boris

"Jack Jackson" wrote:

Quote:
If you are using a DataGridView, you can force changes to be committed
immediately instead of when leaving the field. Maybe that would help.

Protected Overrides Sub onCurrentCellDirtyStateChanged(ByVal e As
System.EventArgs)
MyBase.OnCurrentCellDirtyStateChanged(e)

If IsCurrentCellDirty Then
CommitEdit(DataGridViewDataErrorContexts.Commit)
End If
End Sub


On Wed, 26 Sep 2007 14:12:02 -0700, bmelt
bmelt12345 (AT) community (DOT) nospam> wrote:

Hi Linda,

In my app, custom control is a grid. If I set value in grid cell using
properties, yes, IDE saves changes before compilation. It looks more
convenient for users to type values in grid cells directly, and update
properties when cell value is stored (serializer is called in my code). The
problem is that cell's new value is not stored with each character typed, but
only when moving to another cell. If user types new value and forget to move
to another cell before pressing F5, new value is not stored before
compilation. From this point, it would be convenient to trap build start
event and store the last cell value before compilation. If you'll not be able
to help me trap this event, I'll try to find a workaround in control itself
changing value store code.

I see that using MenuCommandService class we can handle some menu commands
in Designer. Is it possible to solve my problem with this or with something
similar? Commands that I need are not in StandardCommands so it seems I just
need a GUID and command ID for "Build" menu item to use MenuCommandService ?
If this should work, where can I find GUID and command ID for menu items I'm
interested in?

Regards,
Boris


"Linda Liu [MSFT]" wrote:

Hi Boris,

Thank you for your prompt reply!

Generally speaking, if we make some changes in design time and then build
the project directly, VS IDE saves the changes first which serializes the
changes to code and then begin the compilation.

Could you provide more information about your custom control and custom
serializer? If it is difficult to describe, you may send me a simple
project that could just reproduce the problem.

To get my actual email address, remove 'online' from my displayed email
address.


Sincerely,
Linda Liu
Microsoft Online Community Support




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

Default Re: Trap a build start event from designer - 09-27-2007 , 04:24 AM



Hi Boris,

Thank you for your reply!

The MenuCommandService class implements the IMenuCommandService interface,
which is the managed interface used to add handlers for menu commands and
to define verbs. However, the Build/Start Debugging commands are not
commands on a designer, instead, they're commands of Visual Studio IDE.

So it's impossible to trap a build start event from designer.

Quote:
The problem is that cell's new value is not stored with each character
typed, but
only when moving to another cell.

When we make any change on a control in the designer, the changes should be
serialized into the InitializeComponent method immediately, even if we
don't save the changes.

I suggest you to type new value in a grid cell and switch to the code view
to see if the changes are serialized into the form's InitializeComponent
method.

If you could create a simple project that could reproduce the problem, I
still recommend you to send the sample project to me. Then I may give you a
direct assistance.

I look forward to your reply.


Sincerely,
Linda Liu
Microsoft Online Community Support



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

Default Re: Trap a build start event from designer - 10-01-2007 , 01:08 PM



Hi Linda,
Yes, probably it makes sense for me to invoke serialization after typing
each character into a cell.

BTW, I'm still wondering if we can trap Visual Studio events in Designer -
it may be possible through EnvDTE? Can we use from custom control at design
time something like
EnvDTE80:TE2 ^dte2 =

(EnvDTE80:TE2^)Marshal::GetActiveObject("VisualS tudio.DTE.8.0");
dte2->Events->BuildEvents->OnBuildBegin
+= gcnew _dispBuildEvents_OnBuildBeginEventHandler
(this,&MyControl::BuildEvents_OnBuildBegin);
void BuildEvents_OnBuildBegin(vsBuildScope Scope, vsBuildAction Action)
{
}
I could not figure out how to get it working yet.

Regards,
Boris


"Linda Liu [MSFT]" wrote:

Quote:
Hi Boris,

Thank you for your reply!

The MenuCommandService class implements the IMenuCommandService interface,
which is the managed interface used to add handlers for menu commands and
to define verbs. However, the Build/Start Debugging commands are not
commands on a designer, instead, they're commands of Visual Studio IDE.

So it's impossible to trap a build start event from designer.

The problem is that cell's new value is not stored with each character
typed, but
only when moving to another cell.

When we make any change on a control in the designer, the changes should be
serialized into the InitializeComponent method immediately, even if we
don't save the changes.

I suggest you to type new value in a grid cell and switch to the code view
to see if the changes are serialized into the form's InitializeComponent
method.

If you could create a simple project that could reproduce the problem, I
still recommend you to send the sample project to me. Then I may give you a
direct assistance.

I look forward to your reply.


Sincerely,
Linda Liu
Microsoft Online Community Support



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

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



Hi Boris,

Thank you for your feedback!

I am performing research on this issue and will get the result back to you
ASAP.

I appreciate your patience!

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.