zoukankan      html  css  js  c++  java
  • WPF与Win32的交互(2)

    为WPF添加Windows窗体控件

    1、通过XAML实现 

    1)添加WindowsFormIntegration.dll引用

         引用命名空间 xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"

    2)通过XAML来实现 

        <Grid x:Name="myGrid">
            <Grid.RowDefinitions>
                <RowDefinition/>
                <RowDefinition/>
            </Grid.RowDefinitions>
            <WindowsFormsHost>
                <wf:Button Text="WinForm Button" Click="Button_Click"></wf:Button>
            </WindowsFormsHost>
            <WindowsFormsHost Grid.Row="1">
                <wf:CheckBox Text="WinForm CheckBox"></wf:CheckBox>
            </WindowsFormsHost>
        </Grid>
    
     
            void button_Click(object sender, EventArgs e)
            {
                MessageBox.Show("this is the first windows form Button");
            }
    

     2.通过Code来实现

    1)使用命名空间

    using WindowsForms = System.Windows.Forms;
    using System.Windows.Forms.Integration;

    2)Code代码

     public partial class WPFWithWindowFormControl : Window
        {
            public WPFWithWindowFormControl()
            {
                this.Loaded += new RoutedEventHandler(WPFWithWindowFormControl_Loaded);
                InitializeComponent();
            }
    
            void WPFWithWindowFormControl_Loaded(object sender, RoutedEventArgs e)
            {
                WindowsFormsHost host = new WindowsFormsHost();
                WindowsForms.Button button = new System.Windows.Forms.Button();
                button.Text = "Button1";
                button.BackColor = System.Drawing.Color.LightBlue;
                button.Width = 100;
                button.Height = 50;
                button.Click += new EventHandler(button_Click);
    
                host.Child = button;
                host.VerticalAlignment = VerticalAlignment.Top;
                host.HorizontalAlignment = HorizontalAlignment.Left;
    
                WindowsFormsHost host2 = new WindowsFormsHost();
                WindowsForms.Button button2 = new System.Windows.Forms.Button();
                button2.Text = "Windows Form Button2";
                button2.BackColor = System.Drawing.Color.Red;
                button2.Width = 100;
                button2.Height = 50;
                
                host2.Child = button2;
                host2.Height = 50;
                host2.Width = 300;
                host2.VerticalAlignment = VerticalAlignment.Bottom;
                host2.HorizontalAlignment = HorizontalAlignment.Right;
    
                myGrid.Children.Add(host);
                myGrid.Children.Add(host2);
               
               
            }
    
            void button_Click(object sender, EventArgs e)
            {
                MessageBox.Show("this is the first windows form Button");
            }
    
        
        }
    

    前台代码:

        <Grid x:Name="myGrid"> 
        </Grid> 

  • 相关阅读:
    如何诊断RAC数据库上的“IPC Send timeout”问题?
    ORA-1157处理过程
    ORA-1157 Troubleshooting
    SQL优化案例(执行计划固定)
    数据库io层面故障
    sql优化案例(索引创建不合理)
    SQL优化案例(union问题)
    Redis在Windows下的安装与使用
    npm使用淘宝镜像
    基于compose单机部署 etcd + coredns
  • 原文地址:https://www.cnblogs.com/linlf03/p/2171941.html
Copyright © 2011-2022 走看看