property Control.CloseOn as CloseOnEnum
Indicates when the control is closed.

 TypeDescription 
   CloseOnEnum A CloseOnEnum expression that indicates the way how the control is closed.  

Use the CloseOn property to specify how to close an item that hosts an ActiveX control. By default, the CloseOn property is exLButtonDblClk, and that means that the popup menu is closed if the user double clicks the ActiveX control. Use the SelectOn property to specify whether the control selects an item when user presses or releases the mouse button.

The following VB sample changes the item's caption when user double clicks a new date in a MSCal.Calendar control:

Private Sub ExMenu1_OleEvent(ByVal ID As Long, ByVal Ev As EXMENULibCtl.IOleEvent)
    If Ev.Name = "DblClick" Then
        With ExMenu1.Item(ID)
            .Caption = "Date: <b>" & .SubControl.Object.Value & "</b>"
        End With
    End If
End Sub

Private Sub Form_Load()
    With ExMenu1
        With .Items.Add("Date: <b>" & Date & "</b>", ItemTypeEnum.SubControl, 0).SubControl
            .CloseOn = exLButtonDblClk
            .Width = 256
            .Height = 256
            .ControlID = "MSCal.Calendar"
            .Create
        End With
        .Refresh
    End With
End Sub

The following C++ sample changes the item's caption when user double clicks a new date in a MSCal.Calendar control:

#import <exmenu.dll>
#import <mscal.ocx>
void OnOleEventExmenu1(long ID, LPDISPATCH Ev) 
{
	EXMENULib::IOleEventPtr spEvent( Ev );
	CString strName( spEvent->GetName().operator const char *() );
	if ( strName == _T("DblClick") ) 
	{
		CItem item = m_menu.GetItem( COleVariant( ID ) );
		MSACAL::ICalendarPtr spCalendar( item.GetSubControl().GetObject() );
		if ( spCalendar != NULL )
		{
			COleVariant vtValue;
			spCalendar->get_Value( &vtValue );
			item.SetCaption( V2S( vtValue ) );
		}
	}
}

The C++ sample requires #import <exmenu.dll> statement to include definitions for OleEvent and OleEventParam objects. The #import <mscal.ocx> statement imports definition for all objects in the MSCAL.Calendar library. 

The V2S function converts a Variant expression to a string value:

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;
}

The following VB.NET sample changes the item's caption when user double clicks a new date in a MSCal.Calendar control:

Private Sub AxExMenu1_OleEvent(ByVal sender As Object, ByVal e As AxEXMENULib._IMenuEvents_OleEventEvent) Handles AxExMenu1.OleEvent
    If e.ev.Name = "DblClick" Then
        With AxExMenu1.item(e.iD)
            .Caption = "Date: <b>" & .SubControl.Object.Value & "</b>"
        End With
    End If
End Sub

The following C# sample changes the item's caption when user double clicks a new date in a MSCal.Calendar control:

private void axExMenu1_OleEvent(object sender, AxEXMENULib._IMenuEvents_OleEventEvent e)
{
	if (e.ev.Name == "DblClick")
	{
		EXMENULib.item item = axExMenu1[e.iD];
		MSACAL.Calendar cal = item.SubControl.Object as MSACAL.Calendar;
		if (cal != null)
			item.Caption = cal.Value.ToString();
	}
}

the C# sample requires adding a new reference to MSCAL.Calendar library. Select the "Project\Add Reference..." and add the Microsoft Calendar Control.  

The following VFP sample changes the item's caption when user double clicks a new date in a MSCal.Calendar control:

*** ActiveX Control Event ***
LPARAMETERS id, ev

With Ev
	if ( .Name = "DblClick" ) 
		with thisform.ExMenu1.Item(id)
			.Caption = .SubControl.Object.Value
		endwith
	endif
EndWith

 


Send comments on this topic.
1999-2015 Exontrol.COM, Software. All rights reserved.