Use the XP style interface in VB. NET

Source: Internet
Author: User

In VB.net, the style of Windows applications started from form is XP by default, but if it is set to start Windows applications from the main function, the interface will return to the ugly style of VB6. In this case, what should I do to use the XP style interface?

 

You can find a lot of plug-ins that use Windows XP on the Internet. However, basically, they all use vb6as their prefix and all use the primary program name .exe. manifest "is an xml configuration file. Some methods are very complicated (I don't know) and convenient, but it does not completely solve the problem. You have to recompile the file every time you re-compile it.

 

In fact, there is already a very convenient method for this problem in VB.net, that is, using enablevisualstyles. The specific method is as follows:

Module main

Sub main ()
Application. enablevisualstyles ()
Application. doevents ()
Application. Run (frmmain)
End sub
End Module

According to msdn, it is best to use enablevisualstyles in the main function, and then use the application to run the form. In addition, if the control contains the flatstyle attribute (such as button, groupbox, checkedbox, and radiobutton), you must change the attribute to system.
Note that only one enablevisualstyles can be used once in an application. Otherwise, an interopservices. sehexception is thrown.

 

-----------------------------------------------------------------------------

 

Next we will introduce the simple but incomplete method mentioned above:

 

Create a. manifest file. The file must be in the same folder as the target program (for example, the/bin folder of your project), and the name must be
Myapp.exe. manifest, where MyApp is your program file name. The file content is as follows:

<? XML version = "1.0" encoding = "UTF-8" standalone = "yes"?>
<Assembly xmlns = "urn: Schemas-Microsoft-com: ASM. V1" manifestversion = "1.0">
<Assemblyidentity version = "1.0.0.0" processorarchitecture = "x86"
Name = "MyApp" type = "Win32"/>
<Description> your application description here. </description>
<Dependency>
<Dependentassembly>
<Assemblyidentity type = "Win32" name = "Microsoft. Windows. Common-Controls" version = "6.0.0.0"
Processorarchitecture = "x86" publickeytoken = "6595b64144ccf1df" Language = "*"/>
</Dependentassembly>
</Dependency>
</Assembly>
Replace myapp.exe with the target program file name and version with your version. You can use NotePad to create this file.
In the. NET project, set the flatstyle attribute of the button and label of the form to system, for example:
  

In this way, the. NET program you created can render the XP style.
Here, a problem occurs: In no case, myapp.exeis the file name of myapp.exe. manifest, and XP sytle disappears.

The solution directly inserts the manifestfile into the. exe file. The method is as follows:
Use Visual studio.netto open the. exe file (test_wmpsdk.exe). The following is displayed:
  

We add a resource to it:
  

In the dialog box, the manifest type is not found. It doesn't matter. We use "import" to import:
  

Note that the file type is "all files ". After adding the resource, the resource type is required. We write rt_manifest:
  

Now the resource is added:
  

Before we finish, we need to change the resource ID from 101 to 1:
  

In this example, save the. exe file and run it. (delete the. manifest file ):
  

When you change the .exe file name, the program can still render the XP style. But there is another problem. Because resources are added later, once your project is regenerated, the XP style disappears. A thorough approach is to add the manifest file to the resources of the project.

As for how to add the manifest file to engineering resources, it seems very complicated. I have not studied it in depth. If you are interested, you can still find this information on the Internet.

 

 

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.