heres a few classes i wrote a while back,
it probably needs a bit of tidying up, but it works
some nice functions for setting the values of an HTML form once the page has
loaded + submitting a button from a windows forms app.
The main one you'll be interested in though is...
public void Navigate(string _url, string _valuedatapairs)..
this method you just call like :
webcontrol.Navigate("
www.yahoo.co.uk","param1=one¶m2=two&etc=easyasthis"
);
if you want to pass values to an array from a list box, use a for loop, and
make each parameter the same name.... but you probably
know what to do from here.
also started doing some work on showing a custom context menu -
anyway, hope this helps
(you'll need to get VS.NET to create a wrapper for the WebControl) - i
haven't included it here
sam martin
/////////////////////////////////////////////////////////////////////////
public class DocUIResponseArgs : System.EventArgs
{
private string _appref;
private string _appdata;
public DocUIResponseArgs(string _r, string _d)
{
this._appdata = _d;
this._appref = _r;
}
public string AppRef
{
get { return this._appref; }
}
public string AppData
{
get { return this._appdata; }
}
}
public class DocUIHandler
{
private string _appref;
private DocUIResponseHandler _handler;
public DocUIHandler(string _r, DocUIResponseHandler _h)
{
this._appref = _r;
this._handler = _h;
}
public string AppRef
{
get { return this._appref; }
}
public DocUIResponseHandler Handler
{
get { return this._handler; }
}
}
public delegate void DocUIResponseDelegate(object sender, DocUIResponseArgs
e);
public delegate void DocumentCompleteDelegate(object sender,
DocUIResponseArgs e);
public delegate void DocUIResponseHandler(object sender, DocUIResponseArgs
e);
/// <summary>
/// Summary description for WebControl.
/// </summary>
public class WebControl : System.Windows.Forms.UserControl,
IDocHostUIHandler
{
private string _urlbase;
private AxSHDocVw.AxWebBrowser axWebBrowser;
private System.Collections.ArrayList _delegatemap;
public event DocumentCompleteDelegate DocumentCompleteEvent;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public WebControl()
{
// This call is required by the Windows.Forms Form Designer.
InitializeComponent();
this._delegatemap = new ArrayList();
_urlbase =
System.Configuration.ConfigurationSettings.AppSettings["Accuman.Web.Server"]
;
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
public void Navigate(string _url, string _valuedatapairs)
{
//_delegatemap.Clear();
object _ourl = this._urlbase+_url;
object _onull = new object();
object _header = "Content-Type: application/x-www-form-urlencoded" + "\n"
+ "\r";
string _data =_valuedatapairs;
object _odata = System.Text.ASCIIEncoding.ASCII.GetBytes(_data);
this.axWebBrowser.Navigate2(ref _ourl,ref _onull,ref _onull,ref
_odata,ref _header);
}
public void RefreshPage()
{
object _onull = null;
this.axWebBrowser.Refresh2(ref _onull);
}
public void SetFormFieldValue(string _fieldid, string _value)
{
IHTMLDocument2 doc = (IHTMLDocument2)this.axWebBrowser.Document;
mshtml.HTMLInputElementClass _f =
(mshtml.HTMLInputElementClass)doc.all.item(_fieldid,null);
_f.value = _value;
}
public void SubmitForm(string _formid)
{
IHTMLDocument2 doc = (IHTMLDocument2)this.axWebBrowser.Document;
mshtml.HTMLFormElementClass _f =
(mshtml.HTMLFormElementClass)doc.forms.item(null,0);
object _oevt = new object();
_f.submit();
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new
System.Resources.ResourceManager(typeof(WebControl));
this.axWebBrowser = new AxSHDocVw.AxWebBrowser();
((System.ComponentModel.ISupportInitialize)(this.axWebBrowser)).BeginInit();
this.SuspendLayout();
//
// axWebBrowser
//
this.axWebBrowser.Dock = System.Windows.Forms.DockStyle.Fill;
this.axWebBrowser.Enabled = true;
this.axWebBrowser.Location = new System.Drawing.Point(0, 0);
//this.axWebBrowser.OcxState =
((System.Windows.Forms.AxHost.State)(resources.GetObject("axWebBrowser.OcxSt
ate")));
this.axWebBrowser.Size = new System.Drawing.Size(150, 150);
this.axWebBrowser.TabIndex = 0;
this.axWebBrowser.DocumentComplete += new
AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEventHandler(this.OnDocumentCom
plete);
//
// WebControl
//
this.Controls.Add(this.axWebBrowser);
this.Name = "WebControl";
((System.ComponentModel.ISupportInitialize)(this.axWebBrowser)).EndInit();
this.ResumeLayout(false);
}
#endregion
// IDocHostUIHandler Implementations
void IDocHostUIHandler.EnableModeless(int fEnable)
{
}
void IDocHostUIHandler.FilterDataObject(MsHtmHstInterop.IDataObject pDO,
out MsHtmHstInterop.IDataObject ppDORet)
{
ppDORet = null;
}
void IDocHostUIHandler.GetDropTarget(IDropTarget pDropTarget, out
IDropTarget ppDropTarget)
{
ppDropTarget = null;
}
void IDocHostUIHandler.GetExternal(out object ppDispatch)
{
//ppDispatch = new PopulateClass(this);
ppDispatch = null;
}
void IDocHostUIHandler.GetHostInfo(ref _DOCHOSTUIINFO pInfo)
{
}
void IDocHostUIHandler.GetOptionKeyPath(out string pchKey, uint dw)
{
pchKey = null;
}
void IDocHostUIHandler.HideUI()
{
}
void IDocHostUIHandler.OnDocWindowActivate(int fActivate)
{
}
void IDocHostUIHandler.OnFrameWindowActivate(int fActivate)
{
}
void IDocHostUIHandler.ResizeBorder(ref MsHtmHstInterop.tagRECT prcBorder,
IOleInPlaceUIWindow pUIWindow, int fRameWindow)
{
}
void IDocHostUIHandler.ShowContextMenu(uint dwID, ref
MsHtmHstInterop.tagPOINT ppt, object pcmdtReserved, object pdispReserved)
{
throw new COMException("", 0);
}
void IDocHostUIHandler.ShowUI(uint dwID, IOleInPlaceActiveObject
pActiveObject, IOleCommandTarget pCommandTarget, IOleInPlaceFrame pFrame,
IOleInPlaceUIWindow pDoc)
{
}
void IDocHostUIHandler.TranslateAccelerator(ref tagMSG lpmsg, ref Guid
pguidCmdGroup, uint nCmdID)
{
}
void IDocHostUIHandler.TranslateUrl(uint dwTranslate, ref ushort pchURLIn,
IntPtr ppchURLOut)
{
}
void IDocHostUIHandler.UpdateUI()
{
}
private void OnDocumentComplete(object sender,
AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent e)
{
this.Parent.Cursor = System.Windows.Forms.Cursors.Default;
ICustomDoc cDoc = (ICustomDoc)this.axWebBrowser.Document;
cDoc.SetUIHandler((IDocHostUIHandler)this);
// Get the document.
IHTMLDocument2 doc = (IHTMLDocument2)this.axWebBrowser.Document;
if (DocumentCompleteEvent!=null)
DocumentCompleteEvent(this, new
DocUIResponseArgs(doc.body.getAttribute("appref",0).ToString(),doc.body.getA
ttribute("appdata",0).ToString()));
foreach (DocUIHandler _h in this._delegatemap)
{
object _name = _h.AppRef;
mshtml.HTMLButtonElement _a =
(mshtml.HTMLButtonElement)doc.all.item(_name,null);
((mshtml.HTMLButtonElementEvents2_Event)_a).onclick += new
HTMLButtonElementEvents2_onclickEventHandler(this.Button_onclick);
}
}
public void RegisterUIHandler(string _appref,DocUIResponseHandler
_handler)
{
this._delegatemap.Add(new DocUIHandler(_appref,_handler));
}
public void RemoveUIHandlers()
{
this._delegatemap.Clear();
}
public delegate bool BrowserClickHandler( IHTMLEventObj e );
private bool Button_onclick(IHTMLEventObj e)
{
if (this.InvokeRequired == true)
{
this.BeginInvoke( new BrowserClickHandler(
this.Button_onclick ), new object[] { e } );
}
else
{
string _appref = e.srcElement.id;
if (_appref.Length>0)
{
foreach (DocUIHandler _h in this._delegatemap)
{
if (_h.AppRef == _appref)
{
e.cancelBubble = true;
_h.Handler(this,new
DocUIResponseArgs(e.srcElement.getAttribute("appref",0).ToString(),e.srcElem
ent.getAttribute("appdata",0).ToString()));
break;
}
}
}
}
return false;
}
}