×
Namespaces

Variants
Actions
(Difference between revisions)

How to create Label

From Nokia Developer Wiki
Jump to: navigation, search
kiran10182 (Talk | contribs)
(Step 2: LabelTestAppView.cpp: SizeChanged() modified)
Bogdanovich_Ilya (Talk | contribs)
m
Line 15: Line 15:
 
TInt CountComponentControls() const;
 
TInt CountComponentControls() const;
 
CCoeControl* ComponentControl(TInt aIndex) const;
 
CCoeControl* ComponentControl(TInt aIndex) const;
void SetText(const TDesC& aText); // To change text(user-inputted)
+
void SetTextL(const TDesC& aText); // To change text(user-inputted)
 
</code>
 
</code>
  
Line 77: Line 77:
  
 
//Call this function to change value of Label
 
//Call this function to change value of Label
void CLabelTestAppView::SetText(const TDesC& aText)
+
void CLabelTestAppView::SetTextL(const TDesC& aText)
 
{
 
{
 
   iLabel->SetTextL(aText);
 
   iLabel->SetTextL(aText);

Revision as of 13:56, 27 June 2008

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.


87 page views in the last 30 days.
×