Click here to Skip to main content
16,020,622 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi Folks,

I am calling a user control(Say UC1) inside a panel(panel1)
then through UC1 i am again calling user control(Ssy UC2) for the same panel(panel1) by using this code in UC1:

VB
Private Sub Button_Enter_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_Enter.Click
        Panel1.Controls.Clear()
        'Panel1.BackgroundImage = My.Resources.module_2bg
        Dim obj1 As TherapyUC = New TherapyUC()

        Panel1.Controls.Add(obj1)
        obj1.Dock = DockStyle.Fill
        obj1 = Nothing
End Sub


Doing this way, creates an Error at Panel1.Controls.Add(obj1)



System.ComponentModel.Win32Exception was unhandled
ErrorCode=-2147467259
Message=Error creating window handle.
NativeErrorCode=87
Source=System.Windows.Forms
StackTrace:
at System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp)
at System.Windows.Forms.Control.CreateHandle()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.ControlCollection.Add(Control value)
at Avas.TherapyUC.Button_Enter_Click(Object sender, EventArgs e) in D:\AVAS\homebasic_27_Mar_2012\Elliptical\UserControls\TherapyUC.vb:line 86
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
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(ApplicationContext context)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at Avas.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
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()
InnerException:



Is there any other way to do this or how can i solve this..?

Every reply will be appreciated..
Posted
Comments
Sergey Alexandrovich Kryukov 7-May-13 14:44pm    
Add a tag to this question: "WinForms".
—SA
Sergey Alexandrovich Kryukov 7-May-13 14:45pm    
In which line of your code does it throws?
—SA
Sergey Alexandrovich Kryukov 7-May-13 14:46pm    
There is no such concept as "call a control". What exactly are you trying to do?

Why: "obj1 = Nothing" ??!!!
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900