当前位置:首页 > 网络编程 > 软件语言 > .NET > 在IE中使用VS.net WinForm控件

在IE中使用VS.net WinForm控件

点击次数:87 次 发布日期:2008-11-06 08:07:50 作者:源代码网
源代码网推荐
广告载入中
在Visual Studio .net中,类似于Applet或ActiveX控件,WinForm控件可以嵌入IE中使用。嵌入IE的Windows窗体控件不要求注册,不需用户提示即可激活。我们可以很方便地实现一些WebForm中实现起来相对麻烦的交互操作,结合.net Remoting等技术访问后台数据库,则可生成功能强大而且美观的WebForm页面。
源代码网推荐 使用该技术,需要客户端安装.net FrameWork及IE 6.0,在Windows 2003中已经自带了.net FrameWork。
源代码网推荐 嵌入WebForm的WinFrom控件利用公共语言运行库代码访问安全性,一些特殊操作还需要设置访问权限。
源代码网推荐
源代码网推荐
源代码网推荐
源代码网推荐下面就让我们做个简单的例子,在WinForm用户控件中使用GDI 实现画线功能,并把它嵌入IE浏览器。
源代码网推荐开发环境:Windows 2000专业版、Visualt Studio .net 2002
源代码网推荐
源代码网推荐1.创建WinForm用户控件
源代码网推荐 我们可以建立一个“Windows控件库”项目,最后嵌入浏览器时只需要生成的dll文件。但为了方便调试,我们可以先把控件嵌入WinForm中。
源代码网推荐 新建“Windows应用程序”,名称为WinFormInWebForm,生成的解决方案也名称为WinFormInWebForm。在解决方案中再添加一个“Windows控件库”项目WinFormControl,系统在该项目中自动添加一个了UserControl1的用户控件,删除该控件,然后在“Windows控件库”项目中添加一个用户控件WinFormGDICtrl。
源代码网推荐 现在我们先把该控件加如“Windows应用程序”的Form1中。
源代码网推荐 首先需要生成解决方案以生成控件的dll文件。然后打开工具箱,点右键选择“添加选项卡”,在工具箱中添加一个“WinForm控件”选项卡。在该选项卡上点右键,选择“自定义工具箱”,弹出自定义工具箱页面。切换到.net框架组件页面,单击浏览,到“WinFormControlinDebug”目录选择WinFormControl.dll文件,打开后在“WinForm控件”选项卡里就会出现WinFormGDICtrl控件,这时就可以把该控件拖动到Form1上了。
源代码网推荐
源代码网推荐
源代码网推荐
源代码网推荐
源代码网推荐 打开WinFormGDICtrl.cs文件,我们可以看到WinFormGDICtrl类继承自System.Windows.Forms.UserControl。
源代码网推荐 由于我们要使用GDI 绘图,为防止由控件重绘引起的闪烁,我们可以启用双缓冲,指定控件的ControlStyles.DoubleBuffer为true。要完全启用双缓冲,必须也要将 UserPaint 和 AllPaintingInWmPaint位数设置为 true。在构造函数中加入
源代码网推荐public WinFormGDICtrl()
源代码网推荐{
源代码网推荐 InitializeComponent();
源代码网推荐
源代码网推荐 this.SetStyle(ControlStyles.UserPaint,true);
源代码网推荐 this.SetStyle(ControlStyles.AllPaintingInWmPaint,true);
源代码网推荐 this.SetStyle(ControlStyles.DoubleBuffer,true);

源代码网推荐}
源代码网推荐
源代码网推荐添加一个类LineObj,用于保存线对象,并给该类添加一个Draw方法用于画线
源代码网推荐using System;
源代码网推荐using System.Drawing;
源代码网推荐namespace WinFormControl
源代码网推荐{
源代码网推荐 public class LineObj
源代码网推荐 {
源代码网推荐 public Point m_startPoint; //起始点
源代码网推荐 public Point m_endPoint; //截止点
源代码网推荐
源代码网推荐 public LineObj(int x,int y)
源代码网推荐 {
源代码网推荐 m_startPoint=new Point(x,y);
源代码网推荐 m_endPoint=new Point(x,y);
源代码网推荐 }
源代码网推荐
源代码网推荐 public void Draw(Graphics g)
源代码网推荐 {
源代码网推荐 g.DrawLine(new Pen(Color.Blue,2),m_startPoint,m_endPoint);
源代码网推荐 }
源代码网推荐 }
源代码网推荐}
源代码网推荐
源代码网推荐在WinFormGDICtrl类中添加两个类变量
源代码网推荐private ArrayList m_arrayLines;
源代码网推荐private bool m_bDrawing;
源代码网推荐m_arrayLines为线对象集合,m_bDrawing指示是否画线。
源代码网推荐并在类构造函数中初始化变量
源代码网推荐m_arrayLines=new ArrayList();

源代码网推荐

源代码网供稿.
网友评论 (0)
会员中心
网络编程
本站推荐
网络编程之精华