//============================================================ // <T>设计对齐处理。</T> // // @param alignCd 对齐方式 // @param step 间隔 //============================================================ public void DesignAlign(int alignCd, int step) { // 检查变量 if (!HasFocusControl()) { return; } if (!HasSelectControl()) { return; } // 获得焦点对象 int left = _focusControl.Location.X; int right = _focusControl.Location.X + _focusControl.Size.Width; int hmiddle = (left + right) / 2; int top = _focusControl.Location.Y; int bottom = _focusControl.Location.Y + _focusControl.Size.Height; int vmiddle = (top + bottom) / 2; // 控件集合处理 int count = Count; FObjects <FUiControl> controls = new FObjects <FUiControl>(); controls.Assign(this); if (alignCd == EUiDesignAlign.HorizontalAvg) { if (count > 3) { controls.Sort(new FUiControlLocationComparer(EUiControlLocation.X, true)); int firstX = controls.First.CenterX; int lastX = controls.Last.CenterX; int stepX = (lastX - firstX) / (count - 1); for (int n = 0; n < count; n++) { FUiControl control = controls.Get(n); control.CenterX = firstX + stepX * n; } } } else if (alignCd == EUiDesignAlign.HorizontalAvgSize) { if (count > 3) { controls.Sort(new FUiControlLocationComparer(EUiControlLocation.X, true)); int x = controls.First.Location.X; for (int n = 0; n < count; n++) { FUiControl control = controls.Get(n); control.Location.X = x; x += control.Size.Width + step; } } } else if (alignCd == EUiDesignAlign.VerticalAvg) { if (count > 3) { controls.Sort(new FUiControlLocationComparer(EUiControlLocation.Y, true)); int firstY = controls.First.CenterY; int lastY = controls.Last.CenterY; int stepY = (lastY - firstY) / (count - 1); for (int n = 0; n < count; n++) { FUiControl control = controls.Get(n); control.CenterY = firstY + stepY * n; } } } else if (alignCd == EUiDesignAlign.VerticalAvgSize) { if (count > 3) { controls.Sort(new FUiControlLocationComparer(EUiControlLocation.Y, true)); int y = controls.First.Location.Y; for (int n = 0; n < count; n++) { FUiControl control = controls.Get(n); control.Location.Y = y; y += control.Size.Height + step; } } } else { // 处理其他情况 foreach (FUiControl control in this) { // 检查控件 if (control == _focusControl) { continue; } // 对齐处理 switch (alignCd) { case EUiDesignAlign.Center: control.Location.X = hmiddle - (control.Size.Width >> 1); control.Location.Y = vmiddle - (control.Size.Height >> 1); break; case EUiDesignAlign.Left: control.Location.X = left; break; case EUiDesignAlign.HorizontalMiddle: control.Location.X = hmiddle - (control.Size.Width >> 1); break; case EUiDesignAlign.Right: control.Location.X = right - control.Size.Width; break; case EUiDesignAlign.Top: control.Location.Y = top; break; case EUiDesignAlign.VerticalMiddle: control.Location.Y = vmiddle - (control.Size.Height >> 1); break; case EUiDesignAlign.Bottom: control.Location.Y = bottom - control.Size.Height; break; } } } }
//============================================================ // <T>刷新对象块到外部。</T> // // @param items 对象数组 //============================================================ public void Flush(FObjects <T> items) { items.Assign(_items, 0, _count); Array.Clear(_items, 0, _items.Length); _count = 0; }