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. Draw functions don't work

Draw functions don't work

Scheduled Pinned Locked Moved C#
graphicshelpquestion
6 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
    Manfr3d
    wrote on last edited by
    #1

    I'm writing a geometic drawing program and thougt to be done, but as I started it and tried the functions nothing happened. Maybe it just a little problem I just don't see. The compiler says "built successfully". The functions should draw the named symbol on a white rect. The window is double buffered and is redrawn when the client size is changed. Does anyone know a solution to this problem? Thanks, and best wishes using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace Geo { public partial class Geo : Form { private System.Drawing.Image ImBuffer; private System.Drawing.Graphics GrDisplay; public Geo() { InitializeComponent(); SetStyle(System.Windows.Forms.ControlStyles.UserPaint, true); SetStyle(System.Windows.Forms.ControlStyles.AllPaintingInWmPaint, true); SetStyle(System.Windows.Forms.ControlStyles.DoubleBuffer, true); ImBuffer = new System.Drawing.Bitmap(this.ClientSize.Width, this.ClientSize.Height); GrDisplay = System.Drawing.Graphics.FromImage(ImBuffer); SolidBrush SBWhite = new SolidBrush(Color.FromArgb(255, 255, 255)); GrDisplay.FillRectangle(SBWhite, 0, 0, this.ClientSize.Width, this.ClientSize.Height); } protected override void OnClientSizeChanged(EventArgs e) { base.OnClientSizeChanged(e); ImBuffer = new System.Drawing.Bitmap(this.ClientSize.Width, this.ClientSize.Height); GrDisplay = System.Drawing.Graphics.FromImage(ImBuffer); SolidBrush SBWhite = new SolidBrush(Color.FromArgb(255, 255, 255)); GrDisplay.FillRectangle(SBWhite, 0, 0, this.ClientSize.Width, this.ClientSize.Height); } protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); System.Drawing.Graphics g = e.Graphics; g.DrawImage(ImBuffer, 220, 25); } private void exitToolStripMenuItem1_Click(object sender, EventArgs e) { OnCancel(null, null); } private void OnCancel(object sender, CancelEventArgs e) { if (e != null) { e.Cancel = true; } }

    E 1 Reply Last reply
    0
    • M Manfr3d

      I'm writing a geometic drawing program and thougt to be done, but as I started it and tried the functions nothing happened. Maybe it just a little problem I just don't see. The compiler says "built successfully". The functions should draw the named symbol on a white rect. The window is double buffered and is redrawn when the client size is changed. Does anyone know a solution to this problem? Thanks, and best wishes using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace Geo { public partial class Geo : Form { private System.Drawing.Image ImBuffer; private System.Drawing.Graphics GrDisplay; public Geo() { InitializeComponent(); SetStyle(System.Windows.Forms.ControlStyles.UserPaint, true); SetStyle(System.Windows.Forms.ControlStyles.AllPaintingInWmPaint, true); SetStyle(System.Windows.Forms.ControlStyles.DoubleBuffer, true); ImBuffer = new System.Drawing.Bitmap(this.ClientSize.Width, this.ClientSize.Height); GrDisplay = System.Drawing.Graphics.FromImage(ImBuffer); SolidBrush SBWhite = new SolidBrush(Color.FromArgb(255, 255, 255)); GrDisplay.FillRectangle(SBWhite, 0, 0, this.ClientSize.Width, this.ClientSize.Height); } protected override void OnClientSizeChanged(EventArgs e) { base.OnClientSizeChanged(e); ImBuffer = new System.Drawing.Bitmap(this.ClientSize.Width, this.ClientSize.Height); GrDisplay = System.Drawing.Graphics.FromImage(ImBuffer); SolidBrush SBWhite = new SolidBrush(Color.FromArgb(255, 255, 255)); GrDisplay.FillRectangle(SBWhite, 0, 0, this.ClientSize.Width, this.ClientSize.Height); } protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); System.Drawing.Graphics g = e.Graphics; g.DrawImage(ImBuffer, 220, 25); } private void exitToolStripMenuItem1_Click(object sender, EventArgs e) { OnCancel(null, null); } private void OnCancel(object sender, CancelEventArgs e) { if (e != null) { e.Cancel = true; } }

      E Offline
      E Offline
      Ennis Ray Lynch Jr
      wrote on last edited by
      #2

      someControl.InvalidateRegion();


      Need a C# Consultant? I'm available.
      Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway

      M 1 Reply Last reply
      0
      • E Ennis Ray Lynch Jr

        someControl.InvalidateRegion();


        Need a C# Consultant? I'm available.
        Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway

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

        If you mean, that some function definitions are made in the worng region, I checked that, but didn't find anything. May you tell me what do you exactly mean, so that I can check that again? Thanks and best wishes

        E 1 Reply Last reply
        0
        • M Manfr3d

          If you mean, that some function definitions are made in the worng region, I checked that, but didn't find anything. May you tell me what do you exactly mean, so that I can check that again? Thanks and best wishes

          E Offline
          E Offline
          Ennis Ray Lynch Jr
          wrote on last edited by
          #4

          usually when you draw by overriding paint you need to tell the application when painting is required. This is done view the Invalidate and InvalidateRegion method that is inherited from the base class control. I was just throwing it out there as a possible avenue to consider since many of the custom drawing methods I do require calls to InvalidateRegion to work correctly and efficiently.


          Need a C# Consultant? I'm available.
          Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway

          M 1 Reply Last reply
          0
          • E Ennis Ray Lynch Jr

            usually when you draw by overriding paint you need to tell the application when painting is required. This is done view the Invalidate and InvalidateRegion method that is inherited from the base class control. I was just throwing it out there as a possible avenue to consider since many of the custom drawing methods I do require calls to InvalidateRegion to work correctly and efficiently.


            Need a C# Consultant? I'm available.
            Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway

            M Offline
            M Offline
            Manfr3d
            wrote on last edited by
            #5

            I tried the invalidate methode but it didn' change anything expect for the fact that the drawn rect didn't fill up the client size as I want it. I don't think that this is the problem, I already used the double buffer in other projects without any problems.

            M 1 Reply Last reply
            0
            • M Manfr3d

              I tried the invalidate methode but it didn' change anything expect for the fact that the drawn rect didn't fill up the client size as I want it. I don't think that this is the problem, I already used the double buffer in other projects without any problems.

              M Offline
              M Offline
              Manfr3d
              wrote on last edited by
              #6

              I tried the invalidate method in another way and now it works :) Thanks much

              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