Files
pacs_win_uia/tests/uia-fixture/FixtureForm.cs
T
zimoyin f31b50bb36 完善 XPath 定位与控件监控体验
- 增加简明到深入的 XPath 定位教程
- 保留增量控件树刷新与可编辑 Path
- 完善悬浮条条件选择和诊断

Co-Authored-By: Claude Code <noreply@anthropic.com>
2026-10-13 13:00:10 +08:00

216 lines
8.5 KiB
C#

using System;
using System.Drawing;
using System.Windows.Forms;
namespace UiaFixture
{
/// <summary>
/// A deliberately ordinary window for exercising the tool: every kind of control the tool has to
/// read (button, text box, checkbox, combo, radio, tree, list, grid, tabs) in one window, with
/// stable names and AutomationIds so a saved path keeps resolving.
///
/// This exists because the PACS/OCS clients either expose nothing (CEF shells) or expose a large
/// tree nobody wants to hand-verify against; here the expected answer is known.
///
/// Run it, then in the tool: 刷新窗口 → select "UIA 测试夹具" → 检查选中窗口. The window title and
/// class stay the same between runs, so saved monitor entries and floating-bar conditions can be
/// built against it.
/// </summary>
public sealed class FixtureForm : Form
{
private readonly Label _status;
private readonly TextBox _input;
private readonly CheckBox _check;
private readonly ComboBox _combo;
private readonly TreeView _tree;
private readonly ListView _list;
private readonly DataGridView _grid;
public FixtureForm()
{
Text = "UIA 测试夹具";
Name = "FixtureForm";
StartPosition = FormStartPosition.Manual;
Location = new Point(60, 60);
Size = new Size(760, 620);
MinimumSize = new Size(600, 480);
var tabs = new TabControl { Dock = DockStyle.Fill, Name = "FixtureTabs" };
// ---- page 1: the everyday controls
var page = new TabPage("控件") { Name = "ControlsPage" };
var panel = new Panel { Dock = DockStyle.Fill, Padding = new Padding(10) };
var button = new Button
{
Text = "测试按钮",
Name = "FixtureButton",
AutoSize = true,
Location = new Point(12, 12)
};
button.Click += delegate { SetStatus("按钮被点击:" + DateTime.Now.ToString("HH:mm:ss")); };
_input = new TextBox
{
Name = "FixtureTextBox",
Text = "可编辑文本",
Location = new Point(140, 14),
Width = 220
};
_input.TextChanged += delegate { SetStatus("文本框内容已改为:" + _input.Text); };
_check = new CheckBox
{
Text = "启用选项",
Name = "FixtureCheckBox",
Location = new Point(12, 50),
AutoSize = true
};
_check.CheckedChanged += delegate { SetStatus("复选框:" + (_check.Checked ? "选中" : "未选中")); };
var radioA = new RadioButton { Text = "选项 A", Name = "FixtureRadioA", Location = new Point(140, 50), AutoSize = true, Checked = true };
var radioB = new RadioButton { Text = "选项 B", Name = "FixtureRadioB", Location = new Point(240, 50), AutoSize = true };
radioA.CheckedChanged += delegate { SetStatus("单选:A"); };
radioB.CheckedChanged += delegate { SetStatus("单选:B"); };
_combo = new ComboBox
{
Name = "FixtureComboBox",
DropDownStyle = ComboBoxStyle.DropDownList,
Location = new Point(12, 80),
Width = 200
};
_combo.Items.AddRange(new object[] { "第一项", "第二项", "第三项" });
_combo.SelectedIndex = 0;
_combo.SelectedIndexChanged += delegate { SetStatus("下拉选择:" + _combo.SelectedItem); };
var listLabel = new Label { Text = "列表(两列)", AutoSize = true, Location = new Point(12, 116) };
_list = new ListView
{
Name = "FixtureListView",
View = View.Details,
FullRowSelect = true,
Location = new Point(12, 138),
Size = new Size(320, 150)
};
_list.Columns.Add("姓名", 120);
_list.Columns.Add("编号", 100);
for (int index = 1; index <= 3; index++)
{
_list.Items.Add(new ListViewItem(new[] { "项目 " + index, "ID" + index }));
}
_tree = new TreeView
{
Name = "FixtureTreeView",
Location = new Point(348, 138),
Size = new Size(360, 150)
};
TreeNode root = _tree.Nodes.Add("根节点");
root.Nodes.Add("子节点 1");
root.Nodes.Add("子节点 2");
root.ExpandAll();
_status = new Label
{
Name = "FixtureStatusLabel",
Text = "还没有操作。",
AutoSize = false,
Height = 22,
Location = new Point(12, 296),
Width = 700,
ForeColor = Color.DarkSlateGray
};
panel.Controls.Add(button);
panel.Controls.Add(_input);
panel.Controls.Add(_check);
panel.Controls.Add(radioA);
panel.Controls.Add(radioB);
panel.Controls.Add(_combo);
panel.Controls.Add(listLabel);
panel.Controls.Add(_list);
panel.Controls.Add(_tree);
panel.Controls.Add(_status);
page.Controls.Add(panel);
// ---- page 2: a grid, for the list reader
var gridPage = new TabPage("表格") { Name = "GridPage" };
_grid = new DataGridView
{
Name = "FixtureDataGrid",
Dock = DockStyle.Fill,
AllowUserToAddRows = false,
ReadOnly = true,
AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill
};
_grid.Columns.Add("序号", "序号");
_grid.Columns.Add("内容", "内容");
_grid.Columns.Add("状态", "状态");
for (int index = 1; index <= 5; index++)
{
_grid.Rows.Add(index.ToString(), "第 " + index + " 行内容", index % 2 == 0 ? "已完成" : "待处理");
}
gridPage.Controls.Add(_grid);
// ---- page 3: a nested container, for "the list is inside the picked element"
var nestedPage = new TabPage("嵌套") { Name = "NestedPage" };
var outer = new Panel { Dock = DockStyle.Fill, Padding = new Padding(8), Name = "NestedOuter" };
var middle = new Panel { Dock = DockStyle.Fill, Padding = new Padding(8), Name = "NestedMiddle", BackColor = Color.WhiteSmoke };
var innerList = new ListBox { Dock = DockStyle.Fill, Name = "NestedListBox" };
for (int index = 1; index <= 4; index++)
{
innerList.Items.Add("嵌套列表项 " + index);
}
middle.Controls.Add(innerList);
outer.Controls.Add(middle);
nestedPage.Controls.Add(outer);
tabs.TabPages.Add(page);
tabs.TabPages.Add(gridPage);
tabs.TabPages.Add(nestedPage);
Controls.Add(tabs);
// A second top-level window so "which window" itself can be tested.
var secondary = new Form
{
Text = "UIA 测试夹具 - 第二个窗口",
Name = "FixtureSecondWindow",
Owner = this,
StartPosition = FormStartPosition.Manual,
Location = new Point(840, 60),
Size = new Size(360, 220)
};
var secondaryButton = new Button
{
Text = "第二个窗口的按钮",
Name = "FixtureSecondButton",
Location = new Point(20, 24),
AutoSize = true
};
secondaryButton.Click += delegate { SetStatus("第二个窗口的按钮被点击。"); };
secondary.Controls.Add(secondaryButton);
secondary.Shown += delegate { secondary.Location = new Point(Location.X + Width + 20, Location.Y); };
AddOwnedForm(secondary);
}
private void SetStatus(string text)
{
_status.Text = DateTime.Now.ToString("HH:mm:ss") + " " + text;
}
}
internal static class Program
{
[STAThread]
private static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new FixtureForm());
}
}
}