Delphi控件的显示内容与显示边框是两回事
没有内容,不代表没有边框。比如设计期一个空的TImage仍是有边框的。
if (csOpaque in image1.ControlStyle) then ShowMessage('不透明')
else ShowMessage('透明') // image1没有内容的时候,就是透明;有内容的时候,就是不透明
再比如:
procedure TWinControl.PaintControls(DC: HDC; First: TControl);
var
I, Count, SaveIndex: Integer;
FrameBrush: HBRUSH;
begin
// 这个DC其实是父Win控件的句柄
// 一共有2处调用此函数。分别是TControl.Repaint和TWinControl.PaintHandler,分别用来重绘图形控件和Win控件(后者包括了图形子控件,也正因为这个才需要执行这个函数)
if DockSite and UseDockManager and (DockManager <> nil) then
DockManager.PaintSite(DC);
// 重画所有子控件(图形和句柄控件)
// FControls和FWinControls在TControl.SetParent里调用TWinControl.Insert里增加元素
if FControls <> nil then // 专指图形控件,不包含windows控件
begin
I := ;
if First <> nil then
begin
I := FControls.IndexOf(First);
if I < then I := ;
end;
Count := FControls.Count;
while I < Count do
begin
with TControl(FControls[I]) do
if (Visible or (csDesigning in ComponentState) and not (csNoDesignVisible in ControlStyle)) and
RectVisible(DC, Rect(Left, Top, Left + Width, Top + Height)) then // API
begin
if csPaintCopy in Self.ControlState then Include(FControlState, csPaintCopy);
SaveIndex := SaveDC(DC); // API,重画前,保存父控件的DC
MoveWindowOrg(DC, Left, Top); // 调用2个API
IntersectClipRect(DC, , , Width, Height); // API,新建一个完全的区域
// 原本图形控件不能接受Windows消息的,现在也接受了。注意传递了父控件的DC
Perform(WM_PAINT, DC, ); // important7,图形控件已经把WM_PAINT消息内容已经填好,就等程序员填写Paint函数加上真正要执行的内容。
RestoreDC(DC, SaveIndex); // API,恢复父控件的DC
Exclude(FControlState, csPaintCopy); // 画完之后,去除标记
end;
Inc(I);
end;
end;
// 除此以外,还要给Windows子控件额外画边框(因为实体已经画好了)(注意不是给自己画边框)
if FWinControls <> nil then // 专指windows控件,不包含图形控件
for I := to FWinControls.Count - do
with TWinControl(FWinControls[I]) do
if FCtl3D and (csFramed in ControlStyle) and
(Visible or (csDesigning in ComponentState) and not (csNoDesignVisible in ControlStyle)) then
begin
// fixme 可以试试屏蔽这里的语句,看看效果
FrameBrush := CreateSolidBrush(ColorToRGB(clBtnShadow)); // API
FrameRect(DC, Rect(Left - , Top - , Left + Width, Top + Height), FrameBrush); // API 画矩形边框
DeleteObject(FrameBrush); // API
FrameBrush := CreateSolidBrush(ColorToRGB(clBtnHighlight));
FrameRect(DC, Rect(Left, Top, Left + Width + , Top + Height + ), FrameBrush); // 画两条线
DeleteObject(FrameBrush); // API
end;
end;
又看到一个函数:
procedure TWinControl.WMWindowPosChanged(var Message: TWMWindowPosChanged);
var
Framed, Moved, Sized: Boolean;
begin
// 三明治手法,这里使边框失效
// 判断是否有边框,是否移动了,是否改变了尺寸
Framed := FCtl3D and (csFramed in ControlStyle) and (Parent <> nil) and (Message.WindowPos^.flags and SWP_NOREDRAW = );
Moved := (Message.WindowPos^.flags and SWP_NOMOVE = ) and IsWindowVisible(FHandle); // API
Sized := (Message.WindowPos^.flags and SWP_NOSIZE = ) and IsWindowVisible(FHandle);
// 如果有边框,并且已经移动或者改变了尺寸,那么使边框无效
if Framed and (Moved or Sized) then InvalidateFrame; // 类函数 fixme 这不是重复了吗?
// 仅仅调整边框不够,更主要是调整控件自己的位置
if not (csDestroyingHandle in ControlState) then UpdateBounds; // 类函数,使用API调整控件在屏幕上的位置 inherited; // super 三明治手法,调用程序员潜在的消息函数,并重新计算最大化最小化的限制和坞里的尺寸 // fixme 根据消息的内容,再次使边框无效(如果有显示或隐藏标记的话)
if Framed and ((Moved or Sized) or (Message.WindowPos^.flags and (SWP_SHOWWINDOW or SWP_HIDEWINDOW) <> )) then
InvalidateFrame; // 类函数,简单调用API
end;
procedure TWinControl.InvalidateFrame;
var
R: TRect;
begin
R := BoundsRect; // 类属性,调用方法,简单计算
InflateRect(R, , ); // API
InvalidateRect(Parent.FHandle, @R, True); // API
end;
留个爪,以后再详细研究~
Delphi控件的显示内容与显示边框是两回事的更多相关文章
- DotNetBar 控件设置空内容时显示内容
可以通过修改所有关于Watermark时的设置.
- delphi 控件的名称怎么不显示了
选择菜单 Tools--Environment在打开的对话框中选择 Designer 页,选 其中的 Options 选项勾选 Show component captions ,点击 OK即可
- WinForm控件TreeView 只部分节点显示 CheckBox
WinForm控件TreeView 只部分节点显示 CheckBox 用过asp.net的应该知道,要在treeview中实现上述功能可以使用ShowCheckBox 属性指定那些节点显示check ...
- Scroll View 控件以Thumbnail的方式显示一个目录的全部图片,相似图片浏览器
MAC : XCode -> Scroll View 控件以Thumbnail的方式显示一个目录的全部图片,类似图片浏览器 STEP1:将两个目录复制到project里面ImageBrowser ...
- delphi Components[i]清除所有edit控件中的内容
(* 一般的清空combobox方法 combobox1.clear; ... combobox9.clear; *) procedure TForm1.Button1Click(Sender: ...
- Delphi 控件大全
delphi 控件大全(确实很全) delphi 控件查询:http://www.torry.net/ http://www.jrsoftware.org Tb97 最有名的工具条(ToolBar ...
- delphi控件属性大全-详解-简介
http://blog.csdn.net/u011096030/article/details/18716713 button 组件: CAPTION 属性 :用于在按钮上显示文本内容 Cancel ...
- delphi 控件大全(确实很全)
delphi 控件查询:http://www.torry.net/ http://www.jrsoftware.org Tb97 最有名的工具条(ToolBar)控件库,仿Office97,如TDoC ...
- DELPHI控件属性事件说明
常用DELPHI控件属性事件设置说明 常用DELPHI控件属性设置说明目录TForm Class TPanel组件 TToolBar Class TToolButton Class TTimer Cl ...
- delphi 控件查询
//老古董,以前这些东西太多了,收藏的没过来,只好粘贴至此,当然不是本人整理的. delphi 控件查询:http://www.torry.net/ http://www.jrsoftware.org ...
随机推荐
- rsync 推送
两遍服务器都安装好rsync后 如果做推送服务 被推送的服务器的 配置文件 注意事项 1服务端(192.168.1.241)配置的密匙文件 格式为[运行环境] 用户名:密码 root:123456 ...
- JS为Select下拉框添加输入功能
JavaScript使用parentNode.nextSibling.value实现的本功能,实际上你会发现网页上有两个控件元素,一个是Select,一个是input,使用CSS将input覆盖于se ...
- mysql 异常处理实例
1. 语法: DECLARE handler_action HANDLER FOR condition_value [, condition_value] ... statement handler_ ...
- 洛谷比赛 堕落的Joe
/*暴力50*/ #include<iostream> #include<cstdio> #include<cstring> #define maxn 100010 ...
- Android常用组件【转】
UI相关 图片 Android-Universal-Image-Loader:com.nostra13.universalimageloader:异步加载.缓存.显示图片 ImageLoader:co ...
- 开源的Android开发框架-------PowerFramework使用心得(五)网络请求HTTPRequest
GET请求示例 //所有参数都使用Bundle,用putString Bundle bundle = new Bundle(); bundle.putString("username&quo ...
- JavaScript中style.left与offsetLeft的区别
今天在制作焦点轮播图的时候,遇到一个问题,在使用style.left获取图片的位置时,怎么也获取不到.换用offsetLeft就能够成功获取到了.虽然实现了我想要的效果,但是还是不甘心啊,没有找到原因 ...
- 80端口被占用 PID = 4解决办法
请按照下面的步骤来运行命令:1. sc config http stat = demand2. reboot3. run the command(netsh http show servicestat ...
- MySQL中删除重复数据只保留一条
用SQL语句,删除掉重复项只保留一条 在几千条记录里,存在着些相同的记录,如何能用SQL语句,删除掉重复的呢 1.查找表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断 SELECT ...
- PHP学习之中数组--创建数组【1】
在PHP中数组的定义有三种写法,分别是: <?php //第一种方式是用关键字 array来创建的 $username = array("demo1","demo2 ...