hey guys,

was having a great time with SkyBound's FreeStyle when i ran into a very funny problem. On removing a tabpage from the tabcontrol which is using the FreeStyle component, i get an error when executing the following line:

this.Controls.Remove(this.TabPages[SelectedIndex]);

exception thrown is:
System.ArgumentOutOfRangeException was unhandled
Message="InvalidArgument=Value of '0' is not valid for 'index'.\r\nParameter name: index"
Source="System.Windows.Forms"
ParamName="index"
StackTrace:
at System.Windows.Forms.TabControl.GetTabRect(Int32 index)
at xd7781b9627ed1947.x86e4a8bb25bfd380.xb821f4eb74ae7ed5(TabControl x43f09fa35b632ec6, Int32 xc0c4c459c6ccbd00)
at xd7781b9627ed1947.x86e4a8bb25bfd380.xd727d28790d9fe4e(Message& x6088325dec1baa2a)
at xd7781b9627ed1947.x8ec6a1317a73ae90.xf43577d7fc7fb2d4(IntPtr x96e7d32425e52ebf, Int32 x8a41fbc87a3fb305, IntPtr x716e0bc3eafdded2, IntPtr x130fbcecf32fe781)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at testing.Program.Main() in C:\Documents and Settings\lauchunghan\My Documents\Visual Studio 2005\Projects\testing\testing\Program.cs:line 17
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()

however, if i slightly modify the above code to include a messagebox, everything works fine!

if (MessageBox.Show("Close?", "Close", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
 this.Controls.Remove(this.TabPages[SelectedIndex]);
}

i really can't figure out what is wrong.

regards.

Sounds like its trying to say you cant remove either the first tab or have no tabs

hmm. interesing. but how do you explain the MessageBox inclussion? if i include it, everything will be ok. by the way, i noticed something funny too. say the tabs are arranged in this order:

tabA tabB tabC(currently selected)

if i close tabC without the MessageBox, it will throw the exception, however if i close tabA, no error will be shown. if i then close tabB, no error will be shown either. then if i close tabC, an exception will be thrown. could it be something to do with the component i'm using?

then most likely its complaining because its trying to redraw something you just deleted

This article has been dead for over six months. Start a new discussion instead.