Page 1 of 1

Adding MouseDown Event Handler to dynamically created TChart

Posted: Mon Mar 05, 2007 11:26 pm
by 9532498
I've created a TChart object dynamically with m_Chart1.Create.

I need to add an event handler in the code for MouseDown events.. How do I do this?

Posted: Tue Mar 06, 2007 10:01 am
by narcis
Hi nbp,

You should add a method like the one below at your unit:

Code: Select all

    procedure Chart1MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
Implement the method like this:

Code: Select all

procedure TForm1.Chart1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin

end;
And finally assign the event to the chart:

Code: Select all

  Chart1.OnMouseMove:=Chart1MouseMove;

Posted: Tue Mar 06, 2007 3:15 pm
by 9532498
Sorry, I should have posted this on the ActiveX forum. I have added the Tchart (ActiveX) component dynamically with mChart1.Create();
I'm using Visual C++ 6.0 and when I try to add the mouse event handler the way you describe,
mChart1.OnMouseMove = MyMouseMouseFunction;

I get an error saying " = overloaded operator" Do I need to do something different because I'm working with an ActiveX component? I read somewhere that I need to add the event sink map manually to my class??
--nbp

Posted: Mon Mar 19, 2007 3:37 pm
by narcis
Hi nbp,

We have looked at this. Unfortunately dynamically creating events in Microsoft's VC++ is somewhat beyond the scope of our experience. The issue would apply generically to any ActiveX Control so perhaps you might be able to obtain additional help on Microsoft public forums.

As a suggestion to a line of investigation please note that the standard way to setup the event would be via the EVENTSINK_MAP.

ie.

Code: Select all

BEGIN_EVENTSINK_MAP(CDraggingDlg, CDialog)
  ON_EVENT(CDraggingDlg, IDC_TCHART, 1 /*OnAfterDraw*/, OnAfterDrawTChart,
VTS_NONE)
END_EVENTSINK_MAP()
It may be possible to set the events once for IDC_TCHART and re-use the IDC_TCHART for your dynamic Charts as the setting can be programmatically
accessed:

eg.

Code: Select all

void CDraggingDlg::DoDataExchange(CDataExchange* pDX) {
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDraggingDlg)
	DDX_Control(pDX, IDC_TCHART, m_ctrlChart);
	//}}AFX_DATA_MAP
}
Here you may be able to call and substitute m_ctrlChart for your dynamic instance of the Chart.