event ButtonClick (Ed as Editor, Key as Variant)
Occurs when the user clicks the editor's button.

 TypeDescription 
   Ed as Editor An Editor object where the event occurs.  
   Key as Variant A string expression that indicates the key of the button being pressed.   
The ButtonClick event notifies your application that the user clicks a button. The AddButton method inserts new buttons to the editor. Use the RemoveButton method to remove a button. The ButtonClick event is fired if the user presses the drop down button of an editor. In this case, the Key parameter is empty. Use the Change event to notify your application that the editor's content is altered. If the editor hosts an ActiveX control use the UserEditorOleEvent event to monitor the events that inside ActiveX object fires.

The following VB sample displays the key of the button being clicked:

Private Sub Form_Load()
    With Record1
        With .Add("Calc", CalculatorType)
            .Value = 3.14
            .AddButton "AKey", , 1
            .AddButton "BKey", , 2
        End With
    End With
End Sub

Private Sub Record1_ButtonClick(ByVal Ed As EXRECORDLibCtl.IEditor, ByVal Key As Variant)
    Debug.Print Ed.Label & ", Key = """ & Key & """"
End Sub

The following VC sample displays the key of the button being clicked:

COleVariant vtMissing; vtMissing.vt = VT_ERROR;
CEditor editor = m_record.Add(COleVariant("Calc"), /*CalculatorType*/ 21, vtMissing );
editor.SetValue( COleVariant( 3.14 ) );
editor.AddButton( COleVariant( "AKey" ), vtMissing, COleVariant( (long) 1 ), vtMissing, vtMissing, vtMissing );
editor.AddButton( COleVariant( "BKey" ), vtMissing, COleVariant( (long) 1 ), vtMissing, vtMissing, vtMissing );

static CString V2S( VARIANT* pv, LPCTSTR szDefault = _T("") )
{
	if ( pv )
	{
		if ( pv->vt == VT_ERROR )
			return szDefault;

		COleVariant vt;
		vt.ChangeType( VT_BSTR, pv );
		return V_BSTR( &vt );
	}
	return szDefault;
}

void OnButtonClickRecord1(LPDISPATCH Ed, const VARIANT FAR& Key) 
{
	CEditor editor( Ed );
	editor.m_bAutoRelease = FALSE;

	TCHAR szOutput[1024];
	wsprintf( szOutput, "%s, Key = \"%s\"\n", (LPCTSTR)editor.GetLabel(), (LPCTSTR)V2S( &(VARIANT&)Key ) );
	OutputDebugString( szOutput );
	
}

Send comments on this topic.
© 1999-2007 Exontrol Inc, Software. All rights reserved.