Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / Design Time / June 2004

Tip: Looking for answers? Try searching our database.

Cutting and pasting with licensed custom controls.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Brock Reeve - 16 Jun 2004 14:59 GMT
I am using the .NET licensing pattern to license some custom
WindowsForms controls.  Everything is working fine except when I
cut/copy and paste the control.  The problem is that
LicenseManager.GetLicense has a parameter of type LicenseContext.
This type contains a property called UsageMode that tells you if you
are in DesignTime or RunTime.  When pasting one of my custom controls
this property returns RunTime even though I am still in DesignTime.
This seems very inconsistant.  Is there a workaround for this problem?

Thanks,

Brock
"Ying-Shen Yu[MSFT]" - 17 Jun 2004 06:55 GMT
Hi Brock,

I'm able to reproduce this issue, seems the LicenseContext was not set
correctly in copy & paste operation, I'll forward this issue to the product
group to let them know.

In the mean time, I think you may try way to workaround this issue:
1. If you put the license validation code in the constructor of the user
control, remove the License Validation code from the constructor
2. Define a customized LicenseContext class derive from
DesigntimeLicenseContext class like below:
<code>
class MyDesignTimeLicenseContext :
System.ComponentModel.Design.DesigntimeLicenseContext
{
    IDesignerHost provider = null;
    public MyDesignTimeLicenseContext ( IDesignerHost host)
    {
        provider = host;
    }
    public override object GetService(Type type)
    {
        return provider.GetService(type);
    }
}
</code>
2. override OnLoad event for you user control , insert the code snippet
like below:
<code>
if ( DesignMode )
{
    IDesignerHost host = (IDesignerHost) this.GetService(
typeof(IDesignerHost) );
    LicenseManager.CurrentContext = new MyDesignTimeLicenseContext( host );
    license = LicenseManager.Validate(typeof(UserControl1), this);
    LicenseManager.CurrentContext = null;
}
else  license = LicenseManager.Validate(typeof(UserControl1), this);
</code>

Then you should be able to copy & paste licensed user controls.
Does it resolve your problem?
Feel free to reply this thread if you still have problems on it.

Have a nice day!

Best regards,

Ying-Shen Yu [MSFT]
Microsoft Community Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
This mail should not be replied directly, please remove the word "online"
before sending mail.
Brock Reeve - 21 Jun 2004 22:07 GMT
All or our custom controls derive from Control which doesn't have a Load
event.  When it comes down to it, we don't want to move our
LicenseManager.Validate calls outside the constructor.  The constructor will
always be called and we are guaranteed that the licensing code will get
called. Users could override the On* event and not call the base version and
get a free control.  Also the controls could be dynamically created which
may or may not fire certain events and the Validate call could get skipped
altogether.  Sure we could find some little hack to get it to work, but it
would be more work and a lot of testing we are not able to do right now.
Our hope is that this issue is fixed in Whitbey.

Thanks,

Brock
"Ying-Shen Yu[MSFT]" - 22 Jun 2004 02:58 GMT
Hi Brock,

Thanks for your reply!
The reason why I put the code snippet in OnLoad method is because, the
DesignMode property always return false, so  we are unable to determine if
the control was instantiated in design-time or run-time environment.

I have forwarded this issue to product group to let them do further
investigation, thanks for your feedback!

Best regards,

Ying-Shen Yu [MSFT]
Microsoft Community Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
This mail should not be replied directly, please remove the word "online"
before sending mail.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.