Thanks a bunch, this was helpful but I'm still having trouble getting my
stuff wired together. Here's my main form:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Net;
namespace autofolio
{
public class MainForm : System.Windows.Forms.Form
{
private writeLog mylog;
private System.Windows.Forms.Label lbl_program_status;
private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MenuItem menuItem2;
private System.Windows.Forms.MenuItem menuItem5;
private System.Windows.Forms.MenuItem menuItem6;
private System.Windows.Forms.MenuItem menuItem7;
private System.Windows.Forms.MenuItem menuItem8;
private System.Windows.Forms.MenuItem menuItem9;
private System.Windows.Forms.MenuItem menuItem4;
private System.Windows.Forms.MenuItem menuItem3;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label lbl_portfolio;
private System.Windows.Forms.Label lbl_sessgains;
private System.Windows.Forms.Label lbl_sessstart;
private System.Windows.Forms.RichTextBox rt_log;
private System.Windows.Forms.RichTextBox rtf_portfoliotxt;
private System.Windows.Forms.Label lbl_tickerlist;
private System.ComponentModel.Container components = null;
public MainForm()
{
InitializeComponent();
mylog = new writeLog();
mylog.OnlogWrite += new logHandler(updateLogWindow);
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form 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()
{
this.lbl_program_status = new
System.Windows.Forms.Label();
this.mainMenu1 = new System.Windows.Forms.MainMenu
();
this.menuItem1 = new System.Windows.Forms.MenuItem
();
this.menuItem2 = new System.Windows.Forms.MenuItem
();
this.menuItem5 = new System.Windows.Forms.MenuItem
();
this.menuItem3 = new System.Windows.Forms.MenuItem
();
this.menuItem6 = new System.Windows.Forms.MenuItem
();
this.menuItem7 = new System.Windows.Forms.MenuItem
();
this.menuItem8 = new System.Windows.Forms.MenuItem
();
this.menuItem9 = new System.Windows.Forms.MenuItem
();
this.menuItem4 = new System.Windows.Forms.MenuItem
();
this.label1 = new System.Windows.Forms.Label();
this.rtf_portfoliotxt = new
System.Windows.Forms.RichTextBox();
this.lbl_portfolio = new System.Windows.Forms.Label
();
this.lbl_sessgains = new System.Windows.Forms.Label
();
this.lbl_sessstart = new System.Windows.Forms.Label
();
this.rt_log = new System.Windows.Forms.RichTextBox
();
this.lbl_tickerlist = new System.Windows.Forms.Label
();
this.SuspendLayout();
//
// lbl_program_status
//
this.lbl_program_status.Location = new
System.Drawing.Point(24, 408);
this.lbl_program_status.Name = "lbl_program_status";
this.lbl_program_status.Size = new
System.Drawing.Size(576, 16);
this.lbl_program_status.TabIndex = 1;
this.lbl_program_status.Text = "Autofolio Log";
//
// mainMenu1
//
this.mainMenu1.MenuItems.AddRange(new
System.Windows.Forms.MenuItem[] {
this.menuItem1,
this.menuItem5,
this.menuItem8});
//
// menuItem1
//
this.menuItem1.Index = 0;
this.menuItem1.MenuItems.AddRange(new
System.Windows.Forms.MenuItem[] {
this.menuItem2});
this.menuItem1.Text = "File";
//
// menuItem2
//
this.menuItem2.Index = 0;
this.menuItem2.Text = "Exit";
this.menuItem2.Click += new System.EventHandler
(this.menuItem2_Click);
//
// menuItem5
//
this.menuItem5.Index = 1;
this.menuItem5.MenuItems.AddRange(new
System.Windows.Forms.MenuItem[] {
this.menuItem3,
this.menuItem6,
this.menuItem7});
this.menuItem5.Text = "Trade";
//
// menuItem3
//
this.menuItem3.Index = 0;
this.menuItem3.Text = "Start Newsfeed Scans";
this.menuItem3.Click += new System.EventHandler
(this.menuItem3_Click);
//
// menuItem6
//
this.menuItem6.Index = 1;
this.menuItem6.Text = "Start Trading";
//
// menuItem7
//
this.menuItem7.Index = 2;
this.menuItem7.Text = "Forfeit Positions";
this.menuItem7.Click += new System.EventHandler
(this.menuItem7_Click);
//
// menuItem8
//
this.menuItem8.Index = 2;
this.menuItem8.MenuItems.AddRange(new
System.Windows.Forms.MenuItem[] {
this.menuItem9,
this.menuItem4});
this.menuItem8.Text = "Tools";
//
// menuItem9
//
this.menuItem9.Index = 0;
this.menuItem9.Text = "Options";
//
// menuItem4
//
this.menuItem4.Index = 1;
this.menuItem4.Text = "Set Thresholds";
//
// label1
//
this.label1.Location = new System.Drawing.Point(24,
40);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(168, 16);
this.label1.TabIndex = 3;
this.label1.Text = "Tickers In the News...";
//
// rtf_portfoliotxt
//
this.rtf_portfoliotxt.Location = new
System.Drawing.Point(216, 64);
this.rtf_portfoliotxt.Name = "rtf_portfoliotxt";
this.rtf_portfoliotxt.Size = new System.Drawing.Size
(688, 336);
this.rtf_portfoliotxt.TabIndex = 5;
this.rtf_portfoliotxt.Text = "";
//
// lbl_portfolio
//
this.lbl_portfolio.Location = new
System.Drawing.Point(216, 40);
this.lbl_portfolio.Name = "lbl_portfolio";
this.lbl_portfolio.Size = new System.Drawing.Size
(376, 16);
this.lbl_portfolio.TabIndex = 6;
this.lbl_portfolio.Text = "Current Portfolio";
//
// lbl_sessgains
//
this.lbl_sessgains.Location = new
System.Drawing.Point(920, 64);
this.lbl_sessgains.Name = "lbl_sessgains";
this.lbl_sessgains.Size = new System.Drawing.Size
(96, 23);
this.lbl_sessgains.TabIndex = 7;
this.lbl_sessgains.Text = "Session Gains:";
//
// lbl_sessstart
//
this.lbl_sessstart.Location = new
System.Drawing.Point(928, 80);
this.lbl_sessstart.Name = "lbl_sessstart";
this.lbl_sessstart.Size = new System.Drawing.Size
(88, 16);
this.lbl_sessstart.TabIndex = 8;
this.lbl_sessstart.Text = "Session Start:";
//
// rt_log
//
this.rt_log.Location = new System.Drawing.Point(24,
432);
this.rt_log.Name = "rt_log";
this.rt_log.Size = new System.Drawing.Size(880,
264);
this.rt_log.TabIndex = 9;
this.rt_log.Text = "";
//
// lbl_tickerlist
//
this.lbl_tickerlist.BackColor =
System.Drawing.Color.White;
this.lbl_tickerlist.Location = new
System.Drawing.Point(32, 72);
this.lbl_tickerlist.Name = "lbl_tickerlist";
this.lbl_tickerlist.Size = new System.Drawing.Size
(168, 328);
this.lbl_tickerlist.TabIndex = 10;
//
// MainForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(6,
15);
this.ClientSize = new System.Drawing.Size(1216,
736);
this.Controls.Add(this.lbl_tickerlist);
this.Controls.Add(this.rt_log);
this.Controls.Add(this.lbl_sessstart);
this.Controls.Add(this.lbl_sessgains);
this.Controls.Add(this.lbl_portfolio);
this.Controls.Add(this.rtf_portfoliotxt);
this.Controls.Add(this.label1);
this.Controls.Add(this.lbl_program_status);
this.Menu = this.mainMenu1;
this.Name = "MainForm";
this.Text = "Autofolio 1.0";
this.ResumeLayout(false);
}
#endregion
[STAThread]
static void Main()
{
Application.Run(new MainForm());
}
private void menuItem2_Click(object sender,
System.EventArgs e)
{
Application.Exit();
}
private void menuItem3_Click(object sender,
System.EventArgs e)
{
ArrayList currlist = new ArrayList();
fetch_tickers latestticker = new fetch_tickers
(currlist);
currlist=latestticker.fetch_list();
IEnumerator numerator = currlist.GetEnumerator();
if(currlist.Count!=0)
{
while(numerator.MoveNext())
{
this.lbl_tickerlist.Text=this.lbl_tickerlist.Text+
(numerator.Current.ToString()+Environment.NewLine);
}
}
}
public void updateLogWindow(object thisLog, loggerEventArgs
lea)
{
this.rt_log.Text += "Hello";// Environment.NewLine +
lea.logCaller + " -- " + lea.logData;
}
}
}
Here's my events and associated stuff:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Xml;
using System.Net;
using System.Text;
using System.IO;
using System.Text.RegularExpressions ;
using System.Diagnostics;
using System.Threading;
namespace autofolio
{
public delegate void logHandler(object sender, loggerEventArgs
lea);
public class fetch_tickers
{
private ArrayList currlist=new ArrayList();
private ArrayList newlist=new ArrayList();
private ArrayList urlist=new ArrayList();
public fetch_tickers(ArrayList currentlist)
{
this.currlist=currentlist;
}
public ArrayList fetch_list()
{
string begStr="";
string matchStr="";
string urlstring;
string storystring;
string tickerstring;
string storymatchstring;
WebRequest myRequest = WebRequest.Create
("
http://news.moneycentral.msn.com/breaking/breakingnews.asp");
// Return the response.
WebResponse myResponse = myRequest.GetResponse();
begStr=new StreamReader(myResponse.GetResponseStream
(),Encoding.Default).ReadToEnd();
writeLog mylog=new writeLog();
mylog.publish("Fetching latest ticker
list","fetch_tickers");
begStr = begStr.Replace("\n", "");
begStr=begStr.Replace("<font color=ff0020>","");
begStr=begStr.Replace("</font></font>","</font>");
matchStr="href\\s*=\\s*(?:\"(?<webpath>[^\"]*)\"|(?
<webpath>[^\\s>]+)[\\s>])";
new Regex(matchStr, RegexOptions.Compiled);
IEnumerator iEnumerator = Regex.Matches(begStr,
matchStr).GetEnumerator();
while(iEnumerator.MoveNext())
{
Match match=(Match)iEnumerator.Current;
if(iEnumerator.Current.ToString().IndexOf
("breakingnewsarticle")>0)
{
urlstring="
http://news.moneycentral.msn.com/breaking/"+
(match.Value.ToString().Substring(6,(match.Value.Length-8)));
//newlist.Add(urlstring);
urlist.Add(urlstring);
}
}//end while
IEnumerator numer2=urlist.GetEnumerator();
while(numer2.MoveNext())
{
WebRequest storytext=WebRequest.Create
(numer2.Current.ToString());
WebResponse
storyresponse=storytext.GetResponse();
storystring= new StreamReader
(storyresponse.GetResponseStream(),Encoding.Default).ReadToEnd();
storystring = storystring.Replace("\n", "");
storystring=storystring.Replace("<font
color=ff0020>","");
storystring=storystring.Replace("</font>
</font>","</font>");
storymatchstring="US:[A-Z.]*";
new Regex
(storymatchstring,RegexOptions.Compiled);
IEnumerator numer3=Regex.Matches
(storystring,storymatchstring).GetEnumerator();
while(numer3.MoveNext())
{
tickerstring=numer3.Current.ToString();
tickerstring=tickerstring.Remove(0,3);
if (!newlist.Contains(tickerstring))
{
newlist.Add(tickerstring);
}
}//end while
}//end while
myResponse.Close();
return this.newlist;
}//end method fetch_lest
}// end class fetch_tickers
public class appTimer
{
public delegate void appTimerHandler(object timer,
timerEventArgs timerArgs);
public event appTimerHandler OnFiveSecondLapse;
private int second=0;
public void start_clock()
{
for(;
{
Thread.Sleep(10);
DateTime dt=DateTime.Now;
if (dt.Second == this.second+5)
{
timerEventArgs thisTimer=new
timerEventArgs();
if (OnFiveSecondLapse !=null)
{
OnFiveSecondLapse
(this,thisTimer);
}
}
if (dt.Second == this.second+10)
{
this.second=dt.Second;
}
}
}
}
public class timerEventArgs : EventArgs
{
public timerEventArgs()
{
}
}
public class loggerEventArgs : EventArgs
{
public readonly string logData;
public readonly string logCaller;
public loggerEventArgs (string logString, string caller)
{
this.logCaller=caller;
this.logData=logString;
}
}
public class writeLog
{
private string _logData;
private string _logCaller;
public event logHandler OnlogWrite;
public writeLog()
{
}
public void publish(string logData, string caller)
{
this._logData=logData;
this._logCaller=caller;
//loggerEventArgs thislogevent = new loggerEventArgs
(this._logData,this._logCaller);
if(OnlogWrite != null)
{
OnlogWrite(this,new loggerEventArgs(this.
_logData,this._logCaller));
}
}
}
}//end namespace
But my event doesn't fire. Any clues?