a problem in UserControl
-
I have a problem in my C# project I added a User Control in my project & added some items form Toolbox to it. the items are 2 panel(panel1,panel2). so I add this control to my window application Now I want,When I drag an item from ToolBox to my control, it locates on panel2. How can I do this.Please help me. ThanX in advance
-
I have a problem in my C# project I added a User Control in my project & added some items form Toolbox to it. the items are 2 panel(panel1,panel2). so I add this control to my window application Now I want,When I drag an item from ToolBox to my control, it locates on panel2. How can I do this.Please help me. ThanX in advance
http://support.microsoft.com/default.aspx?scid=kb;en-us;813450[^] try this... good luck
Where there is a will,there is a way.
-
http://support.microsoft.com/default.aspx?scid=kb;en-us;813450[^] try this... good luck
Where there is a will,there is a way.
That was good, if you read carefully the question, I have two panel ( Panel1 , Panel2) in my Control and i want the item from ToolBox locates on Panel2. How can i do it?
-
That was good, if you read carefully the question, I have two panel ( Panel1 , Panel2) in my Control and i want the item from ToolBox locates on Panel2. How can i do it?
hi you can overide controlsadded in your usercontrol and destroy the added component and create new instance of the same and add to your panel. but there is a problem.. as it can add to the controls to panel but you can relocate the cotrol. The code is below,sorry dont have much time to explore more in to it.Dont know how helpful its to you.. good luck. bool _tmpOnRelocate = false; protected override void OnControlAdded(ControlEventArgs e) { try { DesHost = this.Container as IDesignerHost; if (DesHost != null && e.Control.Parent == this) { if (_tmpOnRelocate) return; this.SuspendLayout(); Control _Holder = e.Control; _Holder.Location = new Point(0, 0); _tmpOnRelocate = true; IComponent _tmpComp = DesHost.CreateComponent(_Holder.GetType()); DesHost.DestroyComponent(e.Control as Component); ((Control)_tmpComp).Parent = this.panel2; this.panel2.Controls.Add(_tmpComp as Control); this.ResumeLayout(); _tmpOnRelocate = false; } else { base.OnControlAdded(e); } } catch (Exception ee) { MessageBox.Show(ee.Message); } //base.OnControlAdded(e); }
Where there is a will,there is a way.
-
hi you can overide controlsadded in your usercontrol and destroy the added component and create new instance of the same and add to your panel. but there is a problem.. as it can add to the controls to panel but you can relocate the cotrol. The code is below,sorry dont have much time to explore more in to it.Dont know how helpful its to you.. good luck. bool _tmpOnRelocate = false; protected override void OnControlAdded(ControlEventArgs e) { try { DesHost = this.Container as IDesignerHost; if (DesHost != null && e.Control.Parent == this) { if (_tmpOnRelocate) return; this.SuspendLayout(); Control _Holder = e.Control; _Holder.Location = new Point(0, 0); _tmpOnRelocate = true; IComponent _tmpComp = DesHost.CreateComponent(_Holder.GetType()); DesHost.DestroyComponent(e.Control as Component); ((Control)_tmpComp).Parent = this.panel2; this.panel2.Controls.Add(_tmpComp as Control); this.ResumeLayout(); _tmpOnRelocate = false; } else { base.OnControlAdded(e); } } catch (Exception ee) { MessageBox.Show(ee.Message); } //base.OnControlAdded(e); }
Where there is a will,there is a way.
Thanks, But when i drag a control to my User Control, 'Child' is not a child control of this parent error occurred