VB6 GDI+进阶通过拼接圆弧和线绘制圆角矩形
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了VB6 GDI+进阶通过拼接圆弧和线绘制圆角矩形相关的知识,希望对你有一定的参考价值。
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+进阶通过拼接圆弧和线绘制圆角矩形的主要内容,如果未能解决你的问题,请参考以下文章
结构建模设计——Solidworks软件之草图绘制基础图形工具总结(绘制直线矩形圆槽圆弧圆角等)