admin管理员组文章数量:1574077
操作环境:XP,C# ,.Net4.0和VS2010中测试
WinForm中使用DWGThumbnail不用这么麻烦,下面讨论的是在WPF中使用,WPF中无法直接引用DWGThumbnail.ocx来操作
新建一个WPF项目,
添加一个WinForm窗口(即Form1.cs),在Form1窗口(这里注意不是MainWindow窗口)的工具箱中点右键“选择项”,
弹出选择工具箱项,切换到COM组件,
点击“浏览”打开你下载的这个控件DWGThumbnail.ocx,在列表中找到AutoCAD DwgThumbnail Control打上勾,确定。
这时你的Form1设计界面的工具箱中会出现AutoCAD DwgThumbnail Control这个控件的图标,拖一个至Form1窗口中,
然后关闭这个Form1窗口即可,这一步骤的目的就是为了在项目引用集里加入AxDWGTHUMBNAILLib这个类库,
自己直接“添加引用”不行,会报错。这时这个Form1.cs使命完成可以删除了,当然你不删也随便你。
1、在WPF中使用WinForm控件,需添加三个引用:
WindowsFormsIntegration.dll(负责整合WPF和Windows)
System.Windows.Forms
System.Drawing
2、在XAML文件中也添加两个引用(粗体部分):
<Window x:Class="test.MainWindow"
//添加下面这两行
xmlns:wfi ="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"
xmlns:wf ="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
//
xmlns="http://schemas.microsoft/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft/winfx/2006/xaml"
Title="WPF中使用WinForm控件预览DWG文件" Height="350" Width="525">
<Grid>
<wfi:WindowsFormsHost Name="ddd" Background="Beige">
<wf:Panel /> //这里随便添个控件占位,不加会出错
</wfi:WindowsFormsHost>
<Grid/>
</Window>
3、然后写个方法在事件中调用就行了。
private void DWGview()
{
AxDWGTHUMBNAILLib.AxDwgThumbnail ax = new AxDWGTHUMBNAILLib.AxDwgThumbnail();
ax.Location = new System.Drawing.Point(2, 2); //坐标
ax.Size = new System.Drawing.Size(203, 252); //坐标跟尺寸跟下面的width、height可灵活用,不是非写不可
ddd.Child.Controls.Add(ax);
//ax.Width = 600;
//ax.Height = 300;
ax.HasFocusRect = false; //不要焦点虚线
ax.BackColor = System.Drawing.Color.Black; //背景色
ax.DwgFileName = @"C:\aa.dwg";
ax.Refresh();
版权声明:本文标题:winform界面嵌入dwg图纸_WPF中使用WinForm控件预览DWG文件(学习笔记) 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/dongtai/1727765906a1128479.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论