惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
Tenable Blog
H
Heimdal Security Blog
K
Kaspersky official blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
S
Schneier on Security
G
GRAHAM CLULEY
U
Unit 42
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
C
CERT Recently Published Vulnerability Notes
Google DeepMind News
Google DeepMind News
罗磊的独立博客
Stack Overflow Blog
Stack Overflow Blog
阮一峰的网络日志
阮一峰的网络日志
Simon Willison's Weblog
Simon Willison's Weblog
C
Cisco Blogs
Cyberwarzone
Cyberwarzone
T
The Exploit Database - CXSecurity.com
Project Zero
Project Zero
Security Archives - TechRepublic
Security Archives - TechRepublic
www.infosecurity-magazine.com
www.infosecurity-magazine.com
博客园 - 司徒正美
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
V
Visual Studio Blog
博客园 - Franky
Engineering at Meta
Engineering at Meta
WordPress大学
WordPress大学
Jina AI
Jina AI
P
Proofpoint News Feed
P
Proofpoint News Feed
有赞技术团队
有赞技术团队
L
LINUX DO - 最新话题
宝玉的分享
宝玉的分享
N
News and Events Feed by Topic
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
博客园 - 聂微东
T
The Blog of Author Tim Ferriss
Spread Privacy
Spread Privacy
Application and Cybersecurity Blog
Application and Cybersecurity Blog
IT之家
IT之家
S
Security Affairs
博客园 - 叶小钗
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
小众软件
小众软件
N
News | PayPal Newsroom
Cloudbric
Cloudbric
AWS News Blog
AWS News Blog
W
WeLiveSecurity
The Last Watchdog
The Last Watchdog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
NISL@THU
NISL@THU

博客园 - Jonny Yu

[GCC学习]get the optimized function call graph 界面开发中的那些疯狂的小事 Re:架构设计之性能设计经验 技术资产管理 .Net下进程外COM服务器的实现 控件的鼠标拖动和改变大小实现的思考 Learn from mistake, i.e. 和 e.g. 是不同的 How can I hide a user from the Welcome Screen in Windows XP? About HDC window class, OO about wParam and lParam 就差一点点-微妙的强制类型转换 Disable the CrossThreadChecking in .Net Framework v2.0 several useful Store Procedures in MSSQL http://cnblogs.com/rickie/archive/2005/07/02/184927.aspx VS2005使用体验 Inventor 的一些快捷键 First day in Hanna. XPath crash course note
[GDI+]DrawRectangle和FillRectangle,细节决定成败
Jonny Yu · 2005-07-20 · via 博客园 - Jonny Yu

首先, GDI+里坐标网格是通过每个象素的中心的
对于DrawRectangle
其中矩形的长度和宽度指的是象素之间的间隔数,因此如果要绘制
DrawRectangle ( Pens.Black, 0,0, 5,4);
最终会得到长为6个象素宽为5个象素的矩形框。

而在FillRectangle 的时候,指定的长度和宽度是实际矩形的长宽的象素数。
如果仍然按照GDI+的坐标网格来看实际填充的的矩形区域比指定填充区域向左,上各偏移了0.5个象素。

因此在很多时候我们需要为一个填充的矩形区域画边框我们需要小心的给出边界参数。
下面这段代码演示了,如何为矩形区域绘制内边框和外边框。

        private void Form1_Paint(object sender, PaintEventArgs e)
        
{
            Graphics g 
= e.Graphics;

            Rectangle rect 
= new Rectangle(10,10,40,30);

            
g.FillRectangle(Brushes.LightBlue, rect);

            Rectangle innerBounds 
= new Rectangle(rect.Left, rect.Top, rect.Width - 1, rect.Height - 1);
            Rectangle outerBounds 
= new Rectangle(rect.Left - 1, rect.Top - 1, rect.Width + 1, rect.Height + 1);

            g.DrawRectangle(Pens.Brown, innerBounds);
            g.DrawRectangle(Pens.Blue, outerBounds);
        }

这只是我的理解的解决方法,如果大家觉得不对或有更好的实现方法,请尽管拍砖过来啊!

BTW:进一步研究发现Rectangle.Contains的行为也和FillRectangle相同,Rectangle的右上,右下,左下点不算在矩形区域内。所以ClipRectangle的计算又得小心了。