property Node.Picture as Variant
Retrieves or sets a graphic to be displayed in the node.

 TypeDescription 
   Variant A VARIANT value that indicates the picture in the following formats:
  • A picture object being displayed in the node ( IPicture interface )
  • A safe array of bytes that indicates the OLE Object field. Use for OLE objects (such as Microsoft Word documents, Microsoft Excel spreadsheets, pictures, sounds, or other binary data) that were created in other programs using the OLE protocol.
  • A string expression that specifies the key of the picture being inserted using the HTMLPicture property
  • A string expression that indicates the picture's file path
  • A string expression that indicates the base64 encoded string that holds the picture. Use the eximages tool to save your icons as base64 encoded format. 
 

Use the Picture property to load an user defined picture to a node. Use the Image property to display a 16x16 icon in the node. Use the PictureAlignment property to align the picture in the node. Also, you can assign a picture to a node when calling Add method. Use the BackColor property to specify the node's background color. Use the Picture property to display a picture on the control's background. Use the Caption property to assign a caption to a node. You can insert custom sized pictures inside HTML captions using the <img> built-in HTML format. The Picture property supports: BMP,  EMF,  EXIF, GIF, ICON, JPEG, PNG, TIFF or WMF formats. The PictureWidth and PictureHeight properties controls the size of displayed picture. The PictureWidthNode and PictureHeightNode properties of the ChartView object handles the size of the displayed pictures for all the nodes.

If using the /NET assembly version, you can pass an System.Drawing.Image object to the Picture property like: .Nodes.Add("Child2", .Root, "21").Picture = PictureBox1.Image 

The size of the picture being shown in the node is computed as follow:

In any case, the size of the picture is also influenced by the the aspect ratio for the node's picture as it is specified by PictureAspectRatio or PictureAspectRatioNode property while any of these is not exAspectRatioNone.

The following VB sample loads icons and pictures using the BASE64 encoded strings:

Run the sample and you get:

The following two VB samples are equivalents:

With ChartView1
        With .Nodes
            With .Add("<r><dotline><b><fgcolor=0000FF>Andrew Fuller</fgcolor></b><br><solidline><b>Title</b>:<r><fgcolor=FF0000>Vice President Sales</fgcolor><br>USA, Tacoma, WA, 98401, 908 W. Capital Way<br><dotline><upline><b>Phone:</b><r>(206) 555-9482", , , 1, "c:\temp\sample\andrew.gif")
                .BackColor = vbWhite
            End With
        End With
End With

With ChartView1
        With .Nodes
            With .Add("<r><dotline><b><fgcolor=0000FF>Andrew Fuller</fgcolor></b><br><solidline><b>Title</b>:<r><fgcolor=FF0000>Vice President Sales</fgcolor><br>USA, Tacoma, WA, 98401, 908 W. Capital Way<br><dotline><upline><b>Phone:</b><r>(206) 555-9482", , , 1)
                .BackColor = vbWhite
                .Picture = "c:\temp\sample\andrew.gif"
            End With
        End With
    End With

I am wondering how to add a bitmap to a node without using an image list? Actually from a CBitmap that I already have. The idea is to get an IPicture object that displays that HBITMAP handle, so we have to use the OleCreatePictureIndirect API function that does the job. We can use the CPictureHolder class, already defined in the afxctl.h file, or we can use a direct function IPictureFromCBitmap as defined bellow.

  1. Using the CPictureHolder class
    #include <afxctl.h>
    CPictureHolder pict;
    if ( pict.CreateFromBitmap( (HBITMAP)bitmap.Detach() ) )
    {
    	COleVariant vtPicture;
    	V_VT( &vtPicture ) = VT_DISPATCH;
    	(V_DISPATCH( &vtPicture ) = pict.GetPictureDispatch() )->AddRef();
    	node.SetPicture( vtPicture );
    }
  2. Using the IPictureFromCBitmap function
    #include <atlbase.h>
    CComVariant IPictureFromCBitmap( CBitmap* p )
    {
    	if ( NULL != p )
    	{
    		PICTDESC pDesc = {0};
    		pDesc.cbSizeofstruct = sizeof( PICTDESC );
    		pDesc.picType = PICTYPE_BITMAP;
    		pDesc.bmp.hbitmap = (HBITMAP)p->Detach();
    		CComPtr<IPicture> spPicture;
    		if ( SUCCEEDED( OleCreatePictureIndirect( &pDesc, IID_IPicture, FALSE, (LPVOID*)&spPicture ) ) )
    			return CComVariant( CComQIPtr<IDispatch>( spPicture ) );
    	}
    	return NULL;
    }

    and you call something like node.SetPicture( IPictureFromCBitmap( &bitmap ) );

where the node member is the node in the control to put the picture, and the bitmap is an object of CBitmap type.

 


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