Conflicts during runtime and compilation using the visual designer

Source: Internet
Author: User

Recently I was working on a winform project. This project requires that the color and font of the interface can be configured. how to configure it is easy to say. The main purpose is to bind the control property, is the configuration file. In this place, there is a little trouble.
Let's talk about the structure of the project:
All custom controls are a project and compiled as DLL. form is another project that references these DLL to generate exe. Only one configuration file is in the same directory as the EXE, and other configuration files (including files defining control properties) are set in that configuration file.
This causes the problem,ProgramThere is no problem during running, but when using the designer to design the form, the configuration file cannot be found.
Here, you may understand that our configuration file is defined in the configuration file and can only be obtained at runtime. The designer uses the pre-compilation technology, the location where the configuration file needs to be obtained during compilation.
How can we solve conflicts?
Write the path of the configuration file defining the control properties as constCodeIn?
This is what we first thought of. Of course, although there are some restrictions, it is indeed very useful, but new problems have come.
During the test, you need to test whether the attributes defined in the configuration file are correctly set and the path of the configuration file needs to be changed.
Trouble!
During the first test, the control project was compiled after the path in the configuration file and Code was modified. Run EXE, but the interface is not changed.
After repeated confirmation, I thought of the const issue.
As you may know, const is replaced during the compilation period. That is to say, after compiling the DLL, you still need to compile the form project. This is really unbearable.
It is another contradiction.
Const needs to be used during the compilation phase, but it is not expected to work during the runtime.
After searching for msdn, we found the class licensemanager and enumeration type licenseusagemode.
The usage is as follows:

1 If (Licensemanager. currentcontext. usagemode = Licenseusagemode. runtime)
2 {
3//Use at runtime
4}
5
6 If (Licensemanager. currentcontext. usagemode = Licenseusagemode. designtime)
7 {
8//Used by the visual designer or compiler during design
9}

It is very convenient to use the path in the configuration file and the const In the designer at runtime.
I hope the above will help you.
Add the msdn URL:
Http://www.msdn.net/library/chs/default.asp? Url =/library/CHS/cpref/html/frlrfsystemcomponentmodellicenseusagemodeclasstopic. asp

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.