In Visual Studio .NET, similar to the Applet or ActiveX control, the WinForm control can be embedded in IE. The Windows Form Control embedded in IE does not require registration, and you can be activated without user tips. We can easily implement some of WebForm to implement relatively trouble interactive operations, combined with .NET Remoting and other technologies access to the background database, you can generate powerful and beautiful WebForm pages. Using this technology, you need a client to install .NET Framework and IE 6.0, have come with the .NET Framework in Windows 2003. Winfrom control embedded in WebForm uses public language runtime code access security, and some special operations need to set access.
Let's make a simple example, use GDI implementation line function in the WinForm user control, and embed it into the IE browser. Development Environment: Windows 2000 Professional, Visualt Studio .NET 2002
1. Create a WinForm User Control We can create a "Windows Control Library" project, and only the DLL files that only need to be generated when the browser is embedded. But in order to facilitate debugging, we can first embed the control into WinForm. New "Windows Applications", named WinForminWebform, the generated solution also names WinForminWebform. Add a "Windows Control Library" item WinformControl in the solution, the system automatically adds UserControl1 user controls, deletes the control, and then add a user control WinformGdictrl in the Windows Control Library project. Now let's first add this control as "Windows Application" Form1. First, you need to generate a solution to generate a DLL file for the control. Then open the toolbox and right click to select "Add Tab" and add a "WinForm Control" tab to the toolbox. On this tab, right click, select Custom Toolbox, and pop up the custom toolbox page. Switch to the .NET Framework component page, click Browse, to the "/ WinformControl / bin / debug" directory to select the winformControl.dll file, then the WinformGdictrl control will appear in the "Winform Control" tab, then you can The control is dragged to Form1.
Open the winformggtrl.cs file, we can see the WinformGdictrl class inherit from System.Windows.Forms.userControl. Since we want to use GDI drawing, in order to prevent the flash caused by the control, we can enable dual buffering, specify the controls.doubleBuffer for True. To fully enable dual buffering, you must also set the UserPaint and AllPaintingInWmpAint bits to true. Public WinFormGDICtrl added in the constructor () {InitializeComponent (); this.SetStyle (ControlStyles.UserPaint, true); this.SetStyle (ControlStyles.AllPaintingInWmPaint, true); this.SetStyle (ControlStyles.DoubleBuffer, true);} Add a Class LineObj, used to save the line object, and add a DRAW method to this class for the drawing system.drawing; namespace winformj {public class lineobj {public point m_startpoint; // start point 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);}}} Add two type variables in the WinformGdictrl class, add two class variables, private arraylist m_arraylines; private bool m_bdrawing; m_arraylines For line object set, m_bdrawing indicates whether the line is drawn.
And class constructor initializes variables m_arrayLines = new ArrayList (); m_bDrawing = false; adding to the control MouseDown, MouseMove, MouseUp Paint event response function and private void WinFormGDICtrl_MouseDown (object sender, System.Windows.Forms.MouseEventArgs e) {LineObj m_lineObj = new LineObj (eX, eY); m_arrayLines.Add (m_lineObj); m_bDrawing = true;} private void WinFormGDICtrl_MouseMove (object sender, System.Windows.Forms.MouseEventArgs e) {if (m_bDrawing) {LineObj m_lineObj = (LineObj) m_arrayLines [m_arrayLines.Count-1]; m_lineObj.m_endPoint = new Point (eX, eY); this.Invalidate ();}} private void WinFormGDICtrl_MouseUp (object sender, System.Windows.Forms.MouseEventArgs e) {m_bDrawing = false; } private void WinFormGDICtrl_Paint (object sender, System.Windows.Forms.PaintEventArgs e) {Graphics g = e.Graphics; g.FillRectangle (Brushes.Yellow, this.ClientRectangle); foreach (Object obj in m_arrayLines) {LineObj m_lineObj = ( LineObj) Obj; M_LineObj.draw (g);}} Generate a solution, run Form1, you can see the effect of the control Open / WinformControl / BIN / Debug directory, where WinformControl.dll is what we need. 2. Embide the control into the IE browser to create a virtual directory WinFormCtrl, copy the winformControl.dll file into this directory, and create an Object in this directory. html file mark test.htm
head>