?? tabgroupsequence.cs
字號:
if (_direction == Direction.Vertical)
{
space = clientRect.Height;
delta = clientRect.Top;
}
else
{
space = clientRect.Width;
delta = clientRect.Left;
}
// Ensure this is not negative
if (space < 0)
space = 0;
int barSpace = 0;
int allocation = space;
// Create temporary array of working values
int[] positions = new int[_control.Controls.Count];
// Pass 1, allocate all the space needed for each ResizeBar and the
// minimal amount of space that each group requests.
AllocateMandatorySizes(ref positions, ref barSpace, ref space);
// Is there any more space left?
if (space > 0)
{
// Pass 2, allocate any space left over according to the requested
// percent space that each group would like to achieve.
AllocateRemainingSpace(ref positions, space);
}
// Pass 3, reposition the controls according to allocated values.
RepositionChildren(ref positions, clientRect, delta);
}
}
protected void AllocateMandatorySizes(ref int[] positions, ref int barSpace, ref int space)
{
// Process each control
for(int index=0, child=0; index<_control.Controls.Count; index++)
{
ResizeBar bar = _control.Controls[index] as ResizeBar;
// Is this a resize bar control?
if (bar != null)
{
// Length needed is dependant on direction
positions[index] = bar.Length;
// Add up how much space was allocated to ResizeBars
barSpace += positions[index];
}
else
{
Size minimal = _children[child++].MinimumSize;
// Length needed is depends on direction
if (_direction == Direction.Vertical)
positions[index] = minimal.Height;
else
positions[index] = minimal.Width;
}
// Reduce available space by that just allocated
space -= positions[index];
}
}
protected void AllocateRemainingSpace(ref int[] positions, int windowSpace)
{
// Space allocated so far
int allocated = 0;
// Process each control
for(int index=0, childIndex=0; index<_control.Controls.Count; index++)
{
Control c = _control.Controls[index];
bool isResizeBar = (c is ResizeBar);
// We do not allocate any more space for resize bars
if (!isResizeBar)
{
int extra;
// How much of remaining space does the group request to have?
extra = (int)(windowSpace / 100m * _children[childIndex++].Space);
// Is this the last group to be positioned?
if (childIndex == _children.Count)
{
// Use up all the remaining space, this handles the case of the above
// vector calculation giving rounding errors so that the last element
// needs adusting to fill exactly all the available space
extra = windowSpace - allocated;
}
// Add the extra space to any existing space it has
positions[index] += extra;
// Keep count of all allocated so far
allocated += extra;
}
}
}
protected void RepositionChildren(ref int[] positions, Rectangle clientRect, int delta)
{
// Process each control
for(int index=0; index<_control.Controls.Count; index++)
{
// Delta length for this particular control
int newDelta = positions[index];
ResizeBar bar = _control.Controls[index] as ResizeBar;
if (bar != null)
{
if (_direction == Direction.Vertical)
{
// Set new position
bar.Location = new Point(clientRect.X, delta);
bar.Width = clientRect.Width;
bar.Height = newDelta;
// Move delta down to next position
delta += newDelta;
}
else
{
// Set new position
bar.Location = new Point(delta, clientRect.Y);
bar.Height = clientRect.Height;
bar.Width = newDelta;
// Move delta across to next position
delta += newDelta;
}
}
else
{
Control c = _control.Controls[index];
if (c != null)
{
if (newDelta == 0)
c.Hide();
else
{
// Set new position/size based on direction
if (_direction == Direction.Vertical)
{
c.Location = new Point(clientRect.X, delta);
c.Width = clientRect.Width;
c.Height = newDelta;
}
else
{
c.Location = new Point(delta, clientRect.Y);
c.Height = clientRect.Height;
c.Width = newDelta;
}
if (!c.Visible)
c.Show();
// Move delta to next position
delta += newDelta;
}
}
}
}
}
protected void OnControlResize(object sender, EventArgs e)
{
// Change the layout of the children to match new size
RepositionChildren();
}
public bool CanResize(ResizeBar bar)
{
// Cannot resize when in prominent mode
if (!_tabbedGroups.ResizeBarLock && (_tabbedGroups.ProminentLeaf == null))
{
// Find position of this ResizeBar in the Controls collection
int barIndex = _control.Controls.IndexOf(bar);
// Convert from control to children indexing
int beforeIndex = (barIndex - 1) / 2;
TabGroupBase before = _children[beforeIndex];
TabGroupBase after = _children[beforeIndex + 1];
// If groups on both sides have no space then cannot resize there relative positions
if (((before.Space <= 0m) && (after.Space <= 0m)))
return false;
else
return true;
}
else
{
// Must exit prominent mode before resize can occur
return false;
}
}
public bool StartResizeOperation(ResizeBar bar, ref Rectangle screenBoundary)
{
// Find position of this ResizeBar in the Controls collection
int barIndex = _control.Controls.IndexOf(bar);
// Convert from control to children indexing
int beforeIndex = (barIndex - 1) / 2;
// Get groups before and after the resize bar
TabGroupBase before = _children[beforeIndex];
TabGroupBase after = _children[beforeIndex + 1];
// Resizing boundary is defaulted to whole control area
screenBoundary = _control.RectangleToScreen(_control.ClientRectangle);
// Find screen rectangle for the groups either side of the bar
Rectangle rectBefore = before.GroupControl.RectangleToScreen(before.GroupControl.ClientRectangle);
Rectangle rectAfter = after.GroupControl.RectangleToScreen(after.GroupControl.ClientRectangle);
// Reduce the boundary in the appropriate direction
if (_direction == Direction.Vertical)
{
screenBoundary.Y = rectBefore.Y + before.MinimumSize.Height;
screenBoundary.Height -= screenBoundary.Bottom - rectAfter.Bottom;
screenBoundary.Height -= after.MinimumSize.Height;
}
else
{
screenBoundary.X = rectBefore.X + before.MinimumSize.Width;
screenBoundary.Width -= screenBoundary.Right - rectAfter.Right;
screenBoundary.Width -= after.MinimumSize.Width;
}
// Allow resize operation to occur
return true;
}
public void EndResizeOperation(ResizeBar bar, int delta)
{
// Find position of this ResizeBar in the Controls collection
int barIndex = _control.Controls.IndexOf(bar);
// Convert from control to children indexing
int beforeIndex = (barIndex - 1) / 2;
// The Window relating to this bar must be the one before it in the collection
TabGroupBase before = _children[beforeIndex];
// Is the Window being expanded
DeltaGroupSpace(before, delta);
}
protected void DeltaGroupSpace(TabGroupBase group, int vector)
{
Rectangle clientRect = _control.ClientRectangle;
// Space available for allocation
int space;
// New pixel length of the modified group
int newLength = vector;
if (_direction == Direction.Vertical)
{
space = clientRect.Height;
// New pixel size is requested change plus original
// height minus the minimal size that is always added
newLength += group.GroupControl.Height;
newLength -= group.MinimumSize.Height;
}
else
{
space = clientRect.Width;
// New pixel size is requested change plus original
// width minus the minimal size that is always added
newLength += group.GroupControl.Width;
newLength -= group.MinimumSize.Width;
}
int barSpace = 0;
// Create temporary array of working values
int[] positions = new int[_control.Controls.Count];
// Pass 1, allocate all the space needed for each ResizeBar and the
// minimal amount of space that each Window requests.
AllocateMandatorySizes(ref positions, ref barSpace, ref space);
// What is the new percentage it needs?
Decimal newPercent = 0m;
// Is there any room to allow a percentage calculation
if ((newLength > 0) && (space > 0))
newPercent = (Decimal)newLength / (Decimal)space * 100m;
// What is the change in area
Decimal reallocate = newPercent - group.Space;
// Find the group after this one
TabGroupBase nextGroup = _children[_children.IndexOf(group) + 1];
if ((nextGroup.Space - reallocate) < 0m)
reallocate = nextGroup.Space;
// Modify the Window in question
group.Space += reallocate;
// Reverse modify the Window afterwards
nextGroup.Space -= reallocate;
// Update the visual appearance
RepositionChildren();
}
internal Control.ControlCollection ChildControls
{
get { return _control.Controls; }
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -