Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. a problem in UserControl

a problem in UserControl

Scheduled Pinned Locked Moved C#
helpcsharpquestion
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dehghan1984
    wrote on last edited by
    #1

    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

    J 1 Reply Last reply
    0
    • D dehghan1984

      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

      J Offline
      J Offline
      jeyapandian
      wrote on last edited by
      #2

      http://support.microsoft.com/default.aspx?scid=kb;en-us;813450[^] try this... good luck

      Where there is a will,there is a way.

      D 1 Reply Last reply
      0
      • J jeyapandian

        http://support.microsoft.com/default.aspx?scid=kb;en-us;813450[^] try this... good luck

        Where there is a will,there is a way.

        D Offline
        D Offline
        dehghan1984
        wrote on last edited by
        #3

        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?

        J 1 Reply Last reply
        0
        • D dehghan1984

          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?

          J Offline
          J Offline
          jeyapandian
          wrote on last edited by
          #4

          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.

          D 1 Reply Last reply
          0
          • J jeyapandian

            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.

            D Offline
            D Offline
            dehghan1984
            wrote on last edited by
            #5

            Thanks, But when i drag a control to my User Control, 'Child' is not a child control of this parent error occurred

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups