用C++封装了一个简单的“按钮”类

简介:

功能简单,仅仅实现按钮的按下和松开的效果,按钮具体实现什么功能就由开发者自己定义了

复制代码
 1 #include<graphics.h>
 2 #include<iostream>
 3 #include <conio.h>
 4  using  namespace std;
 5  class botton{
 6  public:
 7      int x,y,w,h; // 起点坐标,宽度和高度
 8       char s[ 100]; // 显示文字
 9      botton( int xx, int yy, int ww, int hh, char s[]) // 建立按钮
10      {
11         x=xx;
12         y=yy;
13         w=ww;
14         h=hh;
15         setlinestyle(PS_SOLID,NULL, 1);
16         setcolor(WHITE);
17         line(x,y,x+w,y);
18         line(x,y,x,y+h);
19         setcolor(BLACK);
20         line(x+w,y+h,x+w,y);
21         line(x+w,y+h,x,y+h);
22         
23         outtextxy(x+ 2,y+ 2,s);
24     }
25      void LBOTTON_DOWN() // 鼠标左键按下
26      {
27         setlinestyle(PS_SOLID,NULL, 1);
28         setcolor(BLACK);
29         line(x,y,x+w,y);
30         line(x,y,x,y+h);
31         setcolor(WHITE);
32         line(x+w,y+h,x+w,y);
33         line(x+w,y+h,x,y+h);
34     }
35      void LONTTON_UP() // 鼠标左键松开
36      {
37         setlinestyle(PS_SOLID,NULL, 1);
38         setcolor(WHITE);
39         line(x,y,x+w,y);
40         line(x,y,x,y+h);
41         setcolor(BLACK);
42         line(x+w,y+h,x+w,y);
43         line(x+w,y+h,x,y+h);
44     }
45 };
46  int main()
47 {
48     initgraph( 600, 600);
49     setbkcolor(RGB( 230, 230, 230));
50     cleardevice();
51     setcolor(BLACK);
52     botton b1( 100, 100, 35, 20, " 文件 ");
53     getch();
54     b1.LBOTTON_DOWN();
55     getch();
56     b1.LONTTON_UP();
57     getch();
复制代码

58 } 


博主ma6174对本博客文章(除转载的)享有版权,未经许可不得用于商业用途。转载请注明出处http://www.cnblogs.com/ma6174/

对文章有啥看法或建议,可以评论或发电子邮件到ma6174@163.com


本文转自ma6174博客园博客,原文链接:http://www.cnblogs.com/ma6174/archive/2011/12/07/2279614.html ,如需转载请自行联系原作者
相关文章
存储 编译器 Linux
13 0
|
1天前
|
编译器 C++
标准库中的string类(上)——“C++”
标准库中的string类(上)——“C++”
|
1天前
|
编译器 C++
自从学了C++之后,小雅兰就有对象了!!!(类与对象)(中)——“C++”
自从学了C++之后,小雅兰就有对象了!!!(类与对象)(中)——“C++”
|
1天前
|
存储 编译器 C++
自从学了C++之后,小雅兰就有对象了!!!(类与对象)(上)——“C++”
自从学了C++之后,小雅兰就有对象了!!!(类与对象)(上)——“C++”
|
2天前
|
C++
【C++成长记】C++入门 | 类和对象(下) |Static成员、 友元
【C++成长记】C++入门 | 类和对象(下) |Static成员、 友元
|
2天前
|
存储 编译器 C++
【C++成长记】C++入门 | 类和对象(中) |拷贝构造函数、赋值运算符重载、const成员函数、 取地址及const取地址操作符重载
【C++成长记】C++入门 | 类和对象(中) |拷贝构造函数、赋值运算符重载、const成员函数、 取地址及const取地址操作符重载
|
11天前
|
存储 算法 C语言
【C++初阶】8. STL初阶 + String类
【C++初阶】8. STL初阶 + String类
47 1
|
11天前
|
C语言 C++
【C++初阶】9. string类的模拟实现
【C++初阶】9. string类的模拟实现
36 1
|
19天前
|
存储 安全 编译器
【C++】类的六大默认成员函数及其特性(万字详解)
【C++】类的六大默认成员函数及其特性(万字详解)
33 3
|
21天前
|
C++
4. C++类的组合
4. C++类的组合
26 0