PDA

View Full Version : مشکل در ساخت کلاس button



mehdi_RM
دوشنبه 14 خرداد 1386, 18:28 عصر
سلام
من یه کلاس button ساختم
می خوام کاری کنم که وقتی کاربر کلید tab زد ، بروی دکمه ها حرکت کنه
می خوام این کارو با همون کلاس button انجام بدم
یعنی نیام صفحه رو دوباره پاک کنم و کلیدها رو دوباره از اول بکشم و جای کلید فعال (مثلا رنگشو ) عوض کنم
می خوام بدونم نمیشه همین کارو با کلاس انجام داد بوسیله یک متدی یا تابع؟
تعداد کلید های موجودو می تونم با یه متغیر static داخل کلاس بگیرم ولی این کارو نمی دونم چطوری انجام بدم؟

saeid5977
دوشنبه 14 خرداد 1386, 18:56 عصر
سلام
لازم نیست همه رو دوباره بکشی
فقط اونی که فوکوس رو از دست میده و اونی که فوکوس رو میگیره رو دوباره بکش.
موفق باشی.

mehdi_RM
دوشنبه 14 خرداد 1386, 20:50 عصر
اسم این دو تا شی رو از کجا بگیرم ؟

saeid5977
دوشنبه 14 خرداد 1386, 20:55 عصر
خوب باید خودت اونی که بهش از اول فوکوس میدی رو بدونی کدومه و همینطور ترتیب اونها رو در اینصورت همیشه اون 2 تا رو داری!

mehdi_RM
سه شنبه 15 خرداد 1386, 17:21 عصر
این کد بنظر شما خوبه




#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <graphics.h>
class button
{
public:
static int count;
static int active;
button(int,int,int,int,char *);
friend void refresh(button *p);
int id;
char caption[15];
int x1,y1,x2,y2;
private:
};
button::button(int xx1,int yy1,int xx2,int yy2,char *cap)
{
x1=xx1; x2=xx2; y1=yy1; y2=yy2;

int col=7;
if (button::count==0)
active=0;
id=++count;
if (id==button::active)
setcolor(9);
else
setcolor(6);
rectangle(x1-1,y1-1,x2+1,y2+1);

setcolor(col);
setfillstyle(1,col);
rectangle(x1,y1,x2,y2);
floodfill(x1+3,y1+3,col);
//
setcolor(15);
line(x1,y1,x1+60,y1);
line(x1,y1,x1,y1+15);
setcolor(8);
line(x1,y1+15,x1+60,y1+15);
line(x1+60,y1,x1+60,y1+15);
//
outtextxy(x1+(x2-x1)/2,y1+(y2-y1)/2,caption);
}
//*********************************************
void refresh(button *p)
{
int counter;
for (counter=0;counter<=button::count;counter++)
{
if (p->id==button::active)
setcolor(9);
else
setcolor(6);
setfillstyle(1,6);
rectangle(p->x1-1,p->y1-1,p->x2+1,p->y2+1);
p++;
}
}
//static variable in class button
int button::count=-1;
int button::active;
//*******************************************
int main(void)
{
int gdriver=DETECT,gmode;
initgraph(&gdriver,&gmode ,"c:\\tc\\bgi");
clrscr;
button Button[3]={button(10,15,70,30,"Ignore"),button(100,15,160,30,"Abort")
,button(190,15,250,30,"Cancel")};

button *p;
p=&Button[0];
char ch;
do
{
ch=getch();
ch=getch();
p=&Button[0];
switch(ch)
{
case 72: if(button::active!=0)
button::active-=1;
break;
case 80: if(button::active!=button::count)
button::active+=1;
break;
}

refresh(p);
}while(ch!=27);

getch();
closegraph();
return 0;
}

saeid5977
سه شنبه 15 خرداد 1386, 21:26 عصر
آره خوبه البته اینجا هم که داری همه رو دوباره میکشی؟!

mehdi_RM
چهارشنبه 16 خرداد 1386, 06:59 صبح
داخل برنامه های ویندوز (زبان های ویژوال) از این روش استفاده می کنن؟؟
یا روش دیگه ای ؟
در مورد روش من اگه روش بهتریی داری بگو
برنامه رو بعدا اصلاح می کنم تا فقط اون 2 تا رو فقط عوض کنه؟