2.1按钮

FLTK提供了很多类型的按钮

Fl_Button 普通按钮
Fl_Check_Button 带有选择框的按钮
Fl_Light_Button 带有指示灯的按钮
Fl_Repeat_Button
Fl_Return_Button 能被Enter激活的按钮
Fl_Round_Button 带有圆形选择框的按钮

每一个按钮都需要相应的<FL/Fl_xyz_Button.H>头文件。

构造函数包含了控件的位置,大小和可选的标签

Fl_Button *button = new Fl_Button(x, y, width, height, "label");
Fl_Light_Button *lbutton = new Fl_Light_Button(x, y, width, height);
Fl_Round_Button *rbutton = new Fl_Round_Button(x, y, width, height, "label");

每一个按钮可以设置自己的类型用type(),通过这个设置,可以让一个按钮为 push button, toggle button, or radio button:

button->type(FL_NORMAL_BUTTON);
lbutton->type(FL_TOGGLE_BUTTON);
rbutton->type(FL_RADIO_BUTTON);

对于toggle和radio按钮,value()函数返回当前的状态,开/关(0代表关,1代表开),set()和clear()分别用来设置和清除togglebutton的状态。Radio Button可以用setonly()打开,同组中的其他Radio button按钮将关闭。