多行文本框的应用。可以修改字体型号,字体颜色,行间距
2011-06-22 22:21
585 查看
//---------------------------------------实例化--------------------------------------------
iREdit1.SetRect(TPoint(50, 50), TSize(260, 200));
iEdit1 = new (ELeave) CMyEdwin;
iEdit1->SetContainerWindowL(*this);
TResourceReader reader;
iEikonEnv->CreateResourceReaderLC(reader, R_UTFJJWVX_CONTAINER_EDIT1);
iEdit1->ConstructFromResourceL(reader);
CleanupStack::PopAndDestroy(); // reader internal state
iEdit1->SetFocus(ETrue);
//--------修改字体型号、颜色--------
//CFont* sFont = (CFont*) CEikonEnv::Static()->DenseFont();
CFont* sFont = (CFont*) LatinBold16();
TFontSpec sFontSpec = sFont->FontSpecInTwips();
TCharFormat format;
Mem::FillZ(&format, sizeof(TCharFormat));
TCharFormatMask mask;
Mem::FillZ(&mask, sizeof(TCharFormatMask));
format.iFontSpec.iTypeface = sFontSpec.iTypeface;
TInt nHeight = sFontSpec.iHeight;
format.iFontSpec.iHeight = sFontSpec.iHeight;
format.iFontPresentation.iTextColor = TLogicalRgb(TRgb(238, 84, 0)); //修改字体颜色
mask.SetAttrib(EAttColor);
mask.SetAttrib(EAttFontTypeface);
mask.SetAttrib(EAttFontHeight);
CCharFormatLayer * layer = CCharFormatLayer::NewL(format, mask);
iEdit1->SelectAllL();
iEdit1->SetCharFormatLayer(layer);
//--------修改多行文本框的行间距--------
TParaFormatMask mask2;
mask2.SetAll();
CParaFormat* iFormat = CParaFormat::NewL();
iFormat->iLineSpacingInTwips = 20;
CParaFormatLayer * iFormatLayer = CParaFormatLayer::NewL(iFormat, mask2);
iEdit1->SetParaFormatLayer(iFormatLayer);
//-------------------------------------
iEdit1->SetRect(iREdit1);
//---------------------------------------头文件-------------------------------------------
#ifndef MYEDWIN_H
#define MYEDWIN_H
// INCLUDES
#include <EIKRTED.H>
// CLASS DECLARATION
class CMyEdwin : public CEikRichTextEditor
{
protected:
CLafEdwinCustomDrawBase* CreateCustomDrawL();
};
#endif
//---------------------------------------定义文件-------------------------------------------
// INCLUDE FILES
#include <eikenv.h>
#include "MyEdwin.h"
// =================== CUSTOM DRAW =========================
class CMyCustomDraw : public CLafEdwinCustomDrawBase
{
public:
static CMyCustomDraw
* NewL(const MLafEnv& aEnv, const CCoeControl& aControl);
~CMyCustomDraw();
public:
// from MFormCustomDraw
void DrawBackground(const TParam& aParam, const TRgb& aBackground,
TRect& aDrawn) const;
TRgb SystemColor(TUint aColorIndex, TRgb aDefaultColor) const;
public:
void LineSpacingChanged();
private:
CMyCustomDraw(const MLafEnv& aEnv, const CCoeControl& aControl);
void ConstructL();
private:
CFbsBitmap* iBitmap;
};
CMyCustomDraw* CMyCustomDraw::NewL(const MLafEnv& aEnv,
const CCoeControl& aControl)
{
CMyCustomDraw* self = new (ELeave) CMyCustomDraw(aEnv, aControl);
CleanupStack::PushL(self);
self->ConstructL();
CleanupStack::Pop(self);
return self;
}
CMyCustomDraw::~CMyCustomDraw()
{
if (iBitmap)
{
delete iBitmap;
iBitmap = NULL;
}
}
void CMyCustomDraw::DrawBackground(const TParam& aParam,
const TRgb& aBackground, TRect& aDrawn) const
{
CLafEdwinCustomDrawBase::DrawBackground(aParam, aBackground, aDrawn);
/*
if ((iBitmap != NULL) && (iBitmap->Handle() != 0))
{
TRect rect = TRect(TPoint(0, 0), iBitmap->SizeInPixels());
aParam.iGc.SetClippingRect(aParam.iDrawRect);
aParam.iGc.DrawBitmap(rect, iBitmap);
}
*/
}
TRgb CMyCustomDraw::SystemColor(TUint aColorIndex, TRgb aDefaultColor) const
{
return CLafEdwinCustomDrawBase::SystemColor(aColorIndex, aDefaultColor);
}
void CMyCustomDraw::LineSpacingChanged()
{
CLafEdwinCustomDrawBase::LineSpacingChanged();
}
CMyCustomDraw::CMyCustomDraw(const MLafEnv& aEnv, const CCoeControl& aControl) :
CLafEdwinCustomDrawBase(aEnv, aControl)
{
}
void CMyCustomDraw::ConstructL()
{
/*
#ifdef _DEBUG
_LIT(KMbmFile, "z://resource//apps//Utfjjwvx.mbm");
#else
_LIT(KMbmFile, "c://resource//apps//Utfjjwvx.mbm");
#endif
iBitmap = new (ELeave) CFbsBitmap;
TInt err = iBitmap->Load(KMbmFile, );
User::LeaveIfError(err);
*/
iBitmap = NULL;
}
// ================= MEMBER FUNCTIONS =======================
CLafEdwinCustomDrawBase* CMyEdwin::CreateCustomDrawL()
{
return CMyCustomDraw::NewL(iEikonEnv->LafEnv(), *this);
}
iREdit1.SetRect(TPoint(50, 50), TSize(260, 200));
iEdit1 = new (ELeave) CMyEdwin;
iEdit1->SetContainerWindowL(*this);
TResourceReader reader;
iEikonEnv->CreateResourceReaderLC(reader, R_UTFJJWVX_CONTAINER_EDIT1);
iEdit1->ConstructFromResourceL(reader);
CleanupStack::PopAndDestroy(); // reader internal state
iEdit1->SetFocus(ETrue);
//--------修改字体型号、颜色--------
//CFont* sFont = (CFont*) CEikonEnv::Static()->DenseFont();
CFont* sFont = (CFont*) LatinBold16();
TFontSpec sFontSpec = sFont->FontSpecInTwips();
TCharFormat format;
Mem::FillZ(&format, sizeof(TCharFormat));
TCharFormatMask mask;
Mem::FillZ(&mask, sizeof(TCharFormatMask));
format.iFontSpec.iTypeface = sFontSpec.iTypeface;
TInt nHeight = sFontSpec.iHeight;
format.iFontSpec.iHeight = sFontSpec.iHeight;
format.iFontPresentation.iTextColor = TLogicalRgb(TRgb(238, 84, 0)); //修改字体颜色
mask.SetAttrib(EAttColor);
mask.SetAttrib(EAttFontTypeface);
mask.SetAttrib(EAttFontHeight);
CCharFormatLayer * layer = CCharFormatLayer::NewL(format, mask);
iEdit1->SelectAllL();
iEdit1->SetCharFormatLayer(layer);
//--------修改多行文本框的行间距--------
TParaFormatMask mask2;
mask2.SetAll();
CParaFormat* iFormat = CParaFormat::NewL();
iFormat->iLineSpacingInTwips = 20;
CParaFormatLayer * iFormatLayer = CParaFormatLayer::NewL(iFormat, mask2);
iEdit1->SetParaFormatLayer(iFormatLayer);
//-------------------------------------
iEdit1->SetRect(iREdit1);
//---------------------------------------头文件-------------------------------------------
#ifndef MYEDWIN_H
#define MYEDWIN_H
// INCLUDES
#include <EIKRTED.H>
// CLASS DECLARATION
class CMyEdwin : public CEikRichTextEditor
{
protected:
CLafEdwinCustomDrawBase* CreateCustomDrawL();
};
#endif
//---------------------------------------定义文件-------------------------------------------
// INCLUDE FILES
#include <eikenv.h>
#include "MyEdwin.h"
// =================== CUSTOM DRAW =========================
class CMyCustomDraw : public CLafEdwinCustomDrawBase
{
public:
static CMyCustomDraw
* NewL(const MLafEnv& aEnv, const CCoeControl& aControl);
~CMyCustomDraw();
public:
// from MFormCustomDraw
void DrawBackground(const TParam& aParam, const TRgb& aBackground,
TRect& aDrawn) const;
TRgb SystemColor(TUint aColorIndex, TRgb aDefaultColor) const;
public:
void LineSpacingChanged();
private:
CMyCustomDraw(const MLafEnv& aEnv, const CCoeControl& aControl);
void ConstructL();
private:
CFbsBitmap* iBitmap;
};
CMyCustomDraw* CMyCustomDraw::NewL(const MLafEnv& aEnv,
const CCoeControl& aControl)
{
CMyCustomDraw* self = new (ELeave) CMyCustomDraw(aEnv, aControl);
CleanupStack::PushL(self);
self->ConstructL();
CleanupStack::Pop(self);
return self;
}
CMyCustomDraw::~CMyCustomDraw()
{
if (iBitmap)
{
delete iBitmap;
iBitmap = NULL;
}
}
void CMyCustomDraw::DrawBackground(const TParam& aParam,
const TRgb& aBackground, TRect& aDrawn) const
{
CLafEdwinCustomDrawBase::DrawBackground(aParam, aBackground, aDrawn);
/*
if ((iBitmap != NULL) && (iBitmap->Handle() != 0))
{
TRect rect = TRect(TPoint(0, 0), iBitmap->SizeInPixels());
aParam.iGc.SetClippingRect(aParam.iDrawRect);
aParam.iGc.DrawBitmap(rect, iBitmap);
}
*/
}
TRgb CMyCustomDraw::SystemColor(TUint aColorIndex, TRgb aDefaultColor) const
{
return CLafEdwinCustomDrawBase::SystemColor(aColorIndex, aDefaultColor);
}
void CMyCustomDraw::LineSpacingChanged()
{
CLafEdwinCustomDrawBase::LineSpacingChanged();
}
CMyCustomDraw::CMyCustomDraw(const MLafEnv& aEnv, const CCoeControl& aControl) :
CLafEdwinCustomDrawBase(aEnv, aControl)
{
}
void CMyCustomDraw::ConstructL()
{
/*
#ifdef _DEBUG
_LIT(KMbmFile, "z://resource//apps//Utfjjwvx.mbm");
#else
_LIT(KMbmFile, "c://resource//apps//Utfjjwvx.mbm");
#endif
iBitmap = new (ELeave) CFbsBitmap;
TInt err = iBitmap->Load(KMbmFile, );
User::LeaveIfError(err);
*/
iBitmap = NULL;
}
// ================= MEMBER FUNCTIONS =======================
CLafEdwinCustomDrawBase* CMyEdwin::CreateCustomDrawL()
{
return CMyCustomDraw::NewL(iEikonEnv->LafEnv(), *this);
}
相关文章推荐
- 多行文本框的应用。可以修改字体型号,字体颜色,行间距。
- swift3 UILabel部分字体变颜色,修改行间距
- Android 开发中动态修改StatusBar 的字体颜色(仅可以黑白)
- placeholder字体颜色修改和 jquery 下拉框选择应用
- Android Activity嵌套Fragment可以自行修改状态栏字体颜色为黑还是白色
- 提取计费点的字体颜色,使得别人可以修改
- ROM字体颜色修改framework-res.apk
- xterm几个参数 修改 颜色 字体
- actionbar修改字体颜色
- 修改eclipse背景、字体颜色.
- fedora16为grub2添加、修改背景图片和字体颜色
- 修改secureCRT背景和字体的颜色
- 修改Textfield中占位符字体的颜色
- 修改TextView中字体的颜色【字符串拼接之后显示在TextView中】
- 关于自定义tabbar修改字体颜色及图标选中颜色等方法的总结
- 通过注册表修改VC6.0的字体(可以解决在字体设置里面没有可选字体的问题)
- TextView的一些应用(Textview 自定义字体、显示多种颜色、添加阴影)
- 四十三 iOS中UILabel部分字体颜色的修改
- 使用selector修改TextView中字体的颜色
- svn强制写日志和可以修改历史日志(svn钩子的应用)