Files
EzUI/demo/Adminstor/Adminstor/mainForm.cpp

169 lines
5.1 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "pch.h"
#include "mainForm.h"
void mainForm::OnNotify(Control* sender, EventArgs& args)
{
UIString btnName = sender->Name; // 控件id
Event eventType = args.EventType; // 事件类型
// 针对管理界面的表格控件
//if (btnName == "tableViewAdmin") {
// switch (eventType)
// {
// case 8: break;
// case Event::OnMouseUp://鼠标抬起
// {
// TableView* tableView = (TableView*)FindControl("tableViewAdmin"); //获取表格控件
// }
// break;
// default:
// std::cout << "表格事件:" << (long long)eventType << std::endl;
// break;
// }
//}
switch (eventType)
{
case ezui::OnMouseDown: //鼠标按下
{
if (btnName == "btnExitMain") { //退出
int result = ::MessageBoxW(Hwnd(), L"要退出程序吗?", L"提示", MB_YESNO | MB_ICONQUESTION);
if (result == IDYES)
exit(0);
}
else if (btnName == "btnMinMain") { //最小化
this->ShowMinimized();
}
else if (btnName == "btnMaxMain") { //最大化|还原
if (this->IsMaximized()) {
this->ShowNormal();
// 修改控件文字
Button* btnMax = (Button*)FindControl("btnMaxMain");
btnMax->SetText(L"🗖");
}
else {
this->ShowMaximized();
// 修改控件文字
Button* btnMax = (Button*)FindControl("btnMaxMain");
btnMax->SetText(L"🗗");
}
}
else if (btnName == "btnAdmin") { //到管理页面 获取 mainTab 设置页面为0
TabLayout* mainTab = (TabLayout*)FindControl("mainTab");
mainTab->SetPageIndex(0);
mainTab->Invalidate();
}
else if (btnName == "btnTools") { //到工具页面 获取 mainTab 设置页面为1
TabLayout* mainTab = (TabLayout*)FindControl("mainTab");
mainTab->SetPageIndex(1);
mainTab->Invalidate();
}
else if (btnName == "btnAdminConnect") { //管理页面的连接按钮按下,先获取 btnAdminConnect 按钮,设置为不可用,修改文字为“连接中...”
Button* btnAdminConnect = (Button*)FindControl("btnAdminConnect");
btnAdminConnect->SetText(L"🔄");
btnAdminConnect->Style.BackColor = Color(0, 185, 107);
}
else if (btnName == "btnAdminTemp") { //管理页面的测试按钮
TextBox* textAdmin = (TextBox*)FindControl("textAdminOutput"); //获取输出框
if (textAdmin) {
textAdmin->Insert(L"\n测试成功!",true);
textAdmin->GetScrollBar()->ScrollTo(1.0);
}
TableView* tableView = (TableView*)FindControl("tableViewAdmin"); //获取表格控件
if (tableView){
int rowCount = tableView->GetRowCount(); //总行数
// 表格增加一行数据
tableView->InsertRow(rowCount);
tableView->SetRowData(rowCount, { L"uid" + std::to_wstring(rowCount), L"192.168.200.131\n127.0.0" , L"", L"2026-02-25"});
tableView->SetCellChecked(rowCount, 5, true);
tableView->SetCellComboIndex(rowCount, 2, 0);
// 改变单元格颜色
/*CellStyle style = tableView->GetCellStyle(1, 1);
style.SetBackColor(Color(200, 230, 155));
tableView->SetCellStyle(1, 1, style);*/
}
}
}
break;
case ezui::OnMouseDoubleClick: //鼠标双击
{
//if (btnName == "titleMain") { //标题布局
// if (this->IsMaximized()) {
// this->ShowNormal();
// }
// else {
// this->ShowMaximized();
// }
//}
}
break;
default:
break;
}
if (args.EventType == Event::OnMouseDown) {
}
__super::OnNotify(sender, args);
}
void mainForm::OnClose(bool& close)
{
Application::Exit();
}
mainForm::mainForm() :LayeredWindow(1400, 750)
{
SetResizable(true); // 启用窗口大小调整
SetMiniSize(Size(600, 450)); // 设置最小尺寸
umg.LoadXml("res/mainForm.htm");//加载xml里面的控件与样式
umg.SetupUI(this);
AllocConsole();
FILE* fp = nullptr;
freopen_s(&fp, "CONOUT$", "w", stdout);
freopen_s(&fp, "CONOUT$", "w", stderr);
// 初始化设置表格各项属性
TableView* tableView = (TableView*)FindControl("tableViewAdmin"); //获取表格控件
if (tableView) {
tableView->SelectedRowBackColor = Color(200, 230, 255); // 设置选中行背景色
//tableView->SetColumnType(5, ezui::CellType::CheckBox);
tableView->SetColumnType(2, ezui::CellType::ComboBox);
tableView->SetColumnComboItems(2, { L"默认", L"禁止" , L"验机" });
tableView->SetDefaultTextAlign(Align::MiddleCenter);
//设置列宽
std::vector<int> withs = {60, 120, 50, 90, 85, 85, 100, 70, 70, 80, 80, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90};
for(int i = 0; i < withs.size(); i++)
tableView->SetColumnWidth(i, withs[i]);
// 鼠标右键单击的回调
tableView->RightClick = [tableView](int row, int col) {
int pRow = tableView->GetHoverRow(); //当前行号
int pCol = tableView->GetHoverCol(); //当前列号
UIString celContent = tableView->GetData(pRow, pCol);
//std::cout << "单元格内容: " << celContent.ansi() << std::endl;
std::cout << "当前列宽: " << tableView->GetColumnWidth(pCol) << std::endl;
};
// 单元格编辑完成(编辑结束时触发,提供旧值与新值)
tableView->CellEditFinished = [](int row, int col, const UIString& oldValue, const UIString& newValue) {
std::cout << "完成编辑单元格内容: " << newValue.ansi() << ", " << oldValue.ansi() << std::endl;
};
}
}
mainForm::~mainForm()
{
}