CChartAxisLabel类用来绘制轴标签,上、下、左、右都可以根据实际需要设置对应的轴标签。它处于该控件的区域,如下图所示:

CChartAxisLabel类的头文件。

#if !defined(AFX_CHARTAXISLABEL_H__0E5519C8_A2F4_4CED_9681_32A56B25D0C5__INCLUDED_)
#define AFX_CHARTAXISLABEL_H__0E5519C8_A2F4_4CED_9681_32A56B25D0C5__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "ChartObject.h"
#include "ChartString.h"
class CChartAxis;
class CChartAxisLabel : public CChartObject
{
friend CChartAxis;
public:
void SetText(const TChartString& NewText);
TChartString GetText() const { return m_strLabelText; }
void SetFont(int nPointSize, const TChartString& strFaceName);
CChartAxisLabel(CChartCtrl* pParent, bool bHorizontal);
virtual ~CChartAxisLabel();
private:
void SetPosition(int LeftBorder, int TopBorder, CDC *pDC);
void Draw(CDC* pDC);
CSize GetSize(CDC* pDC) const;
bool m_bIsHorizontal; // Specifies if the axis is horizontal or not
int m_iFontSize;
TChartString m_strFontName;
TChartString m_strLabelText;
};
#endif // !defined(AFX_CHARTAXISLABEL_H__0E5519C8_A2F4_4CED_9681_32A56B25D0C5__INCLUDED_)

CChartAxisLabel类的源文件。

#include "stdafx.h"
#include "ChartAxisLabel.h"
#include "ChartCtrl.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CChartAxisLabel::CChartAxisLabel(CChartCtrl* pParent, bool bHorizontal):CChartObject(pParent)
{
m_bIsHorizontal = bHorizontal;
m_iFontSize = ;
m_strFontName = _T("Microsoft Sans Serif");
m_strLabelText = _T("");
}
CChartAxisLabel::~CChartAxisLabel()
{
}
void CChartAxisLabel::SetText(const TChartString& NewText)
{
m_strLabelText = NewText;
m_pParent->RefreshCtrl();
}
void CChartAxisLabel::SetFont(int nPointSize, const TChartString& strFaceName)
{
m_iFontSize = nPointSize;
m_strFontName = strFaceName;
m_pParent->RefreshCtrl();
}
CSize CChartAxisLabel::GetSize(CDC *pDC) const
{
CSize LabelSize;
LabelSize.cx = ;
LabelSize.cy = ;
if (!m_bIsVisible)
return LabelSize;
if (!pDC->GetSafeHdc())
return LabelSize;
if (m_strLabelText == _T(""))
return LabelSize;
CFont NewFont;
CFont* pOldFont;
NewFont.CreatePointFont(m_iFontSize,m_strFontName.c_str(),pDC);
pOldFont = pDC->SelectObject(&NewFont);
LabelSize = pDC->GetTextExtent(m_strLabelText.c_str());
LabelSize.cx += ;
LabelSize.cy += ;
if (!m_bIsHorizontal)
{
int Width = LabelSize.cy;
int Height = LabelSize.cx;
LabelSize.cx = Width;
LabelSize.cy = Height;
}
pDC->SelectObject(pOldFont);
DeleteObject(NewFont);
return LabelSize;
}
void CChartAxisLabel::Draw(CDC *pDC)
{
if (!m_bIsVisible)
return;
if (!pDC->GetSafeHdc())
return;
if (m_strLabelText == _T(""))
return;
int iPrevMode = pDC->SetBkMode(TRANSPARENT);
COLORREF OldColor = pDC->SetTextColor(m_ObjectColor);
CFont NewFont;
NewFont.CreatePointFont(m_iFontSize,m_strFontName.c_str(),pDC);
CFont* pOldFont;
if (!m_bIsHorizontal)
{
LOGFONT LogFont;
NewFont.GetLogFont(&LogFont);
LogFont.lfOrientation = ;
LogFont.lfEscapement = ;
CFont VertFont;
VertFont.CreateFontIndirect(&LogFont);
pOldFont = pDC->SelectObject(&VertFont);
pDC->ExtTextOut(m_ObjectRect.left + ,m_ObjectRect.top,
ETO_CLIPPED,NULL,m_strLabelText.c_str(),NULL);
pDC->SelectObject(pOldFont);
DeleteObject(VertFont);
DeleteObject(NewFont);
}
else
{
pOldFont = pDC->SelectObject(&NewFont);
pDC->ExtTextOut(m_ObjectRect.left,m_ObjectRect.top + ,
ETO_CLIPPED,NULL,m_strLabelText.c_str(),NULL);
pDC->SelectObject(pOldFont);
DeleteObject(NewFont);
}
pDC->SetBkMode(iPrevMode);
pDC->SetTextColor(OldColor);
}
void CChartAxisLabel::SetPosition(int LeftBorder, int TopBorder, CDC *pDC)
{
CSize NewSize = GetSize(pDC);
CRect NewRect;
NewRect.top = TopBorder;
NewRect.bottom = TopBorder + NewSize.cy;
NewRect.left = LeftBorder;
NewRect.right = LeftBorder + NewSize.cx;
CChartObject::SetRect(NewRect);
}

CChartAxisLabel类在CChartAxis类中设定最终绘制的位置。

ChartCtrl源码剖析之——CChartAxisLabel类的更多相关文章

  1. ChartCtrl源码剖析之——CChartObject类

    首先,做一些简单的铺垫,目前针对ChartCtrl源码的剖析只针对V.15版本.名义上说是剖析,倒不如说是记录下自己针对该控件的理解,非常感谢Cedric Moonen大神,一切的功劳与掌声都该赠予给 ...

  2. ChartCtrl源码剖析之——CChartAxis类

    CChartAxis类用来绘制波形控件的坐标轴,这个源码相对较复杂,当初阅读的时候耗费了不少精力来理解源码中的一些实现细节. CChartAxis类的头文件. #if !defined(AFX_CHA ...

  3. ChartCtrl源码剖析之——CChartScrollBar类

    CChartScrollBar类用来针对每个轴的数据进行滚动,将那些不在当前区域内的数据通过滚动展示出来. CChartScrollBar类的头文件. #pragma once class CChar ...

  4. ChartCtrl源码剖析之——CChartTitle类

    CChartTitle类顾名思义,该类用来绘制波形控件的标题,它处于该控件的区域,如下图所示: CChartTitle类的头文件. #if !defined(AFX_CHARTTITLE_H__499 ...

  5. ChartCtrl源码剖析之——CChartLegend类

    CChartLegend类用来绘制每一个波形的描述信息,它处于该控件的区域,如下图所示: CChartLegend类的头文件. #if !defined(AFX_CHARTLEGEND_H__CD72 ...

  6. ChartCtrl源码剖析之——CChartGrid类

    CChartGrid类用来绘制波形区域中的表格,当绘制波形时波形就显示在这些表格上面.它处于该控件的区域,如下图所示: CChartGrid类的头文件. #if !defined(AFX_CHARTG ...

  7. PART(Persistent Adaptive Radix Tree)的Java实现源码剖析

    论文地址 Adaptive Radix Tree: https://db.in.tum.de/~leis/papers/ART.pdf Persistent Adaptive Radix Tree: ...

  8. 老李推荐:第6章3节《MonkeyRunner源码剖析》Monkey原理分析-事件源-事件源概览-命令翻译类

    老李推荐:第6章3节<MonkeyRunner源码剖析>Monkey原理分析-事件源-事件源概览-命令翻译类   每个来自网络的字串命令都需要进行解析执行,只是有些是在解析的过程中直接执行 ...

  9. WorldWind源码剖析系列:影像存储类ImageStore、Nlt影像存储类NltImageStore和WMS影像存储类WmsImageStore

    影像存储类ImageStore 影像存储类ImageStore提供了计算本地影像路径和远程影像影像URL访问的各种接口,是WmsImageStore类和NltImageStore类的基类.当划分完层次 ...

随机推荐

  1. php统计图类库JpGraph

    php统计图类库JpGraph JpGraph官网地址:https://jpgraph.net/. (1)下载类库: 下载地址:https://jpgraph.net/download/. 选择版本, ...

  2. webstorm js版本设置被重置

    在下列路径下搜索ECMAScript,将版本号全部改为6 C:\Users\admin\.WebStorm2016.1\config\options\statistics.application.us ...

  3. codeforces 301 E. Infinite Inversions

    题目:   time limit per test 2 seconds memory limit per test 256 megabytes input standard input output ...

  4. MySql基本数据类型(转)

    说明:通俗的理解:1字节的8位,即1byte=8bit,而这个1byte叫做长度范围,范围的算法是使用bit去求,比如8bit的长度范围是2的8次方,但是在数据库中的类型上是有区分有符号和无符号的,默 ...

  5. DELPHI最新的产品路线图

    1)根据众多像您一样的客户要求,我们改为一年一个重大版本及更多更新.这个计划回到一年发布周期并提供额外的2或3个包含附加功能及支持期间发布的新版操作系统的更新. 2)在 RAD Studio  10. ...

  6. eclipse中maven插件上传项目jar包到私服

    我们知道,每一个公司都会有自己的工具包或公共包.这样的包就能够上传到公司的maven私服,就不用每一个人都去同步开发包了. 那么,怎么把本地项目打包并公布到私服呢?依照例如以下步骤就能够轻松完毕. 1 ...

  7. curl的使用(from 阮一峰)

    1.   http://www.ruanyifeng.com/blog/2011/09/curl.html 2.   https://curl.haxx.se/docs/httpscripting.h ...

  8. hibernate查询之Criteria实现分页方法(GROOVY语法)

    public int searchTest(String name, Integer pageIndex, List<Test> resultList){ def criteria = T ...

  9. 《Spring设计思想》AOP设计基本原理

    0.前言 Spring 提供了AOP(Aspect Oriented Programming) 的支持, 那么,什么是AOP呢?本文将通过一个另外一个角度来诠释AOP的概念,帮助你更好地理解和使用Sp ...

  10. python菜鸟日记1

    1. 在__init__(self,...)初始化函数中.定义对象的属性,这些属性不用所有写在括号里,括号里的表示定义的时候须要赋初始值的一些属性,而其它不用初始值的属性.能够 直接卸载代码块中,se ...