开源一个sheet表格类
可以建立表格,输入内容,居中显示
#include <iostream>
#include <conio.h>
#include <string>
#include <graphics.h>
using namespace std;
class sheet{
public:
sheet(int l=5,int c=5,int width=80,int highth=40,int posx=0,int posy=0);
//行数,列数,行宽,列宽,起始位置x,y
void put_txt(int x,int y,char *s);
private:
int col,lin,col_high,lin_width,pos_x,pos_y;
};
sheet::sheet(int l,int c,int width,int highth,int posx,int posy)
{
col=c;
lin=l;
lin_width=width;
col_high=highth;
pos_x=posx;
pos_y=posy;
int grax,gray;
grax=col*lin_width;
gray=lin*col_high;
int i,j;
for(i=0;i<=grax;i+=lin_width)
line(i+pos_x,0+pos_y,i+pos_x,gray+pos_y);
for(j=0;j<=gray;j+=col_high)
line(0+pos_x,j+pos_y,grax+pos_x,j+pos_y);
}
void sheet::put_txt(int x,int y,char *s)
{
outtextxy((x-1)*lin_width+20+pos_x,(y-1)*col_high+8+pos_y,s);
}
int main()
{
initgraph(800,600);
// sheet a(15,6,100,30,20,20);
sheet a;
string s="张三";
a.put_txt(2,2,s);
getch();
}
#include <conio.h>
#include <string>
#include <graphics.h>
using namespace std;
class sheet{
public:
sheet(int l=5,int c=5,int width=80,int highth=40,int posx=0,int posy=0);
//行数,列数,行宽,列宽,起始位置x,y
void put_txt(int x,int y,char *s);
private:
int col,lin,col_high,lin_width,pos_x,pos_y;
};
sheet::sheet(int l,int c,int width,int highth,int posx,int posy)
{
col=c;
lin=l;
lin_width=width;
col_high=highth;
pos_x=posx;
pos_y=posy;
int grax,gray;
grax=col*lin_width;
gray=lin*col_high;
int i,j;
for(i=0;i<=grax;i+=lin_width)
line(i+pos_x,0+pos_y,i+pos_x,gray+pos_y);
for(j=0;j<=gray;j+=col_high)
line(0+pos_x,j+pos_y,grax+pos_x,j+pos_y);
}
void sheet::put_txt(int x,int y,char *s)
{
outtextxy((x-1)*lin_width+20+pos_x,(y-1)*col_high+8+pos_y,s);
}
int main()
{
initgraph(800,600);
// sheet a(15,6,100,30,20,20);
sheet a;
string s="张三";
a.put_txt(2,2,s);
getch();
}
博主ma6174对本博客文章(除转载的)享有版权,未经许可不得用于商业用途。转载请注明出处http://www.cnblogs.com/ma6174/
对文章有啥看法或建议,可以评论或发电子邮件到ma6174@163.com