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. How to paint embedded controls.

How to paint embedded controls.

Scheduled Pinned Locked Moved C#
tutorialhardware
2 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.
  • B Offline
    B Offline
    bradsnobar
    wrote on last edited by
    #1

    I have a user control that I would like to embed win forms controls in (for example System.Windows.Forms.Button) I would like to embed the control in a control that is a property on my user control I do not know how to then make the embedded control paint so that the user can see it. public class SideBarMenu : UserControl {    public class MyMenuItem : Control    {     public bool isActive = false;    } // ... other code omitted    protected override void OnPaint(PaintEventArgs e)    {      base.OnPaint(e);      //what do I do to paint the child controls      //that can be contained in a MyMenuItem    }   } public class Test1 {    public static void Test()      {        SideBarMenu mnu = new SideBarMenu();        MyMenuItem i = mnu.AddMenuItem("Hello");        Button b = new Button();        b.Text = "button1";        i.Controls.Add(b);      } }

    N 1 Reply Last reply
    0
    • B bradsnobar

      I have a user control that I would like to embed win forms controls in (for example System.Windows.Forms.Button) I would like to embed the control in a control that is a property on my user control I do not know how to then make the embedded control paint so that the user can see it. public class SideBarMenu : UserControl {    public class MyMenuItem : Control    {     public bool isActive = false;    } // ... other code omitted    protected override void OnPaint(PaintEventArgs e)    {      base.OnPaint(e);      //what do I do to paint the child controls      //that can be contained in a MyMenuItem    }   } public class Test1 {    public static void Test()      {        SideBarMenu mnu = new SideBarMenu();        MyMenuItem i = mnu.AddMenuItem("Hello");        Button b = new Button();        b.Text = "button1";        i.Controls.Add(b);      } }

      N Offline
      N Offline
      Nader Elshehabi
      wrote on last edited by
      #2

      Hello Maybe I'm not following you! So forgive me if I stray. You don't have to worry about painting any controls inside your custom control. Just define their sizes and locations and they will draw themselves. You have only to paint your control to be viewd properly to the user, and of course to have a valid size to view all sub-controls. So in the paint method you only have to paint your control, maybe would want to refresh() or invalidate() all sub-controls and they will draw themselves. Another event you might want to handle is AddedControl. Have a look at it on MSDN. Regards:rose:

      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