[Aaronyang] write to his own WPF4.5 note 24 [Interaction with WinForm-flash-demo-finishing Chapter 1/6]

Source: Internet
Author: User

===== Chic Copyright line ======www.ayjs.net===== Aaronyang ===== AY ====== Anhui six An Yangyang ====== without permission reprint ======

1. Create a new WPF application, and then add a Windows Form

At this point the left Toolbox automatically winform the Toolbox.

Then add a button and set the DialogResult property to OK

Open the WPF MainWindow.xaml Add a button, click the event below

    Private void Btnopenwinform_click (object  sender, RoutedEventArgs e)        {            new  Showswfform ();             if (SS. ShowDialog () = = System.Windows.Forms.DialogResult.OK) {                MessageBox.Show ("OK button clicked ");            }        }

============= Chic Copyright line ==========www.ayjs.net===== Aaronyang ========= AY =========== Anhui six An Yangyang ========== without permission reprint =========

Show the non-modal window, first add WindowsFormIntegration.dll

Add a button again and we open the WinForm interface with the following events

Private void Btnopennormallwinform_click (object  sender, RoutedEventArgs e)        {            new  showswfform ();             // block keyboard events for easy interface access to keyboard operation             Windowsformshost.enablewindowsformsinterop ();            Ss. Show ();        }

Do not add this line Windowsformshost.enablewindowsformsinterop (); Code, open the window after the key will not be captured, such as the TAB key, you can try. Plus, the tab post button will have a dashed box indicating that the TAB key is in effect.

2. Enable visualization of WinForm

 Public Partial class app:application    {        protectedoverridevoid  onstartup (StartupEventArgs e)        {             Base . Onstartup (e);             // System.Windows.Forms.Application.EnableVisualStyles ();         }    }

Try defining a style and find that it will not work, but the above line of code EnableVisualStyles should be for the button to follow the system changes

3. WinForm controls and WPF controls on a single interface

Each control of WinForm is a separate window, and each control has its own area of the screen.

WPF has a top-level window that floats on the screen. So as long as WPF has a separate top-level window handle, and the WPF engine organizes the entire window, the window can be better rendered. Some elements of WPF use separate window handles. such as menus, ToolTips, and drop-down sections of combo boxes. These all have the ability to extend window boundaries.

The "airspace" principle, where the content of the WinForm form is placed on WPF content, the WinForm form content is always on top of WPF, regardless of where the markup is declared. Therefore, WPF and WinForm form content cannot be combined by overlapping. means that you cannot use animations to fly over areas of the WinForm form rendering. The same content cannot be mixed together. So WPF uses Flash generally set a WinForm, but flash when the background is still relatively difficult.

4. In WPF, the control that resides in WinForm, we need to use the WindowsFormsHost control, if you want to use WinForm control, you need to introduce xmlns:wf= "clr-namespace:system.windows.forms; Assembly=system.windows.forms "

<Windowx:class= "Win32wpf.mainwindow"xmlns= "Http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x= "Http://schemas.microsoft.com/winfx/2006/xaml"windowstartuplocation= "Centerscreen"XMLNS:WF= "Clr-namespace:system.windows.forms;assembly=system.windows.forms"Title= "MainWindow"Height= "The "Width= "$">    <Grid>        <grid.rowdefinitions>            <RowDefinitionHeight= "18*"/>            <RowDefinitionHeight= "205*"/>        </grid.rowdefinitions>        <Buttonx:name= "Btnopenwinform"Click= "Btnopenwinform_click"Content= "Modal Open WinForm"HorizontalAlignment= "Left"Margin= "28,10,0,0"VerticalAlignment= "Top"Width= "145"/>        <Buttonx:name= "Btnopennormallwinform"Click= "Btnopennormallwinform_click"Content= "Normal WinForm"HorizontalAlignment= "Left"Margin= "178,10,0,0"VerticalAlignment= "Top"Width= "145"/>        <WindowsFormsHostGrid.Row= "1">                    </WindowsFormsHost>    </Grid></Window>

Value, directly to the NumericUpDown control plus x:name= "Nud" dependency property, and then the background directly this.nud.Value.ToString ();

Then we introduced the Flash COM component

Introduced to play only to find that the 2015 Flash COM build has changed, the basic online tutorial is generally useless. Well, think about it yourself.

No Axshockwaveflash controls were found on the web.

But, forget, or decisively give up, I chose the second solution, found C:\Windows\System32\Macromed\Flash directory, found flash.ocx and flash64_17_0_0_134.ocx, I do not know which is useful, Guess Flash64_17_0_0_134.ocx should be 64-bit.

Remove the just ShockwaveFlash reference. I still open COM build reference, and then browse local, select the flash.ocx, the result is the same as the last time, OK ... Thinking in:

Then I opened the ShowSwfForm.cs, and then winform the version of the designer toolbox, right-click General-Select the item-com component, locate Shockwave Flash Object, and clicking OK. Then drag the control to the WinForm form, and then the.

Came up

Well, you win, I go back to the WPF page, write down the familiar Axshockwaveflash code, and then it's easy.

<Windowx:class= "Win32wpf.mainwindow"xmlns= "Http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x= "Http://schemas.microsoft.com/winfx/2006/xaml"windowstartuplocation= "Centerscreen"XMLNS:WF= "Clr-namespace:system.windows.forms;assembly=system.windows.forms"xmlns:f= "Clr-namespace:axshockwaveflashobjects;assembly=axinterop.shockwaveflashobjects"Title= "MainWindow"Height= "The "Width= "$"Loaded= "window_loaded">    <Grid>        <grid.rowdefinitions>            <RowDefinitionHeight= "18*"/>            <RowDefinitionHeight= "205*"/>        </grid.rowdefinitions>        <Buttonx:name= "Btnopenwinform"Click= "Btnopenwinform_click"Content= "Modal Open WinForm"HorizontalAlignment= "Left"Margin= "28,10,0,0"VerticalAlignment= "Top"Width= "145"/>        <Buttonx:name= "Btnopennormallwinform"Click= "Btnopennormallwinform_click"Content= "Normal WinForm"HorizontalAlignment= "Left"Margin= "178,10,0,0"VerticalAlignment= "Top"Width= "145"/>        <WindowsFormsHostGrid.Row= "1"x:name= "WFH">            <!--<wf:numericupdown maximum= "minimum=" 0 "increment=" width= "" "dock=" Top "></wf:numericupdown > -            <F:axshockwaveflashx:name= "Flashcontainer"/>        </WindowsFormsHost>    </Grid></Window>

OK, backstage code, the Internet is able to come out of Baidu.

============= Chic Copyright line ==========www.ayjs.net===== Aaronyang ========= AY =========== Anhui six An Yangyang ========== without permission reprint =========

-------------------A small recommendation, the author's Affirmation, the reader's support. Pushing is not recommended is not important, it is important to hope that we can extend the WPF, do not let such a good technology disappear, please, let us make a contribution to WPF technology. -----------------

[Aaronyang] write to his own WPF4.5 note 24 [Interaction with WinForm-flash-demo-finishing Chapter 1/6]

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.