Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.

Revision as of 08:36, 2 August 2012 by izinin (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

How to create Label

From Wiki
Jump to: navigation, search
Article Metadata
Created: kiran10182 (27 Jun 2008)
Last edited: izinin (02 Aug 2012)
Reviewer Approved    Thumbs up icon sm.jpg

Following code snippet shows how to create Label control in Symbian C++.

Step 1: LabelTestAppView.h

  • Open your LabelTestAppView.h file.
  • Include entries for required header files.
#include <eiklabel.h>
  • Add required functions which will be needed for control.
TInt CountComponentControls() const;
CCoeControl* ComponentControl(TInt aIndex) const;
void PutTextL(const TDesC& aText); // To change text(user-inputted)
  • Declare object of Label:
private: // data
// ..
CEikLabel* iLabel;

Step 2: LabelTestAppView.cpp

  • Open your "LabelTestAppView.cpp" file.
  • Now in the ContructL() function of your LabelTestAppView.cpp file:
void CLabelTestAppView::ConstructL( const TRect& aRect )
// Create a window for this application view
_LIT(KTextHelloWorld, "hello world");
iLabel = new (ELeave) CEikLabel;
iLabel->SetContainerWindowL( *this );
// Set the windows size
SetRect( aRect );
// Activate the window, which makes it ready to be drawn
delete iLabel;
void CLabelTestAppView::SizeChanged()
//NOTE: the first time SizeChanged comes when iLabel has not created yet
iLabel->SetExtent( TPoint(0,0), iLabel->MinimumSize());
TInt CLabelTestAppView::CountComponentControls() const
return 1;
CCoeControl* CLabelTestAppView::ComponentControl(TInt aIndex) const
switch ( aIndex )
case 0:
return iLabel;
return NULL;
//Call this function to change value of Label
void CLabelTestAppView::PutTextL(const TDesC& aText)

Note: Do not forget to add an entry for eikcoctl.lib in your .mmp file.

This page was last modified on 2 August 2012, at 08:36.
33 page views in the last 30 days.