Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The skill of using ComponentOne-- from Winform to W

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

Overview

WPF and Winform are two separate platforms, but both are based on .NET version 4.0 or later, so many .NET developers begin to study how to use Winform in WPF. Microsoft has built a communication bridge between the two development platforms, and the conversion between the two has been quite mature so far. Today, we will mainly talk about how to use ComponentOne controls in these two platforms.

This paper mainly uses FlexReport .NET report control as a medium to link the two platforms.

Step 1

First of all, let's set up the basic communication channels of the two platforms. It is very simple. There are many steps on the Internet, which are mainly divided into three steps:

1. Add two references: WindowsFormsIntegration.dll (responsible for integrating WPF and Windows) and System.Windows.Forms.

two。 Add two references (in bold) to the XAML file:

< /Window>

To explain, what this code really works is the reference WindowsFormsIntegration.dll, and this reference System.Windows.Forms refers to the Microsoft native control in Winform, so when using ComponentOne, you can not reference it.

Let's first look at an example: using Winform in WPF through Microsoft primitive controls, the code is as follows:

WindowsFormsHost is actually a container for Winform in WPF, so all Winform controls are displayed in this container.

Setp2

As we said above, we use FlexReport as the medium for communication, then we need to prepare a few small steps:

The template of FlexReport under 1.Winform

two。 Related citation

Note: the reference here is a reference to Winform. Again, we need to quote in xmal:

Xmlns:cc11= "clr-namespace:C1.Win.FlexViewer;assembly=C1.Win.FlexViewer.4"

Add controls to the layout for report preview

Setp3

We load the report in the background

Private C1FlexReport _ report; public Window1 () {InitializeComponent (); _ report = new C1FlexReport (); / / load report definition from resources Assembly asm = Assembly.GetExecutingAssembly (); using (Stream stream = asm.GetManifestResourceStream ("WpfApp1.Resources.FlexCommonTasks.flxr")) _ report.Load (stream, "Chart2D"); / / assign report to the preview pane flexViewerPane.DocumentSource = null; flexViewerPane.DocumentSource = _ report }

Note: keep in mind that the reports here are from the Winform platform.

At this point, we have finished more than half of our work, and we are still short of the last step of turning stone into gold. Many people think that it is over here, but we have to consider the problem of ComponentOne License authorization. How to register the authorization of Winform under WPF is actually very simple, because the license mechanism of .NET is the same, we only need to register the license of the control in the same way, but manual registration is recommended here, which is very important, because if you are not careful, you will report the error of lc.exe=-1.

We all use it here.

C1FlexViewerPane

C1FlexReport

So we write the following registration information in the license file

C1.Win.FlexReport.C1FlexReport, C1.Win.FlexReport.4 C1.Win.FlexViewer.C1FlexViewerPane, C1.Win.FlexViewer.4

At this point, we are done.

Example × ×

For the sample source code in this article, please click here to download

About the city of grapes:

Empowered developer! Founded in 1980, Grape City is the world's leading software and service provider integrating development tools, business intelligence solutions, and management system design tools. Xi'an Grape City is its branch in China, providing software research and development services to the global market, and providing international advanced development tools, software and R & D consulting services for the informatization of Chinese enterprises. Grape City's controls and software products have won many awards at home and abroad, and have been widely used by hundreds of thousands of enterprises, schools and government agencies around the world.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report