Draw functions don't work
-
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; } }
-
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; } }
someControl.InvalidateRegion();
Need a C# Consultant? I'm available.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway -
someControl.InvalidateRegion();
Need a C# Consultant? I'm available.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway -
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
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 -
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 HemingwayI 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.
-
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.