C#开发医学影像胶片打印系统(一):万能花式布局的实现思路
C#开发医学影像胶⽚打印系统(⼀):万能花式布局的实现思
本篇⽂章将介绍开发医学影像胶⽚打印系统(printscu模式)遇到不规则排版时的⼀种思路,
⼀般来讲,医院打印胶⽚时都是整张胶⽚打印,但有时需要将多个病⼈或⼀个病⼈的多个检查打印在同⼀张胶⽚上,
这时候就需要不规则排版来满⾜打印需求,使胶⽚利⽤率最⼤化。
国际惯例,先看效果:
常规打印业务流程:
1、编辑布局模板
2、载⼊布局模板
婚姻登记需要什么3、选择标记模板
4、下载与选择影像
5、微调影像
6、超清预览、发送打印
编辑布局模板:
我们在⼀个Grid中,通过⾏数和列数循环创建带边框的Border来显⽰表格,并添加⿏标事件:
          for (int i = 0; i < row; i++)
{
for (int j = 0; j < col; j++)
{
Border border = new Border
{
Width = w,
Height = h,
HorizontalAlignment = HorizontalAlignment.Left,
VerticalAlignment = VerticalAlignment.Top,
Margin = new Thickness(j * w, i * h, 0, 0),
BorderThickness = new Thickness(1),惠州旅游景点
BorderBrush = ColorHandler.GetColorBrush("#CCCCCC"),
Background = ColorHandler.GetColorBrush("#000000"),
};
border.MouseEnter += Border_MouseEnter;
border.MouseLeftButtonDown += Border_MouseLeftButtonDown;
GridTempl.Children.Add(border);
}
控制台}
点击单元格时将改变背景颜⾊,在⿏标按下时并移动⿏标,触发MouseEnter,选择多个单元格:
因为合并单元格是不能为不规则形状,所以多选的单元格整体必须为⼀个矩形,
因此多选时⾸先记录所有选中的单元格,然后通过坐标判断左上⾓和右下⾓的单元格位置,这样整体矩形的宽和⾼的范围就确定了,在此矩形范围内的单元格将⾃动全部选中:
但也有特殊情况:如果矩形范围包含⼤⼩不⼀的单元格这时候计算范围就会不准确:
通过以下⼏种情况来判断⼤单元格与⼩单元格的包含关系:
    /// <summary>
/// 筛选出已经合并的cell并计算最⼤选中范围
/// </summary>
private void CheckCell()
{
List<Border> bors = new List<Border>();
for (int i = 0; i < GridTempl.Children.Count; i++)
{
Border border = (GridTempl.Children[i] as Border);
if (((SolidColorBrush)border.Background).Color == Color.FromRgb(68, 68, 68))
{
bors.Add(border);
}
}关于马的成语
double cellMinLeft = bors[0].Margin.Left;
有可以在家做的工作吗double cellMaxLeft = 0;
double cellMinTop = bors[0].Margin.Top;
double cellMaxTop = 0;
for (int i = 0; i < bors.Count; i++)
{
if (bors[i].Margin.Left < cellMinLeft)
{
cellMinLeft = bors[i].Margin.Left;
}
if (bors[i].Margin.Top < cellMinTop)
{
cellMinTop = bors[i].Margin.Top;
}
if (bors[i].Margin.Top + bors[i].Height > cellMaxTop)
{
cellMaxTop = bors[i].Margin.Top + bors[i].Height;
}
if (bors[i].Margin.Left + bors[i].Width > cellMaxLeft)
{
cellMaxLeft = bors[i].Margin.Left + bors[i].Width;
}
}
for (int i = 0; i < GridTempl.Children.Count; i++)
{
Border otherBor = GridTempl.Children[i] as Border;
if (bors.Contains(otherBor))
{
continue;
}
//包含左上⾓
写字台高度
if (otherBor.Margin.Left > cellMinLeft
&& (otherBor.Margin.Left) < cellMaxLeft
&& otherBor.Margin.Top > cellMinTop
&& (otherBor.Margin.Top) < cellMaxTop)
{
otherBor.Background = ColorHandler.GetColorBrush("#444444");                    CheckCell();
return;
}
//包含右上⾓
if (otherBor.Margin.Left + otherBor.Width > cellMinLeft
&& (otherBor.Margin.Left + otherBor.Width) < cellMaxLeft
&& otherBor.Margin.Top > cellMinTop
&& (otherBor.Margin.Top) < cellMaxTop)
{
otherBor.Background = ColorHandler.GetColorBrush("#444444");                    CheckCell();
return;
}
//包含右下⾓
if (otherBor.Margin.Left + otherBor.Width > cellMinLeft
&& (otherBor.Margin.Left + otherBor.Width) < cellMaxLeft                            && (otherBor.Margin.Top + otherBor.Height) > cellMinTop                            && (otherBor.Margin.Top + otherBor.Height) < cellMaxTop)                {
otherBor.Background = ColorHandler.GetColorBrush("#444444");                    CheckCell();
return;
}
//包含左下⾓
if (otherBor.Margin.Left > cellMinLeft
&& (otherBor.Margin.Left) < cellMaxLeft
&& (otherBor.Margin.Top + otherBor.Height) > cellMinTop                          && (otherBor.Margin.Top + otherBor.Height) < cellMaxTop)                {
otherBor.Background = ColorHandler.GetColorBrush("#444444");                    CheckCell();
return;
}
//⽔平分割
if (otherBor.Margin.Left > cellMinLeft
&& (otherBor.Margin.Left) < cellMaxLeft
&& (otherBor.Margin.Top) <= cellMinTop
&& (otherBor.Margin.Top + otherBor.Height) >= cellMaxTop)                {
otherBor.Background = ColorHandler.GetColorBrush("#444444");                    CheckCell();
return;
}
//垂直分割
if (otherBor.Margin.Left <= cellMinLeft
&& (otherBor.Margin.Left + otherBor.Width) >= cellMaxLeft                          && (otherBor.Margin.Top) > cellMinTop
&& (otherBor.Margin.Top + otherBor.Height) < cellMaxTop)                {
otherBor.Background = ColorHandler.GetColorBrush("#444444");                    CheckCell();
return;
}
}
}
通过递归填充单元格达到矩形范围的同⾏同列⾃动选择,接下来就可以合并所选择的单元格:计算最⼤宽度和最⼤⾼度,并且使左上⾓的单元格等于最⼤宽⾼,以实现合并效果:
      //计算最⼤宽度
double w = borderFirst.Width;
for (int i = 0; i < bors.Count; i++)
{
if (bors[i] != borderFirst && borderFirst.Margin.Top == bors[i].Margin.Top)
{
w += bors[i].Width;
}
}
//计算最⼤⾼度
double h = borderFirst.Height;
for (int i = 0; i < bors.Count; i++)
{
if (bors[i] != borderFirst && borderFirst.Margin.Left == bors[i].Margin.Left)
{
h += bors[i].Height;
}
}
borderFirst.Tag = Math.Round(h / borderFirst.Height) + "#" + Math.Round(w / borderFirst.Width);
borderFirst.Width = w;
borderFirst.Height = h;
看效果:
将布局通过⾃定义格式保存到本地⽂件,就可以在排版界⾯载⼊布局模板。

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。