没有找到合适的产品?
联系客服协助选型:023-68661681
提供3000多款全球软件/控件产品
针对软件研发的各个阶段提供专业培训与技术咨询
根据客户需求提供定制化的软件开发服务
全球知名设计软件,显著提升设计质量
打造以经营为中心,实现生产过程透明化管理
帮助企业合理产能分配,提高资源利用率
快速打造数字化生产线,实现全流程追溯
生产过程精准追溯,满足企业合规要求
以六西格玛为理论基础,实现产品质量全数字化管理
通过大屏电子看板,实现车间透明化管理
对设备进行全生命周期管理,提高设备综合利用率
实现设备数据的实时采集与监控
利用数字化技术提升油气勘探的效率和成功率
钻井计划优化、实时监控和风险评估
提供业务洞察与决策支持实现数据驱动决策
 
                
            转帖|其它|编辑:郝浩|2011-05-13 14:44:52.000|阅读 1225 次
概述:下面以在Wpf中添加ZedGraph(用于创建任意数据的二维线型、条型、饼型图表的一个开源类库)控件,说明在WPF中使用Winform控件的方法。
# 界面/图表报表/文档/IDE等千款热门软控件火热销售中 >>
下面以在Wpf中添加ZedGraph(用于创建任意数据的二维线型、条型、饼型图表的一个开源类库)控件,说明在WPF中使用Winform控件的方法。
1、 首先添加对如下两个dll文件的引用:WindowsFormsIntegration.dll,System.Windows.Forms.dll。
2、 由于要用到ZedGraph控件,所以也要添加对ZedGraph.dll的引用。
3、 在要使用WinForm控件的WPF窗体的XAML文件中添加如下内容(选中部分):
即:
 xmlns:wfi ="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"
xmlns:wf ="clr-namespace:System.Windows.Forms;
assembly=System.Windows.Forms"
xmlns:zedgraph="clr-namespace:ZedGraph;assembly=ZedGraph"
 
4、 在WPF的容器控件内如Grid内首先要添加WinForm控件的宿主容器,用于衔接WPF和WinForm,
对应XAML如下:
 <Grid>
           <wfi:WindowsFormsHost Width="300" HorizontalAlignment="Right">
               <wf:Label x:Name="lblName" Text="winForm控件在此” />
           </wfi:WindowsFormsHost>
           <wfi:WindowsFormsHost>
               <wf:Button x:Name="nnn" Text="确定”/>
           </wfi:WindowsFormsHost>
           <wfi:WindowsFormsHost>
               <zedgraph:ZedGraphControl x:Name="zedGraphControl" />
           </wfi:WindowsFormsHost>
     <Button Content="Button" Height="23" HorizontalAlignment="Left" 
Margin="10,10,0,0" 
Name="button1" VerticalAlignment="Top"
Width="75" Click="button1_Click" />
       </Grid>
说明:<wfi:WindowsFormsHost></wfi:WindowsFormsHost>即为WinForm控件的宿主容器,每一个宿主容器只能放一个WinForm控件,如下例,放了三个WinForm控件,分别放在三个宿主容器里面,该容器可以设置属性来调整大小和布局。
注意:如上我添加的WinForm控件如在指定其Name时,必须加前缀x:,如添加Lable时<wf:Label x:Name="lblName" Text="我是WPF中的WinForm控件” />,
否则后台代码无法访问。
5、 如果要在WPF后台代码中访问上面的Lable,可直接像在WinForm中使用一样。如在点击某一按钮时改变Lable内容,代码如下:lblName.Text=”内容已改变”;
6、 以使用WinForm控件ZedGraph绘制曲线为例,说明后台用法:
在后台用Using添加对System.Windows.Forms和ZedGraph和System.Drawing命名空间的引用,完整后台代码如下:
 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Forms;
using ZedGraph;
using System.Drawing;
namespace ZedGraphAtWpf2
{
       /// <summary>
       /// MainWindow.xaml 的交互逻辑
       /// </summary>
       public partial class MainWindow : Window
       {
           public MainWindow()
           {
               InitializeComponent();
           }
           private void button1_Click(object sender, RoutedEventArgs e)
           {
               lblName.Text =”我是WinForm控件”;
           }
           private void Window_Loaded(object sender, RoutedEventArgs e)
           {
               ZedGraph.GraphPane myPane = zedGraphControl.GraphPane;
               myPane.Title.Text = "My Test Graph\n(For CodeProject Sample)";
               myPane.XAxis.Title.Text = "My X Axis";
               myPane.YAxis.Title.Text = "My Y Axis";
               PointPairList list1 = new PointPairList();
               PointPairList list2 = new PointPairList();
               for (int i = 0; i < 36; i++)
               {
                   double x = (double)i + 5;
                   double y1 = 1.5 + Math.Sin((double)i * 0.2);
                   double y2 = 3.0 * (1.5 + Math.Sin((double)i * 0.2));
                   list1.Add(x, y1);
                   list2.Add(x, y2);
               }
               // Generate a red curve with diamond
               // symbols, and "Porsche" in the legend
               LineItem myCurve = myPane.AddCurve("Porsche",
                   list1, System.Drawing.Color.Red, SymbolType.Diamond);
               // Generate a blue curve with circle
               // symbols, and "Piper" in the legend
               LineItem myCurve2 = myPane.AddCurve("Piper",
                   list2, System.Drawing.Color.Blue, SymbolType.Circle);
               zedGraphControl.AxisChange();
           }
       }
}
完整XAML如下:
<Window x:Class="ZedGraphAtWpf2.MainWindow"
            xmlns:wfi ="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"
           xmlns:wf ="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
           xmlns:zedgraph="clr-namespace:ZedGraph;assembly=ZedGraph"
           xmlns="//schemas.microsoft.com/winfx/2006/xaml/presentation"
           xmlns:x="//schemas.microsoft.com/winfx/2006/xaml"
           Title="MainWindow" Height="350" Width="525" Loaded="Window_Loaded">
       <Grid>
           <wfi:WindowsFormsHost Width="300" HorizontalAlignment="Right">
               <wf:Label x:Name="lblName" Text="WinForm控件在此” />
           </wfi:WindowsFormsHost>
           <wfi:WindowsFormsHost>
               <wf:Button x:Name="nnn" Text="确定” />
           </wfi:WindowsFormsHost>
           <wfi:WindowsFormsHost>
               <zedgraph:ZedGraphControl x:Name="zedGraphControl" />
           </wfi:WindowsFormsHost>
    <Button Content="Button" Height="23" HorizontalAlignment="Left" 
Margin="10,10,0,0" 
Name="button1" VerticalAlignment="Top" 
Width="75" Click="button1_Click" />
       </Grid>
</Window>
本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@ldacury.cn
文章转载自:CSDN



 
					接DevExpress原厂商通知,将于近日上调旗下产品授权价格,现在下单客户可享受优惠报价!
 
					面对“数字中国”建设和中国制造2025战略实施的机遇期,中车信息公司紧跟时代的步伐,以“集约化、专业化、标准化、精益化、一体化、平台化”为工作目标,大力推进信息服务、工业软件等核心产品及业务的发展。在慧都3D解决方案的实施下,清软英泰建成了多模型来源的综合轻量化显示平台、实现文件不失真的百倍压缩比、针对模型中的大模型文件,在展示平台上进行流畅展示,提升工作效率,优化了使用体验。
 
					本站的模型资源均免费下载,登录后即可下载。模型仅供学习交流,勿做商业用途。
 
					本站的模型资源均免费下载,登录后即可下载。模型仅供学习交流,勿做商业用途。
服务电话
重庆/ 023-68661681
华东/ 13452821722
华南/ 18100878085
华北/ 17347785263
客户支持
技术支持咨询服务
服务热线:400-700-1020
邮箱:sales@ldacury.cn
关注我们
地址 : 重庆市九龙坡区火炬大道69号6幢
 
                 
            
 靠谱朗驰娱乐体育
靠谱朗驰娱乐体育  
					 
					 
					 
					 
					