Note that there are some explanatory texts on larger screens.

plurals
  1. POC# Invalidate() and Update() doesn't call OnPaint()
    primarykey
    data
    text
    <pre><code> delegate void UpdateD(); protected override void OnPaint(PaintEventArgs e) { MessageBox.Show("Painting"); //other stuff } public void Repaint() { if (InvokeRequired) { UpdateD d = new UpdateD(Repaint); Invoke(d); } else { this.Invalidate(); this.Update(); } } </code></pre> <p>All of this is in the code of my form. The messagebox never shows up.</p> <p>I have: </p> <pre><code>this.SetStyle(ControlStyles.UserPaint, true); </code></pre> <p>in my forms constructor.</p> <p>I've tried making a method that does this and adding it to the paint event with: </p> <pre><code>this.Paint += new System.Windows.Forms.PaintEventHandler(this.Paint); </code></pre> <p>...But that doesn't work, either.</p> <p>Anyone know what's causing this?</p> <p>EDIT: There are a number of places where <code>.Repaint()</code> is called, and I know for a fact that they're all successfully calling the method. I've checked.</p> <p>EDIT2: I've done some debugging and came to the conclusion that it has something to do with my foreach loop inside the OnPaint operation.</p> <pre><code>foreach (Game.mob m in world.mobs) { if (m.sprite != null &amp;&amp; m.ID != PlayerID) { int xdif = Player.X &gt; m.X ? Player.X - m.X : m.X - Player.X; int ydif = Player.Y &gt; m.Y ? Player.Y - m.Y : m.Y - Player.Y; bool inRangeX = xdif &lt;= viewField ? true : false; bool inRangeY = ydif &lt;= viewField ? true : false; if (inRangeX &amp;&amp; inRangeY) { Point pos = new Point(); if (Player.X &gt; m.X) pos.X = DrawLoc.X - xdif; else pos.X = DrawLoc.X + xdif; if (Player.Y &gt; m.Y) pos.Y = DrawLoc.Y - ydif; else pos.Y = DrawLoc.Y + ydif; if (ConfigurationManager.AppSettings["Debug"] == "1") SetText("Drawing mob"); newGraphics.DrawImage(m.sprite, pos); } } } </code></pre> <p><code>Game.mob</code> is my class that contains X and Y positions along with the Image to draw. <code>world.mobs</code> is a list of all mobs. <code>Player</code> is declared earlier in the code.</p> <p>The code above is supposed to draw every mob that is in sight relative to the player. Strange thing is, I use this exact code in another program and it works pretty much flawlessly, but in this program it completely breaks the code. If the foreach loop performs any iterations at all none of the code in the OnPaint method (not even the code before the loop) is executed at all.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload