发文章
发文工具
撰写
网文摘手
文档
视频
思维导图
随笔
相册
原创同步助手
其他工具
图片转文字
文件清理
AI助手
留言交流
void CMyListCtrl::OnPaint(){ // First let the control do its default drawing. const MSG *msg = GetCurrentMessage(); DefWindowProc( msg->message, msg->wParam, msg->lParam ); // Draw the lines only for LVS_REPORT mode if( (GetStyle() & LVS_TYPEMASK) == LVS_REPORT ) { // Get the number of columns CClientDC dc(this ); CHeaderCtrl* pHeader = (CHeaderCtrl*)GetDlgItem(0); int nColumnCount = pHeader->GetItemCount(); // The bottom of the header corresponds to the top of the line RECT rect; pHeader->GetClientRect( &rect ); int top = rect.bottom; // Now get the client rect so we know the line length and // when to stop GetClientRect( &rect ); // The border of the column is offset by the horz scroll int borderx = 0 - GetScrollPos( SB_HORZ ); for( int i = 0; i < nColumnCount; i++ ) { // Get the next border borderx += GetColumnWidth( i ); // if next border is outside client area, break out if( borderx >= rect.right ) break; // Draw the line. dc.MoveTo( borderx-1, top); dc.LineTo( borderx-1, rect.bottom ); } } // Do not call CListCtrl::OnPaint() for painting messages} To draw the vertical lines, we use the header control to determine the column dimensions and also the effective client area after taking into account the header control itself. Finally, we draw a line to the right of each column. Note that the horizontal scrollbars position is taken into account when determining the border. If we dont do this, we might end up with a line right in the middle of a column when the list has been horizontally scrolled. The GetScrollPos() function returns 0 if there is no scrollbar so we dont need to make a prior check on whether the list view control does have a horizontal scrollbar. We could also have used GetItemRect() function, but it works only if the list has atleast one item. The line is actually drawn one pixel left of the column border. This aligns it better with the column header. It also introduces a bug. When you increase a column width, the column area below the last visible item is not updated, thus leaving traces of the previous line. There are two approaches you can take to resolve this. First, draw the line exactly on the column border (e.i. do not subtract 1 from borderx). The second approach is to handle the HDN_TRACK notification from the header control and invalidate the exposed area so that it gets redrawn.
void CMyListCtrl::OnPaint(){ // First let the control do its default drawing. const MSG *msg = GetCurrentMessage(); DefWindowProc( msg->message, msg->wParam, msg->lParam ); // Draw the lines only for LVS_REPORT mode if( (GetStyle() & LVS_TYPEMASK) == LVS_REPORT ) { // Get the number of columns CClientDC dc(this ); CHeaderCtrl* pHeader = (CHeaderCtrl*)GetDlgItem(0); int nColumnCount = pHeader->GetItemCount(); // The bottom of the header corresponds to the top of the line RECT rect; pHeader->GetClientRect( &rect ); int top = rect.bottom; // Now get the client rect so we know the line length and // when to stop GetClientRect( &rect ); // The border of the column is offset by the horz scroll int borderx = 0 - GetScrollPos( SB_HORZ ); for( int i = 0; i < nColumnCount; i++ ) { // Get the next border borderx += GetColumnWidth( i ); // if next border is outside client area, break out if( borderx >= rect.right ) break; // Draw the line. dc.MoveTo( borderx-1, top); dc.LineTo( borderx-1, rect.bottom ); } } // Do not call CListCtrl::OnPaint() for painting messages}
Note that the horizontal scrollbars position is taken into account when determining the border. If we dont do this, we might end up with a line right in the middle of a column when the list has been horizontally scrolled. The GetScrollPos() function returns 0 if there is no scrollbar so we dont need to make a prior check on whether the list view control does have a horizontal scrollbar. We could also have used GetItemRect() function, but it works only if the list has atleast one item.
The line is actually drawn one pixel left of the column border. This aligns it better with the column header. It also introduces a bug. When you increase a column width, the column area below the last visible item is not updated, thus leaving traces of the previous line. There are two approaches you can take to resolve this. First, draw the line exactly on the column border (e.i. do not subtract 1 from borderx). The second approach is to handle the HDN_TRACK notification from the header control and invalidate the exposed area so that it gets redrawn.
来自: louisasea > 《WPF》
0条评论
发表
请遵守用户 评论公约
用OpenCV和OCR识别图片中的表格数据 !OpenCV简直太强大了!
# 寻找单元格区域 def CellDetect(self): vertical_lines = self.VerticalLineDetect() horizontal_lines = self.HorizontalLineDetect(...
pdfplumber说明文档翻译
pdfplumber说明文档翻译_pdfplumber中文文档_hbh112233abc的博客-CSDN博客。import pdfplumberwith pdfplumber.open("path/to/file.pdf") as pdf: first_page = pdf.pages[0] print(first_pa...
draw2d里面的一函数 translateToAbsolute(rect)
请教draw2d里面的一函数 translateToAbsolute(rect)请问 translateToAbsolute()这个函数有什么作用?text.setBounds(rect.x,rect.y,rect.width,rect.height);figure在它父亲内的位置为50,50figure的父...
用EXCEL可多种办法生成99乘法表
用EXCEL可多种办法生成99乘法表。1、在一个工作表区域内(B12:J12),依次输入1-9.(A13:A21)区域内依次输入1-9.然后再单元格B13内输入一个公式,通过拖曳填充产生具有上三角矩阵结构的九九乘法表。=IF(AND(...
Heeseop Yoon 内饰绘画艺术作品集
My work deals with memory and perception within cluttered spaces.As I correct "mistakes" the work results in double o...
\vspace vs. \vskip
\vspace vs. \vskip.There are six modes, divided in threecategories:horizontal mode and restricted horizontal mode,vertical mode and internal vertical mode, andmath mode and display math m...
[精品转载]-构图进阶指南(简译).
Guidelines forBetter Photographic Composition:Balance构图进阶指南:平衡。Guidelines forBetter Photographic Composition: Framing...
DbGridEh根据某一个字段的值显示对应底色或字体变化
DbGridEh根据某一个字段的值显示对应底色或字体变化。改变行底色:procedure TForm1.dggrideh1DrawColumnCell(Sender: TObject;const Rect: TRect; DataCol: Integer; Column: TColumnEh; State: TGrid...
WinAPI: GetKeyNameText
type TForm1 = class(TForm) procedure FormCreate(Sender: TObject);procedure MyMsg(var msg: TWMKeyDown);var Form1: TForm1;MyMsg(var msg: TWMKeyDown);var buf: array[0..begin {获取} Ge...
微信扫码,在手机上查看选中内容