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. overrride onpaint

overrride onpaint

Scheduled Pinned Locked Moved C#
graphicsquestion
3 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.
  • S Offline
    S Offline
    Sasuko
    wrote on last edited by
    #1

    why it doesn't work? It show the draw i want, but when i write text the draw disappear: public partial class UserControl1 : TextBox { public UserControl1() { this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint, true); this.BorderStyle = BorderStyle.None; InitializeComponent(); } protected override void OnPaint(PaintEventArgs e) { Graphics g = e.Graphics; Pen p = new Pen(Color.Red ,3.0f); g.DrawRectangle(p, new Rectangle(0, 0, this.Width, this.Height)); } }

    R L 2 Replies Last reply
    0
    • S Sasuko

      why it doesn't work? It show the draw i want, but when i write text the draw disappear: public partial class UserControl1 : TextBox { public UserControl1() { this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint, true); this.BorderStyle = BorderStyle.None; InitializeComponent(); } protected override void OnPaint(PaintEventArgs e) { Graphics g = e.Graphics; Pen p = new Pen(Color.Red ,3.0f); g.DrawRectangle(p, new Rectangle(0, 0, this.Width, this.Height)); } }

      R Offline
      R Offline
      Ravi Bhavnani
      wrote on last edited by
      #2

      Sasuko wrote:

      but when i write text the draw disappear:

      Do you mean that the text you type is never displayed? If so, I would expect this is happening because your OnPaint() method isn't writing it. /ravi My new year's resolution: 2048 x 1536 Home | Music | Articles | Freeware | Trips ravib(at)ravib(dot)com

      1 Reply Last reply
      0
      • S Sasuko

        why it doesn't work? It show the draw i want, but when i write text the draw disappear: public partial class UserControl1 : TextBox { public UserControl1() { this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint, true); this.BorderStyle = BorderStyle.None; InitializeComponent(); } protected override void OnPaint(PaintEventArgs e) { Graphics g = e.Graphics; Pen p = new Pen(Color.Red ,3.0f); g.DrawRectangle(p, new Rectangle(0, 0, this.Width, this.Height)); } }

        L Offline
        L Offline
        leppie
        wrote on last edited by
        #3

        OnPaint doesnt fire for TextBox based controls. Its by design. You will have to hack with P/Invoke.**

        xacc.ide-0.1.3.12 - Now a whole lot faster (and better)
        Consolas size screenshots (see how fractional font sizes look)

        **

        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