Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Programmieren allgemein (https://www.delphipraxis.net/40-programmieren-allgemein/)
-   -   c# - Paint Event (https://www.delphipraxis.net/22835-c-paint-event.html)

nailor 24. Mai 2004 19:21


c# - Paint Event
 
Code:
using System;
using System.Drawing;
using System.Windows.Forms;

namespace debug
{
   public class WinForm : System.Windows.Forms.Form
   {
      private System.ComponentModel.Container components = null;
      private System.Windows.Forms.PictureBox pictureBox1;

      public WinForm()
      {
         InitializeComponent();
      }

      protected override void Dispose (bool disposing)
      {
         if (disposing)
         {
            if (components != null)
            {
               components.Dispose();
            }
         }
         base.Dispose(disposing);
      }

      private void InitializeComponent()
      {
         this.pictureBox1 = new System.Windows.Forms.PictureBox();
         this.SuspendLayout();
         // 
         // pictureBox1
         // 
         this.pictureBox1.Location = new System.Drawing.Point(16, 16);
         this.pictureBox1.Name = "pictureBox1";
         this.pictureBox1.Size = new System.Drawing.Size(264, 240);
         this.pictureBox1.Paint += new System.Windows.Forms.PaintEventHandler(this.pictureBox1_Paint);
         // 
         // WinForm
         // 
         this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
         this.ClientSize = new System.Drawing.Size(292, 266);
         this.Controls.Add(this.pictureBox1);
         this.Name = "WinForm";
         this.ResumeLayout(false);
      }

      [STAThread]
      static void Main()
      {
         Application.Run(new WinForm());
      }

      private int test = 0;

      private void pictureBox1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
      {
         test++;

         const int size       = 25;
         const int boarder = 10;
         const int gap       = 3;

         System.Drawing.SolidBrush wB = new System.Drawing.SolidBrush(Color.White);
         System.Drawing.SolidBrush bB = new System.Drawing.SolidBrush(Color.Black);

         System.Drawing.SolidBrush aB;
         System.Drawing.Rectangle r = new System.Drawing.Rectangle(0,0,size-gap,size-gap);

         for (int i = 0; i < 5; i++)
            for (int j = 0; j < 5; j++)
            {
               r.X = i * size + boarder;
               r.Y = j * size + boarder;

               if ((i+j) % 2 == 0)
                  aB = wB;
               else
                  aB = bB;

               this.pictureBox1.CreateGraphics().FillRectangle(aB, r);
            }

         this.Text = test.ToString();
      }
   }
}
waaaaarum klappt das, wenn man ein anderes fenster davor "langschiebt", aber nicht, wenn man das fenster minimiert und wiederherstellt, und auch nicht, wenn man das andere fenster, das meins verdeckt, minimiert? die caption des fensters beweist ja, dass der code eigentlich ausgeführt wird.
kann mir jemand sagen, wie ich den code hier funktionierend bekomme, oder wie ich machen kann, das ein gezeichnetes bild nicht "verloren" geht?

nailor

Udo 25. Mai 2004 21:09

Re: c# - Paint Event
 
Nicht: this.pictureBox1.CreateGraphics().FillRectangle(aB , r);

Sondern: e.Graphics.FillRectangle(aB, r);
^

Prost. :mrgreen:

nailor 25. Mai 2004 21:19

Re: c# - Paint Event
 
donkö. klappert


Alle Zeitangaben in WEZ +1. Es ist jetzt 23:14 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz