?? tabgroupsequence.cs
字號:
{
// Create a resizing bar
ResizeBar bar = new ResizeBar(_direction, this);
_control.Controls.Add(bar);
_control.Controls.SetChildIndex(bar, childPos++);
}
// Add new child control in its place
_control.Controls.Add(tgb.GroupControl);
_control.Controls.SetChildIndex(tgb.GroupControl, childPos++);
// Insert at current position
_children.Insert(index, tgb);
// Adjust variables to reflect increased size
index++;
count++;
firstInsert = false;
}
// Assign any remainder to last group
_children[index-1].RealSpace += temp - totalAllocated;
// Need controls repositioned
changed = true;
// Mark layout as dirty
if (_tabbedGroups.AutoCalculateDirty)
_tabbedGroups.Dirty = true;
}
}
}
}
// Change in contents requires entries to be repositioned
if (changed)
RepositionChildren();
}
protected TabGroupBase Add(TabGroupBase group)
{
// Remember reference
_children.Add(group);
// First group added to sequence?
if (_children.Count == 1)
{
// Add new child control
_control.Controls.Add(group.GroupControl);
}
else
{
// Create a resizing bar
ResizeBar bar = new ResizeBar(_direction, this);
// Append resize bar between existing entries and new entry
_control.Controls.Add(bar);
// Append new group control
_control.Controls.Add(group.GroupControl);
}
if (!_tabbedGroups.Initializing)
{
// Allocate space for the new child
AllocateSpace(group);
// Update child layout to reflect new proportional spacing values
RepositionChildren();
}
// Mark layout as dirty
if (_tabbedGroups.AutoCalculateDirty)
_tabbedGroups.Dirty = true;
return group;
}
protected TabGroupBase Insert(int index, TabGroupBase group)
{
// Range check index
if (index < 0)
throw new ArgumentOutOfRangeException("index", index, "Insert index must be at least 0");
if (index >= _children.Count)
throw new ArgumentOutOfRangeException("index", index, "Cannot insert after end of current entries");
// Remember reference
_children.Insert(index, group);
// Create a resizing bar
ResizeBar bar = new ResizeBar(_direction, this);
// Append resize bar between existing entries and new entry
_control.Controls.Add(bar);
// Append new group control
_control.Controls.Add(group.GroupControl);
// Inserting at start of collection?
if (index == 0)
{
// Reposition the bar and group to start of collection
_control.Controls.SetChildIndex(bar, 0);
_control.Controls.SetChildIndex(group.GroupControl, 0);
}
else
{
// Find correct index taking into account number of resize bars
int pos = index * 2 - 1;
// Reposition the bar and Window to correct relative ordering
_control.Controls.SetChildIndex(bar, pos++);
_control.Controls.SetChildIndex(group.GroupControl, pos);
}
// Allocate space for the new child
AllocateSpace(group);
// Update child layout to reflect new proportional spacing values
RepositionChildren();
// Mark layout as dirty
if (_tabbedGroups.AutoCalculateDirty)
_tabbedGroups.Dirty = true;
return group;
}
internal void Replace(TabGroupBase orig, TabGroupBase replace)
{
// Find array position of old item
int origPos = _children.IndexOf(orig);
// Transfer across the space occupied
replace.RealSpace = orig.RealSpace;
// Is this the only Window entry?
if (_children.Count == 1)
{
// Remove Window from appearance
// Use helper method to circumvent form Close bug
ControlHelper.RemoveAt(_control.Controls, 0);
}
else
{
int pos = 0;
// Calculate position of Window to remove
if (origPos != 0)
pos = origPos * 2 - 1;
// Remove Window and bar
// Use helper method to circumvent form Close bug
ControlHelper.RemoveAt(_control.Controls, pos);
ControlHelper.RemoveAt(_control.Controls, pos);
}
// Inserting at start of collection?
if (origPos == 0)
{
if (_children.Count > 1)
{
// Create a resizing bar
ResizeBar bar = new ResizeBar(_direction, this);
// Append resize bar between existing entries and new entry
_control.Controls.Add(bar);
// Reposition the bar and group to start of collection
_control.Controls.SetChildIndex(bar, 0);
}
// Append new group control
_control.Controls.Add(replace.GroupControl);
// Reposition the bar and group to start of collection
_control.Controls.SetChildIndex(replace.GroupControl, 0);
}
else
{
// Create a resizing bar
ResizeBar bar = new ResizeBar(_direction, this);
// Append resize bar between existing entries and new entry
_control.Controls.Add(bar);
// Append new group control
_control.Controls.Add(replace.GroupControl);
// Find correct index taking into account number of resize bars
int pos = origPos * 2 - 1;
// Reposition the bar and Window to correct relative ordering
_control.Controls.SetChildIndex(bar, pos++);
_control.Controls.SetChildIndex(replace.GroupControl, pos);
}
// Update parentage
replace.SetParent(this);
// Replace the entry
_children[origPos] = replace;
// Update child layout to reflect new proportional spacing values
RepositionChildren();
// Mark layout as dirty
if (_tabbedGroups.AutoCalculateDirty)
_tabbedGroups.Dirty = true;
}
protected void AllocateSpace(TabGroupBase newGroup)
{
// Is this the only group?
if (_children.Count == 1)
{
// Give it all the space
newGroup.Space = 100m;
}
else
{
// Calculate how much space it should have
Decimal newSpace = 100m / _children.Count;
// How much space should we steal from each of the others
Decimal reduceSpace = newSpace / (_children.Count - 1);
// Actual space acquired so far
Decimal allocatedSpace = 0m;
foreach(TabGroupBase group in _children)
{
// Only process existing entries, not the new one
if (group != newGroup)
{
// How much space does the group currently have
Decimal currentSpace = group.Space;
// How much space to steal from it
Decimal xferSpace = reduceSpace;
// If group has less space then we want, just steal all it has
if (currentSpace < xferSpace)
xferSpace = currentSpace;
// Transfer the space across
currentSpace -= xferSpace;
// Round the sensible number of decimal places
currentSpace = Decimal.Round(currentSpace, SPACE_PRECISION);
// Update window with new space allocation
group.Space = currentSpace;
// Total up total space of all entries except new one
allocatedSpace += currentSpace;
}
}
// Assign all remaining space to new entry
newGroup.Space = 100m - allocatedSpace;
}
}
protected void RemoveWindowSpace(Decimal space)
{
// Are there any children to process?
if (_children.Count != 0)
{
// Is there only a single group left?
if (_children.Count == 1)
{
// Give it all the space
_children[0].Space = 100m;
}
else
{
// Is there any space to reallocate?
if (space > 0)
{
// Total up all the values
Decimal totalAllocated = 0m;
// How much space should we add to each of the others
Decimal freedSpace = space / _children.Count;
foreach(TabGroupBase group in _children)
{
// We only retain a sensible level of precision
Decimal newSpace = Decimal.Round(group.Space + freedSpace, SPACE_PRECISION);
// Assign back new space
group.Space = newSpace;
// Total up all space so far
totalAllocated += newSpace;
}
// Look for minor errors because not all fractions can be accurately represented in binary!
if (totalAllocated > 100m)
{
// Remove from first entry
_children[0].Space -= totalAllocated - 100m;
}
else if (totalAllocated < 100m)
{
// Add to first entry
_children[0].Space += 100m - totalAllocated;
}
}
}
}
}
protected void RepositionChildren()
{
// Area available for repositioning
Rectangle clientRect = _control.ClientRectangle;
// Is there anything to reposition?
if (_children.Count > 0)
{
// Space available for allocation
int space;
// Starting position of first control
int delta;
// Values depend on sequence direction
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -