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. Custom Button Background

Custom Button Background

Scheduled Pinned Locked Moved C#
graphics
4 Posts 3 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.
  • G Offline
    G Offline
    GoldenFrog
    wrote on last edited by
    #1

    I hope I'm just missing something basic. Is it possible to have a custom background (say, gradient) for a System.Windows.Forms.Button without having to do *ALL* the drawing yourself. OnPaintBackground does not appear to be called; the paint code for Button appears to be integrated with it's background logic.

    P 1 Reply Last reply
    0
    • G GoldenFrog

      I hope I'm just missing something basic. Is it possible to have a custom background (say, gradient) for a System.Windows.Forms.Button without having to do *ALL* the drawing yourself. OnPaintBackground does not appear to be called; the paint code for Button appears to be integrated with it's background logic.

      P Offline
      P Offline
      Pradeep C
      wrote on last edited by
      #2

      I think you should be able to do this without much problem by creating a csutom control which derives from Button class. You can override the OnPaint method and call base.OnPaint() so that it would do all the normal painting required for creating a Button and the you could draw whatever you want, like gradient or ...

      --- "Drawing on my superior command of language I said nothing."

      G 1 Reply Last reply
      0
      • P Pradeep C

        I think you should be able to do this without much problem by creating a csutom control which derives from Button class. You can override the OnPaint method and call base.OnPaint() so that it would do all the normal painting required for creating a Button and the you could draw whatever you want, like gradient or ...

        --- "Drawing on my superior command of language I said nothing."

        G Offline
        G Offline
        GoldenFrog
        wrote on last edited by
        #3

        That solution will not let you paint the background and ignore the foreground. The need is to have a custom background, but let .NET draw the foreground image and text. The calculations of *where* the image and text appear is fairly convoluted due to the ImageAlign, TextAlign, and TextImageRelation properties. I have pretty much confirmed this is not possible as .NET draws the button background and image/text in one operation, giving derived classes no opportunity to inject in the process. Thank you for the answer.

        A 1 Reply Last reply
        0
        • G GoldenFrog

          That solution will not let you paint the background and ignore the foreground. The need is to have a custom background, but let .NET draw the foreground image and text. The calculations of *where* the image and text appear is fairly convoluted due to the ImageAlign, TextAlign, and TextImageRelation properties. I have pretty much confirmed this is not possible as .NET draws the button background and image/text in one operation, giving derived classes no opportunity to inject in the process. Thank you for the answer.

          A Offline
          A Offline
          Anthony Mushrow
          wrote on last edited by
          #4

          Can't you set a picture as the background of a button? and have another picture for the foreground, and text and all that other stuff? Or is it I that is confused?

          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