Monday, April 7, 2014

How to Host single or multiple Windows forms Controls in WPF

1. Open the Solution Explorer.
2. Right Click on the References, then click on the Add Reference.
3. Then Click on the Assemblies on the left Panel. Then select the Framwork.
4. Then Check the Checkbox of System.Windows.Forms and WindowsFormsIntegration.
5. Then Click Ok..





























6. Then Open the MainWindow.xaml
7. Write the following code:---



       <Window x:Class="pk7918.MainWindow"
       xmlns:wfi="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"
        xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
        Title="MainWindow" Height="350" Width="525">
    <Grid VerticalAlignment="Bottom">
        <Button Content="Button" HorizontalAlignment="Left" Margin="205,211,0,0" VerticalAlignment="Top" Width="75" Click="Button_Click_1"/>
        <Label Content="Label" HorizontalAlignment="Left" Margin="108,123,0,0" VerticalAlignment="Top"/>
        <TextBox HorizontalAlignment="Left" x:Name="txtname" Height="23" Margin="223,146,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="120"/>
        <Grid VerticalAlignment="Top">
           <wfi:WindowsFormsHost>
            <wf:DateTimePicker>
                
            </wf:DateTimePicker>
        </wfi:WindowsFormsHost>

        </Grid>
    </Grid>
</Window>
   








No comments:

Post a Comment