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. When Adding A Control, what events fire? [modified]

When Adding A Control, what events fire? [modified]

Scheduled Pinned Locked Moved C#
graphicsdockerquestion
3 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
    Duraplex
    wrote on last edited by
    #1

    I'm building a custom control inherited from a picturebox control, and I would like it to automatically resize to the dimensions of the container control to which it is added(could be any valid container control) Referencing the Parent of the custom control in its structure definition Public MycustomePicBox() { this.Size=new System.Drawing.Size(this.Parent.Clientrectangle.... } isn't possible because at the time the code executes, the custom control hasn't been added to the container control yet. Is there an event that fires for a Control when it has been added to a container?

    modified on Sunday, March 29, 2009 10:43 PM

    M 1 Reply Last reply
    0
    • D Duraplex

      I'm building a custom control inherited from a picturebox control, and I would like it to automatically resize to the dimensions of the container control to which it is added(could be any valid container control) Referencing the Parent of the custom control in its structure definition Public MycustomePicBox() { this.Size=new System.Drawing.Size(this.Parent.Clientrectangle.... } isn't possible because at the time the code executes, the custom control hasn't been added to the container control yet. Is there an event that fires for a Control when it has been added to a container?

      modified on Sunday, March 29, 2009 10:43 PM

      M Offline
      M Offline
      maxatlis
      wrote on last edited by
      #2

      I hope I haven’t got the wrong end of the stick of what you’re trying to achieve. I’ve just had a quick look, and found that there’s an event available for when controls are added to a user control. Try using the ControlAdded Event. To initialize it do the following… public userControl1() { InitializeComponent(); /* Please note, the code below should really be inside InitializeComponent(); But for speed, i've added it in here. Add the line below… Note: Press Tab key after typing in += as this will auto complete the rest of the event. */ this.ControlAdded+=new ControlEventHandler(userControl1_ControlAdded); } private void userControl1_ControlAdded(object sender, ControlEventArgs e) { // execute your methods for resizing to parent control. } I hope this has helped? :) P.S. I am using the latest version of C#.Net framework 3.5 so I’m guessing that these events are also available for frameworks 1.1 and 2. Rule 1 - Don’t break what’s not broken! Rule 2 - Don’t reinvent the wheel… just give it a lick of paint! Rule 3 - Keep plenty of programmer foods to hand… Pizza, beer & crisps... including the books on "How to Crash Your System in Twenty Seconds!"

      D 1 Reply Last reply
      0
      • M maxatlis

        I hope I haven’t got the wrong end of the stick of what you’re trying to achieve. I’ve just had a quick look, and found that there’s an event available for when controls are added to a user control. Try using the ControlAdded Event. To initialize it do the following… public userControl1() { InitializeComponent(); /* Please note, the code below should really be inside InitializeComponent(); But for speed, i've added it in here. Add the line below… Note: Press Tab key after typing in += as this will auto complete the rest of the event. */ this.ControlAdded+=new ControlEventHandler(userControl1_ControlAdded); } private void userControl1_ControlAdded(object sender, ControlEventArgs e) { // execute your methods for resizing to parent control. } I hope this has helped? :) P.S. I am using the latest version of C#.Net framework 3.5 so I’m guessing that these events are also available for frameworks 1.1 and 2. Rule 1 - Don’t break what’s not broken! Rule 2 - Don’t reinvent the wheel… just give it a lick of paint! Rule 3 - Keep plenty of programmer foods to hand… Pizza, beer & crisps... including the books on "How to Crash Your System in Twenty Seconds!"

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

        I think that event fires for the container control.

        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