ERLEDIGT
JA
JA
ANTWORTEN
4
4
ZUGRIFFE
854
854
EMPFEHLEN
-
Hallo leute,
Ich habe in meinem Project die OnPaint Methode überschrieben.
Das problem ist nur, dass der dabei nie zum ende kommt, da er immer wieder von forne beginnt.
MFG 01
Code :1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace Mandelbrot { public partial class Form1 : Form { private bool painted = false; private const int MaxIterations = 50; //Region private const float Min_X = -2.2F; private const float Max_X = 1F; private const float Min_Y = -1.2F; private const float Max_Y = 1.2F; //Startpunkt private float X_Min = Min_X; private float X_Max = Max_X; private float Y_Min = Min_Y; private float Y_Max = Max_Y; public Form1() { InitializeComponent(); } protected override void OnPaint(PaintEventArgs e) { if (!painted) { base.OnPaint(e); painted = true; const float Max_Squared = 2.0F; GetProportion(); int count; float XC, YC, dXC, dYC, XZ, YZ, XZ2, YZ2; int wi = this.Width; int hi = this.Height; dXC = (X_Max - X_Min) / (wi - 1); dYC = (Y_Max - Y_Min) / (hi - 1); XC = X_Min; for (float i = 0F; i <= wi - 1; i++) { YC = Y_Min; for (float j = 0F; j <= hi - 1; j++) { XZ = 0; YZ = 0; XZ2 = 0; YZ2 = 0; count = 0; while (count < MaxIterations && XZ < Max_Squared && YZ < Max_Squared) { XZ2 = XZ * XZ; YZ2 = YZ * YZ; YZ = 2 * YZ * XZ + YC; XZ = XZ2 - YZ2 + XC; count++; } //Color C = Color.FromArgb(count, count, count); //Pen P=new Pen(C); Pen P = new Pen(Color.Black); if (!(count < MaxIterations)) { e.Graphics.DrawLine(P, i, j, i + 0.1F, j + 0.1F); } YC = YC + dYC; } XC = XC + dXC; } painted = false; } } private void GetProportion() { float Proportion, FormProportion; float hi, wi, mid; Proportion = (Y_Max - Y_Min) / (X_Max - X_Min); FormProportion = float.Parse(this.Height.ToString()) / float.Parse(this.Width.ToString()); if (Proportion > FormProportion) { wi = (Y_Max - Y_Min) / FormProportion; mid = (X_Min + X_Max) / 2F; X_Min = mid - wi / 2F; X_Max = mid + wi / 2F; } else { hi = (X_Max - X_Min) * FormProportion; mid = (Y_Min + Y_Max) / 2F; Y_Min = mid - hi / 2F; Y_Max = mid + hi / 2F; } } private void Form1_Resize(object sender, EventArgs e) { this.Invalidate(); } } }
-
10.02.09 23:21 #2Ch Tutorials.de Gastzugang
Hallo,
du sagst beim Einstieg deiner Funktion " painted = true;" aber überschreibst es am Ende wieder mit " painted = false;" somit ist kein Abbruch möglich und "if (!painted)" ist immer gegeben. Ein Rückgabeparameter wäre nicht schlecht.
Code :1 2 3
protected override bool OnPaint(PaintEventArgs e) return painted;
Gruss
-
Hi
Hab deinen Code grad kopiert. Das Programm funktioniert ohne Probleme. Der Code wird einmal ausgeführt, wenn kein weiteres Zeichnen von Nöten ist.
Wie hast du denn festgestellt, das das Paint mehrfach ausgeführt wird?Grüße Nico
----------------------
Xing
----------------------
Zitat von Mark Twain (1835-1910)
Zitat von Mike Wilson - Biographie über Larry Ellison (CEO Oracle)
-
Und die Variable painted ist sinnlos.
Solltest du diese am Ende doch mal auf true setzen
, verschwindet dein gezeichnes eh bei der nächsten Aufforderung zum neuzeichnen des Formulars.
Wenn du diesen Zustand also aus irgend einem Grund halten musst, zeichne auf ein Bitmap.
Code :1 2 3 4 5 6 7 8 9
Bitmap bmp=new Bitmap(width, height) using(Graphics g=Graphics.FromImage(bmp)) { g.Draw(....); //zeichnen g.Flush(); //Zeichen Operationen ausführen } form.BackGroundImage=bmp;
-
Hallo leute,
habe das Painted herrausgenommen.
Das Property "DoubleBuffered = true;" hat mir gehollfen, da das Bild erst berechnet wird befor es angezeigt bekommt.
Hier der ganze Quellcode:
Code :1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace Mandelbrot { public partial class Form1 : Form { private const int MaxIterations = 255; //Region private const float Min_X = -2.2F; private const float Max_X = 1F; private const float Min_Y = -1.2F; private const float Max_Y = 1.2F; //Startpunkt private float X_Min = Min_X; private float X_Max = Max_X; private float Y_Min = Min_Y; private float Y_Max = Max_Y; public Form1() { DoubleBuffered = true; InitializeComponent(); } protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); const float Max_Squared = 2.0F; GetProportion(); int count; float XC, YC, dXC, dYC, XZ, YZ, XZ2, YZ2; int wi = this.Width; int hi = this.Height; dXC = (X_Max - X_Min) / (wi - 1); dYC = (Y_Max - Y_Min) / (hi - 1); XC = X_Min; for (float i = 0F; i <= wi - 1; i++) { YC = Y_Min; for (float j = 0F; j <= hi - 1; j++) { XZ = 0; YZ = 0; XZ2 = 0; YZ2 = 0; count = 0; while (count < MaxIterations && XZ < Max_Squared && YZ < Max_Squared) { XZ2 = XZ * XZ; YZ2 = YZ * YZ; YZ = 2F * YZ * XZ + YC; XZ = XZ2 - YZ2 + XC; count++; } Color C = Color.FromArgb(10, count, 10); Pen P = new Pen(C); //Pen P = new Pen(Color.Black); //if (!(count < MaxIterations)) //{ e.Graphics.DrawLine(P, i, j, i + 0.1F, j + 0.1F); //} YC = YC + dYC; } XC = XC + dXC; } } private void GetProportion() { float Proportion, FormProportion; float hi, wi, mid; Proportion = (Y_Max - Y_Min) / (X_Max - X_Min); FormProportion = float.Parse(this.Height.ToString()) / float.Parse(this.Width.ToString()); if (Proportion > FormProportion) { wi = (Y_Max - Y_Min) / FormProportion; mid = (X_Min + X_Max) / 2F; X_Min = mid - wi / 2F; X_Max = mid + wi / 2F; } else { hi = (X_Max - X_Min) * FormProportion; mid = (Y_Min + Y_Max) / 2F; Y_Min = mid - hi / 2F; Y_Max = mid + hi / 2F; } } private void Form1_Resize(object sender, EventArgs e) { this.Invalidate(); } } }
Aber wenn ich das Propperty herrausnehme kann er das nicht zuende Zeichnen.
Das ist allerdings nur bei mir. Auf der Arbeit funktioniert alles perfect!
MFG 01
Ähnliche Themen
-
GDI+ Grafik / OnPaint
Von TheShihan im Forum VisualStudio & MFCAntworten: 7Letzter Beitrag: 27.02.08, 10:04 -
OnPaint event hook
Von KainPlan im Forum C/C++Antworten: 5Letzter Beitrag: 26.02.08, 11:44 -
BMPs anzeigen durch OnPaint()
Von BlackD0G im Forum VisualStudio & MFCAntworten: 13Letzter Beitrag: 01.06.06, 16:47 -
Bewegung in PaintBox/OnPaint auslösen?
Von r_Alf im Forum Borland CBuilder und VCLAntworten: 2Letzter Beitrag: 10.04.06, 12:18 -
OnPaint() selbst auslösen
Von ensae im Forum VisualStudio & MFCAntworten: 3Letzter Beitrag: 27.02.04, 18:28





Zitieren

Login





