Join Now
Quality Rating:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)
Expertise Level:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)

This page was last modified 10:56, 27 June 2008.

How to create Label

From Forum Nokia Wiki

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 SetTextL(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
    CreateWindowL();
 
    _LIT(KTextHelloWorld, "hello world");
    iLabel = new (ELeave) CEikLabel;
    iLabel->SetContainerWindowL( *this );
    iLabel->SetTextL(KTextHelloWorld);
    
    // Set the windows size
    SetRect( aRect );
 
    // Activate the window, which makes it ready to be drawn
    ActivateL();
}
 
CLabelTestAppView::~CLabelTestAppView()
{
    delete iLabel;
}
 
void CLabelTestAppView::SizeChanged()
{  
    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;
    default:
        return NULL;
    }
}
 
//Call this function to change value of Label
void CLabelTestAppView::SetTextL(const TDesC& aText)
{
   iLabel->SetTextL(aText);
}

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


Related Discussions
Thread Thread Starter Forum Replies Last Post
Text isn't displayed properly schnesim General Symbian C++ 21 2008-06-28 08:59
how to add Text to CEikLabel ? liuxingyu_best Symbian User Interface 2 2008-08-20 15:16
How to change field's label foreground color (FORM)? sliponoga Symbian User Interface 2 2006-05-16 09:33
ListBox in CAknDialog fills up whole dialog Juggle4Evr1 Symbian User Interface 1 2003-05-16 10:15
how to update screen ceehira General Symbian C++ 2 2005-07-11 09:04
 
Powered by MediaWiki
     
     RDF Facets:
     
     
     qfnZtypeQUqfnTypeZCommunityContentQ
     qfnZtypeQUqfnTypeZWebpageQ
     qfnZtypeQUqfnTypeZWikiContentQ
     qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX