码迷,mamicode.com
首页 > 其他好文 > 详细

【VB6 GDI+进阶】通过拼接圆弧和线绘制圆角矩形

时间:2017-04-03 21:23:09      阅读:199      评论:0      收藏:0      [点我收藏+]

标签:rect   ima   sub   blog   角度   拼接   wro   绘制   val   

GDI+中没有直接绘制圆角矩形的函数。本篇将详细介绍如何通过拼接圆弧和线绘制圆角矩形,结尾附封装好的函数,可以直接调用。

1.GdipDrawArcI(绘制圆弧)

函数声明如下:

Public Declare Function GdipDrawArcI _
               Lib "gdiplus" (ByVal graphics As Long, _
                              ByVal Pen As Long, _
                              ByVal X As Long, _
                              ByVal Y As Long, _
                              ByVal Width As Long, _
                              ByVal Height As Long, _
                              ByVal StartAngle As Single, _
                              ByVal sweepAngle As Single) As GpStatus

第一、第二个参数传入相应的Graphics与Pen,第三、第四个函数为圆弧所在圆的左上角XY坐标、Width和Height则为圆弧所在圆的宽和高;重要的是最后两个参数:StatrAngle是指圆弧起点与下图红线的夹角,SweepAngle则是圆弧的角度。

技术分享

上图蓝圈为XY坐标,StarAngle为90度,SweepAngle为90度,紫色圆弧就是绘制的效果。

2.GdipDrawLineI(绘制线)

VistaSwx介绍过我就不多说了。

 

3.绘制圆角矩形

思路:四个角落绘制90度的圆弧,接着用线连接。

Private Sub DrawRoundRectangle(Graphics As Long, Pen As Long, X As Long, Y As Long, Width As Long, Height As Long, Optional RoundSize As Long = 30)
GdipDrawArcI Graphics, Pen, X, Y, RoundSize * 2, RoundSize * 2, 180, 90
GdipDrawLineI Graphics, Pen, X + RoundSize, Y, X + Width - RoundSize, Y
GdipDrawArcI Graphics, Pen, X + Width - RoundSize * 2, Y, RoundSize * 2, RoundSize * 2, 270, 90
GdipDrawLineI Graphics, Pen, X + Width, Y + RoundSize, X + Width, Y + Height - RoundSize
GdipDrawArcI Graphics, Pen, X + Width - RoundSize * 2, Y + Height - RoundSize * 2, RoundSize * 2, RoundSize * 2, 0, 90
GdipDrawLineI Graphics, Pen, X + RoundSize, Y + Height, X + Width - RoundSize, Y + Height
GdipDrawArcI Graphics, Pen, X, Y + Height - RoundSize * 2, RoundSize * 2, RoundSize * 2, 90, 90
GdipDrawLineI Graphics, Pen, X, Y + RoundSize, X, Y + Height - RoundSize
End Sub

XY为圆角矩形坐标,Height width为高和宽,RoundSize为圆弧的大小。如果想填充的话把Pen改成Brush,Draw改成Fill即可,自己试试吧。

【VB6 GDI+进阶】通过拼接圆弧和线绘制圆角矩形

标签:rect   ima   sub   blog   角度   拼接   wro   绘制   val   

原文地址:http://www.cnblogs.com/Yokin/p/6663601.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!