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.Navi gate("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 DocUIResponseAr gs : System.EventArg s
{
private string _appref;
private string _appdata;
public DocUIResponseAr gs(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 DocUIResponseHa ndler _handler;
public DocUIHandler(st ring _r, DocUIResponseHa ndler _h)
{
this._appref = _r;
this._handler = _h;
}
public string AppRef
{
get { return this._appref; }
}
public DocUIResponseHa ndler Handler
{
get { return this._handler; }
}
}
public delegate void DocUIResponseDe legate(object sender, DocUIResponseAr gs
e);
public delegate void DocumentComplet eDelegate(objec t sender,
DocUIResponseAr gs e);
public delegate void DocUIResponseHa ndler(object sender, DocUIResponseAr gs
e);
/// <summary>
/// Summary description for WebControl.
/// </summary>
public class WebControl : System.Windows. Forms.UserContr ol,
IDocHostUIHandl er
{
private string _urlbase;
private AxSHDocVw.AxWeb Browser axWebBrowser;
private System.Collecti ons.ArrayList _delegatemap;
public event DocumentComplet eDelegate DocumentComplet eEvent;
/// <summary>
/// Required designer variable.
/// </summary>
private System.Componen tModel.Containe r components = null;
public WebControl()
{
// This call is required by the Windows.Forms Form Designer.
InitializeCompo nent();
this._delegatem ap = new ArrayList();
_urlbase =
System.Configur ation.Configura tionSettings.Ap pSettings["Accuman.Web.Se rver"]
;
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Disp ose();
}
}
base.Dispose( disposing );
}
public void Navigate(string _url, string _valuedatapairs )
{
//_delegatemap.Cl ear();
object _ourl = this._urlbase+_ url;
object _onull = new object();
object _header = "Content-Type: application/x-www-form-urlencoded" + "\n"
+ "\r";
string _data =_valuedatapair s;
object _odata = System.Text.ASC IIEncoding.ASCI I.GetBytes(_dat a);
this.axWebBrows er.Navigate2(re f _ourl,ref _onull,ref _onull,ref
_odata,ref _header);
}
public void RefreshPage()
{
object _onull = null;
this.axWebBrows er.Refresh2(ref _onull);
}
public void SetFormFieldVal ue(string _fieldid, string _value)
{
IHTMLDocument2 doc = (IHTMLDocument2 )this.axWebBrow ser.Document;
mshtml.HTMLInpu tElementClass _f =
(mshtml.HTMLInp utElementClass) doc.all.item(_f ieldid,null);
_f.value = _value;
}
public void SubmitForm(stri ng _formid)
{
IHTMLDocument2 doc = (IHTMLDocument2 )this.axWebBrow ser.Document;
mshtml.HTMLForm ElementClass _f =
(mshtml.HTMLFor mElementClass)d oc.forms.item(n ull,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 InitializeCompo nent()
{
System.Resource s.ResourceManag er resources = new
System.Resource s.ResourceManag er(typeof(WebCo ntrol));
this.axWebBrows er = new AxSHDocVw.AxWeb Browser();
((System.Compon entModel.ISuppo rtInitialize)(t his.axWebBrowse r)).BeginInit() ;
this.SuspendLay out();
//
// axWebBrowser
//
this.axWebBrows er.Dock = System.Windows. Forms.DockStyle .Fill;
this.axWebBrows er.Enabled = true;
this.axWebBrows er.Location = new System.Drawing. Point(0, 0);
//this.axWebBrows er.OcxState =
((System.Window s.Forms.AxHost. State)(resource s.GetObject("ax WebBrowser.OcxS t
ate")));
this.axWebBrows er.Size = new System.Drawing. Size(150, 150);
this.axWebBrows er.TabIndex = 0;
this.axWebBrows er.DocumentComp lete += new
AxSHDocVw.DWebB rowserEvents2_D ocumentComplete EventHandler(th is.OnDocumentCo m
plete);
//
// WebControl
//
this.Controls.A dd(this.axWebBr owser);
this.Name = "WebControl ";
((System.Compon entModel.ISuppo rtInitialize)(t his.axWebBrowse r)).EndInit();
this.ResumeLayo ut(false);
}
#endregion
// IDocHostUIHandl er Implementations
void IDocHostUIHandl er.EnableModele ss(int fEnable)
{
}
void IDocHostUIHandl er.FilterDataOb ject(MsHtmHstIn terop.IDataObje ct pDO,
out MsHtmHstInterop .IDataObject ppDORet)
{
ppDORet = null;
}
void IDocHostUIHandl er.GetDropTarge t(IDropTarget pDropTarget, out
IDropTarget ppDropTarget)
{
ppDropTarget = null;
}
void IDocHostUIHandl er.GetExternal( out object ppDispatch)
{
//ppDispatch = new PopulateClass(t his);
ppDispatch = null;
}
void IDocHostUIHandl er.GetHostInfo( ref _DOCHOSTUIINFO pInfo)
{
}
void IDocHostUIHandl er.GetOptionKey Path(out string pchKey, uint dw)
{
pchKey = null;
}
void IDocHostUIHandl er.HideUI()
{
}
void IDocHostUIHandl er.OnDocWindowA ctivate(int fActivate)
{
}
void IDocHostUIHandl er.OnFrameWindo wActivate(int fActivate)
{
}
void IDocHostUIHandl er.ResizeBorder (ref MsHtmHstInterop .tagRECT prcBorder,
IOleInPlaceUIWi ndow pUIWindow, int fRameWindow)
{
}
void IDocHostUIHandl er.ShowContextM enu(uint dwID, ref
MsHtmHstInterop .tagPOINT ppt, object pcmdtReserved, object pdispReserved)
{
throw new COMException("" , 0);
}
void IDocHostUIHandl er.ShowUI(uint dwID, IOleInPlaceActi veObject
pActiveObject, IOleCommandTarg et pCommandTarget, IOleInPlaceFram e pFrame,
IOleInPlaceUIWi ndow pDoc)
{
}
void IDocHostUIHandl er.TranslateAcc elerator(ref tagMSG lpmsg, ref Guid
pguidCmdGroup, uint nCmdID)
{
}
void IDocHostUIHandl er.TranslateUrl (uint dwTranslate, ref ushort pchURLIn,
IntPtr ppchURLOut)
{
}
void IDocHostUIHandl er.UpdateUI()
{
}
private void OnDocumentCompl ete(object sender,
AxSHDocVw.DWebB rowserEvents2_D ocumentComplete Event e)
{
this.Parent.Cur sor = System.Windows. Forms.Cursors.D efault;
ICustomDoc cDoc = (ICustomDoc)thi s.axWebBrowser. Document;
cDoc.SetUIHandl er((IDocHostUIH andler)this);
// Get the document.
IHTMLDocument2 doc = (IHTMLDocument2 )this.axWebBrow ser.Document;
if (DocumentComple teEvent!=null)
DocumentComplet eEvent(this, new
DocUIResponseAr gs(doc.body.get Attribute("appr ef",0).ToString (),doc.body.get A
ttribute("appda ta",0).ToString ()));
foreach (DocUIHandler _h in this._delegatem ap)
{
object _name = _h.AppRef;
mshtml.HTMLButt onElement _a =
(mshtml.HTMLBut tonElement)doc. all.item(_name, null);
((mshtml.HTMLBu ttonElementEven ts2_Event)_a).o nclick += new
HTMLButtonEleme ntEvents2_oncli ckEventHandler( this.Button_onc lick);
}
}
public void RegisterUIHandl er(string _appref,DocUIRe sponseHandler
_handler)
{
this._delegatem ap.Add(new DocUIHandler(_a ppref,_handler) );
}
public void RemoveUIHandler s()
{
this._delegatem ap.Clear();
}
public delegate bool BrowserClickHan dler( IHTMLEventObj e );
private bool Button_onclick( IHTMLEventObj e)
{
if (this.InvokeReq uired == true)
{
this.BeginInvok e( new BrowserClickHan dler(
this.Button_onc lick ), new object[] { e } );
}
else
{
string _appref = e.srcElement.id ;
if (_appref.Length >0)
{
foreach (DocUIHandler _h in this._delegatem ap)
{
if (_h.AppRef == _appref)
{
e.cancelBubble = true;
_h.Handler(this ,new
DocUIResponseAr gs(e.srcElement .getAttribute(" appref",0).ToSt ring(),e.srcEle m
ent.getAttribut e("appdata",0). ToString()));
break;
}
}
}
}
return false;
}
}
"Brian F" <ss*******@Yaho o.com> wrote in message
news:93******** *************** ***@posting.goo gle.com...
Exactly what the subject says.
I have an ASP page that I want my C# windows application to open in
Internet Explorer, and if possible have it send along a list of values
from a list box. Thank you.