C++控制台界面库_列表框类

列表框类:可以滚动,分页显示字符串链表或字符串数组。现在以字符串数组为例。

示例代码:

// ConsoleApplication1.cpp : 此文件包含 “main” 函数。程序执行将在此处开始并结束。

#include “console.h”
#pragma comment(lib,“console.lib”)

void jiemian0(); // 0

int main(int argc, char* argv[])
{
Screen screen;
screen.SetTitle(“列表框类”);
screen.ShowOrHideCursor(0);

Event event;
event.AddMouseMode();

jiemian0();

event.RestoreMode();
screen.Close_handle();
return 0;

}

void jiemian0()
{
Screen screen;
screen.SetSize(80,33);

Event event;

Button Exit_button = Button(40, 26, "退出");
Exit_button.Display_button();
	
char nf[10][100] = {"王凯 731014","张颖 457812","高俅 741256","孙悟空 321678","猪八戒 841256",
	"唐僧 325741","沙僧 345678","林黛玉 478512","贾宝玉 698745","武松 864321"};

Listbox listbox(10, 10, 40, 5);
listbox.Attribute1(true, false, 0);
listbox.ScrollButtonUp.Attribute(5, 15);
listbox.ScrollButtonUp.Display_button();
listbox.ScrollButtonDown.Attribute(5, 15);
listbox.ScrollButtonDown.Display_button();
listbox.AddArrayto_ScrollListbox(nf, 10);

Textbox textbox = Textbox(10, 17, 40);
textbox.Attribute(2, 14, 14);

int index;

while (1)
{
	event.ReadEvent();
	if (event.Mouse_Event())
	{
		if (Exit_button.MousePosition_At_button()
			&& event.Left_Button_Pressed())
		{
			break;
		}

		if (listbox.ScrollButtonUp.MousePosition_At_button()
			&& event.Left_Button_Pressed())
		{
			listbox.ScrollListboxText_array(UP, nf,10);
		}

		if (listbox.ScrollButtonDown.MousePosition_At_button()
			&& event.Left_Button_Pressed())
		{
			listbox.ScrollListboxText_array(DOWN, nf,10);
		}

		if (event.Mouse_Wheel_Up())
		{
			listbox.ScrollListboxText_array(UP, nf,10);
		}
		if (event.Mouse_Wheel_Down())
		{
			listbox.ScrollListboxText_array(DOWN,nf,10);
		}

		if (listbox.MousePosition_At_listbox()
			&& event.Left_Button_Pressed())
		{
			index = listbox.ScrollItemIndex();
			textbox.DisplayString_textbox(nf[index]);
		}			
	}	
}

}

运行效果:

C++控制台界面库_列表框类_第1张图片

你可能感兴趣的:(C++控制台界面库_列表框类)