使用Easyx制作一个按钮控件

5 篇文章 2 订阅
2 篇文章 0 订阅

代码附上

void botton(int left, int top, int right, int bottom, int rgb_R_before, int rgb_G_before, int rgb_B_before, int rgb_R_init, int rgb_G_init, int rgb_B_init, int rgb_R_after, int rgb_G_after, int rgb_B_after, wchar_t* L_TEXT_before, wchar_t* L_TEXT_init, wchar_t* L_TEXT_after)
{
	if (button == 0)
	{
		clearrectangle(left,top,right,bottom);
		//边框设置
		setlinecolor(BLACK);
		line(left, top, left, bottom);
		line(left, top, right, top);
		line(right, top, right, bottom);
		line(left, bottom, right, bottom);
		//渐变颜色设置
		int a = 10;				//颜色渐变区域
		int i = 0;				//局部变量i,用于循环变量
		double c = 255 / a;		//设置变化率
		//绘制渐变颜色变化边框
		for (i = 0; i < a; i++)
		{
			setlinecolor(RGB(c * i, c * i, c * i));
			line(left - i, top - i, left - i, bottom + i);
			line(left - i, top - i, right + i, top - i);
			line(right + i, top - i, right + i, bottom - i);
			line(left - i, bottom + i, right + i, bottom + i);
		}
		solidrectangle(left, top, right, bottom);
		setfillcolor(RGB(rgb_R_before,rgb_G_before,rgb_B_before));
		settextcolor(BLACK);
		RECT r = { left,top,right,bottom };			//获取按钮的矩形区域
		drawtext(L_TEXT_before, &r, DT_CENTER | DT_NOPREFIX | DT_WORDBREAK | DT_INTERNAL);//设置文字的输出格式:居中,自动换行,使用系统字体,使用系统字体自动计算,并且输出文字
		//drawtext(L_TEXT_before, &r, DT_CENTER | DT_VCENTER | DT_SINGLELINE);			//垂直居中,单行显示
	}
	if (button == 1)
	{
		clearrectangle(left,top,right,bottom);
		//边框设置
		setlinecolor(BROWN);
		line(left, top, left, bottom);
		line(left, top, right, top);
		line(right, top, right, bottom);
		line(left, bottom, right, bottom);
		//渐变颜色设置
		int a = 10;				//颜色渐变区域
		int i = 0;				//局部变量i,用于循环变量
		double c = 255 / a;		//设置变化率
		//绘制渐变颜色变化边框
		for (i = 0; i < a; i++)
		{
			setlinecolor(RGB(c * i, c * i, c * i));
			line(left - i, top - i, left - i, bottom + i);
			line(left - i, top - i, right + i, top - i);
			line(right + i, top - i, right + i, bottom - i);
			line(left - i, bottom + i, right + i, bottom + i);
		}
		//设置矩形区域填充颜色
		solidrectangle(left, top, right, bottom);
		setfillcolor(RGB(rgb_R_init,rgb_G_init,rgb_B_init));
		//setfillcolor(RGB(128, 128, 135));			//灰色
		settextcolor(BLACK);
		RECT r = { left,top,right,bottom };			//获取按钮的矩形区域
		drawtext(L_TEXT_init, &r, DT_CENTER | DT_NOPREFIX | DT_WORDBREAK | DT_INTERNAL);//设置文字的输出格式:居中,自动换行,使用系统字体,使用系统字体自动计算,并且输出文字
		//drawtext(L_TEXT_before, &r, DT_CENTER | DT_VCENTER | DT_SINGLELINE);			//垂直居中,单行显示
	}
	if (button == 2)
	{
		clearrectangle(left,top,right,bottom);
		//边框设置
		setlinecolor(BLACK);
		line(left, top, left, bottom);
		line(left, top, right, top);
		line(right, top, right, bottom);
		line(left, bottom, right, bottom);
	}
	//渐变颜色设置
	int a = 10;				//颜色渐变区域
	int i = 0;				//局部变量i,用于循环变量
	double c = 255 / a;		//设置变化率
	//绘制渐变颜色变化边框
	for (i = 0; i < a; i++)
	{
		setlinecolor(RGB(c * i, c * i, c * i));
		line(left - i, top - i, left - i, bottom + i);
		line(left - i, top - i, right + i, top - i);
		line(right + i, top - i, right + i, bottom - i);
		line(left - i, bottom + i, right + i, bottom + i);
	}
	solidrectangle(left, top, right, bottom);
	setfillcolor(RGB(rgb_R_after,rgb_G_after,rgb_B_after));
	settextcolor(BLACK);
	RECT r = { left,top,right,bottom };			//获取按钮的矩形区域
	drawtext(L_TEXT_after, &r, DT_CENTER | DT_NOPREFIX | DT_WORDBREAK | DT_INTERNAL);//设置文字的输出格式:居中,自动换行,使用系统字体,使用系统字体自动计算,并且输出文字
	//drawtext(L_TEXT_before, &r, DT_CENTER | DT_VCENTER | DT_SINGLELINE);			//垂直居中,单行显示
}

注意
botton 是一个全局变量,配合鼠标事件线程同时使用。

  • 2
    点赞
  • 30
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值