Method of Introducing WindowsForms Control into WPF
- 2021-11-01 04:20:38
- OfStack
This paper describes the method of introducing WindowsForms control into WPF. Share it for your reference, as follows:
Environment:
[1]WindowsXP with SP3
[2]VS2008 with SP1
Text:
Step1: Introducing Windows Forms into existing projects
Right mouse button [References]- > Select [Add Reference]- > [. NET] tab
Add [WindowsFormsIntegration] and [System. Windows. Forms]
Step2: Add to the XAML file
[S2-1] Add namespace reference:
xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
xmlns:wfi="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"
[S2-2] Add Windows Forms control
<wfi:WindowsFormsHost Name="winFormsContainer" Grid.Row="2" Margin="0,5,0,0">
<wf:ListView x:Name="listView1" Margin="0,2,0,0" Name="listView1"/>
</wfi:WindowsFormsHost>
Step3: Operate WindowsForms control in CS code
Icon icon = new Icon(@"driver.ico");
System.Windows.Forms.ImageList imageList2 = new System.Windows.Forms.ImageList();
imageList2.Images.Add(icon);
listView1.SmallImageList = imageList2;
More readers interested in C # can check the topic of this site: "C # Form Operation Skills Summary", "C # Common Control Usage Tutorial", "WinForm Control Usage Summary", "C # Programming Thread Use Skills Summary", "C # Operating Excel Skills Summary", "XML File Operation Skills Summary in C #", "C # Data Structure and Algorithm Tutorial", "C # Array Operation Skills Summary" and "C # Object-Oriented Programming Introduction Tutorial"
I hope this article is helpful to everyone's C # programming.