C# 指标维护控件设置字体25字体颜色蓝色去掉指标编码 指标名称 指标单位 指标类型 每个StackPanel里添加8个TextBlock 4个文本框private MaintenanceMetrics 创建Grid Grid grid = new Grid; gridRowDefinitionsAddnew
private MaintenanceMetrics() { // 创建Grid Grid grid = new Grid(); grid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(70) }); grid.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
// 创建TextBlock
TextBlock textBlock = new TextBlock()
{
Text = "指标维护",
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center,
FontSize = 25,
Foreground = Brushes.Blue
};
Grid.SetRow(textBlock, 0);
grid.Children.Add(textBlock);
// 创建内部Grid
Grid innerGrid = new Grid();
for (int i = 0; i < 5; i++)
{
innerGrid.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
}
Grid.SetRow(innerGrid, 1);
grid.Children.Add(innerGrid);
// 创建四个StackPanel
string[] labels = { "指标编码", "指标名称", "指标单位", "指标类型" };
for (int i = 0; i < 4; i++)
{
StackPanel stackPanel = new StackPanel() { Orientation = Orientation.Horizontal };
if (i == 0 || i == 1 || i == 2 || i == 3)
{
Label label = new Label() { Content = labels[i], Width = 80 };
label.Visibility = Visibility.Collapsed;
stackPanel.Children.Add(label);
}
stackPanel.Children.Add(new TextBlock() { Width = 200, FontSize = 25, Foreground = Brushes.Blue });
stackPanel.Children.Add(new TextBox() { Width = 200 });
stackPanel.Children.Add(new TextBox() { Width = 200 });
stackPanel.Children.Add(new TextBox() { Width = 200 });
Grid.SetRow(stackPanel, i);
innerGrid.Children.Add(stackPanel);
}
// 创建保存和取消Button
Button saveButton = new Button() { Content = "保存", Width = 80 };
Button cancelButton = new Button() { Content = "取消", Width = 80 };
StackPanel buttonPanel = new StackPanel() { Orientation = Orientation.Horizontal };
buttonPanel.Children.Add(saveButton);
buttonPanel.Children.Add(cancelButton);
Grid.SetRow(buttonPanel, 4);
innerGrid.Children.Add(buttonPanel);
// 设置Window属性
this.Content = grid;
this.Title = "Window";
this.Width = 800;
this.Height = 600;
原文地址: https://www.cveoy.top/t/topic/cT1l 著作权归作者所有。请勿转载和采集!