示例#1
0
		private void RemoveSlice(Slice gonner, int index)
		{
			gonner.AboutToDiscard();
			gonner.SplitCont.SplitterMoved -= new SplitterEventHandler(slice_SplitterMoved);
			Controls.RemoveAt(index);

			// Reset CurrentSlice, if appropriate.
			if (gonner == m_currentSlice)
			{
				Slice newCurrent = null;
				if (Controls.Count > index)
				{
					// Get the one at the same index (next one after the one being removed).
					newCurrent = Controls[index] as Slice;
				}
				else if (Controls.Count > 0 && Controls.Count > index - 1)
				{
					// Get the one before index.
					newCurrent = Controls[index - 1] as Slice;
				}
				if (newCurrent != null)
				{
					CurrentSlice = newCurrent;
				}
				else
				{
					m_currentSlice = null;
					gonner.SetCurrentState(false);
				}
			}
			// Since "gonner's" SliceTreeNode still is referenced by m_tooltip,
			// (if it has one at all, that is),
			// we have to also remove with ToolTip for gonner,
			// Since the dumb MS ToolTip class can't just remove one,
			// we have to remove them all and re-add the remaining ones
			// in order to have it really turn loose of the SliceTreeNode.
			// But, only do all of that, if it actually has a ToolTip.
			bool gonnerHasToolTip = (gonner.ToolTip != null);
			if (gonnerHasToolTip)
				m_tooltip.RemoveAll();
			gonner.Dispose();
			// Now, we need to re-add all of the surviving tooltips.
			if (gonnerHasToolTip)
			{
				foreach (Slice keeper in Controls)
					SetToolTip(keeper);
			}

			ResetTabIndices(index);
		}