AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

c# - Paint Event

Ein Thema von nailor · begonnen am 24. Mai 2004 · letzter Beitrag vom 25. Mai 2004
Antwort Antwort
Benutzerbild von nailor
nailor

Registriert seit: 12. Dez 2002
Ort: Karlsruhe
1.989 Beiträge
 
#1

c# - Paint Event

  Alt 24. Mai 2004, 19:21
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
Michael N.
http://nailor.devzero.de/code/sharpmath/testing/ --- Tests, Feedback, Anregungen, ... aller Art sehr willkommen!
::: don't try so hard - it'll happen for a reason :::
  Mit Zitat antworten Zitat
Udo

Registriert seit: 19. Jan 2003
54 Beiträge
 
Delphi 8 Architect
 
#2

Re: c# - Paint Event

  Alt 25. Mai 2004, 21:09
Nicht: this.pictureBox1.CreateGraphics().FillRectangle(aB , r);

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

Prost.
  Mit Zitat antworten Zitat
Benutzerbild von nailor
nailor

Registriert seit: 12. Dez 2002
Ort: Karlsruhe
1.989 Beiträge
 
#3

Re: c# - Paint Event

  Alt 25. Mai 2004, 21:19
donkö. klappert
Michael N.
http://nailor.devzero.de/code/sharpmath/testing/ --- Tests, Feedback, Anregungen, ... aller Art sehr willkommen!
::: don't try so hard - it'll happen for a reason :::
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 09:25 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