SidebarLibrary.WinControls.OutlookBar.SetCurrentBand C# (CSharp) Method

SetCurrentBand() private method

private SetCurrentBand ( int index ) : void
index int
return void
		public void SetCurrentBand(int index)
		{
			// If in design mode and index equals -1 just don't do anything
			if ( DesignMode && index == -1 )
				return;

			// Make sure index is valid
			Debug.Assert(index >= 0 && index < bands.Count, "Invalid Band Index");
			// Don't do anything if requested to set it to the same one
			if ( currentBandIndex == index)
				return;

			// Hide current child control if any
			Control childControl;
			if ( currentBandIndex != -1 && bands.Count > 0)
			{
				OutlookBarBand oldBand = bands[currentBandIndex];
				childControl = oldBand.ChildControl;
				if ( childControl != null )
					childControl.Visible = false;
			}

			// Animate showing the new band
			if ( index != currentBandIndex )
			{
				AnimateScroll(currentBandIndex, index);
			}

			// Reset parameter
			currentBandIndex = index;
			firstItem = 0;
			lastHighlightedItem = -1;

			OutlookBarBand newBand = bands[currentBandIndex];
			childControl = newBand.ChildControl;
			if ( childControl != null )
			{
				// Make the outlookbar the parent of the child control
				// so that when we change the bounds of the control they
				// would be relative to the parent control
				// Don't do this every time since it causes flickering
				IntPtr hParent = WindowsAPI.GetParent(childControl.Handle);
				if ( hParent != Handle )
				{
					WindowsAPI.SetParent(childControl.Handle, Handle);

					// Hook up into control recreation
					childControl.HandleCreated += new EventHandler(HandleRecreated);
				}

				Rectangle rc = GetViewPortRect();
				childControl.Bounds = rc;
				childControl.Visible = true;
				childControl.Focus();
			}

			// update the bar
			Invalidate();

			// Fire property changed
			FirePropertyChanged(OutlookBarProperty.CurrentBandChanged);

		}