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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. WindowsControl Background

WindowsControl Background

Scheduled Pinned Locked Moved C#
question
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.
  • M Offline
    M Offline
    Mazdak
    wrote on last edited by
    #1

    I want to paint some colors on the background of my costom windows control and have some button and ... on it.If I overriden the OnPaint and do my painting there,It draw them in front of all things and nothing else is shown.How can I paint background and add controls in front of it? Thanks Mazy No sig. available now.

    S 1 Reply Last reply
    0
    • M Mazdak

      I want to paint some colors on the background of my costom windows control and have some button and ... on it.If I overriden the OnPaint and do my painting there,It draw them in front of all things and nothing else is shown.How can I paint background and add controls in front of it? Thanks Mazy No sig. available now.

      S Offline
      S Offline
      sumeat
      wrote on last edited by
      #2

      I tried the same and it works. The background color of the custom control did not hide any controls on it. How are you doing it? Can you paste your code or some pseudo-code Suhas

      M 1 Reply Last reply
      0
      • S sumeat

        I tried the same and it works. The background color of the custom control did not hide any controls on it. How are you doing it? Can you paste your code or some pseudo-code Suhas

        M Offline
        M Offline
        Mazdak
        wrote on last edited by
        #3

        Simply add this lines to th control:

        private void UserControl1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
        {
        Rectangle rect = new Rectangle(0,0,this.Size.Width,this.Size.Height);
        e.Graphics.FillRectangle(new System.Drawing.Drawing2D.LinearGradientBrush(rect,m_bkcolor1,m_bkcolor2,m_lineargradientmode),rect);
        }

        But I after I add these two styles it works correctly,but I think it should be works without these two styles too:

        this.SetStyle(ControlStyles.UserPaint,true);
        this.SetStyle(ControlStyles.AllPaintingInWmPaint,true);

        Mazy No sig. available now.

        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