<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[DrawLine() im Konstruktor]]></title><description><![CDATA[<p>Hallo,</p>
<p>in dem folgenden Beispiel erzeuge ich im Konstruktor von Form1 ein Graphics-Objekt zu einem Panel (Zeile 25,33), und zeichne dann eine gelbe Linie in das Panel (Zeile 34).<br />
Weiter unten in button1_Click zeichne ich eine rote Linie in das gleiche Panel (Zeile 100). Wenn ich auf Button1 klicke, wird die rote Linie wie erwartet gezeichnet. Aber die gelbe Linie wird nie gezeichnet. Warum geht das nicht?</p>
<p>Gruss Michael</p>
<pre><code class="language-cpp">#pragma once

namespace test_7_7_2010 {

	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;

	/// &lt;summary&gt;
	/// Summary for Form1
	///
	/// WARNING: If you change the name of this class, you will need to change the
	///          'Resource File Name' property for the managed resource compiler tool
	///          associated with all .resx files this class depends on.  Otherwise,
	///          the designers will not be able to interact properly with localized
	///          resources associated with this form.
	/// &lt;/summary&gt;
	public ref class Form1 : public System::Windows::Forms::Form
	{
	public:
		Graphics^ g;

		Form1(void)
		{
			InitializeComponent();
			//
			//TODO: Add the constructor code here
			//
            g = panel1-&gt;CreateGraphics();
			g-&gt;DrawLine(gcnew Pen(Color::Yellow),0,0,50,50);
		}

	protected:
		/// &lt;summary&gt;
		/// Clean up any resources being used.
		/// &lt;/summary&gt;
		~Form1()
		{
			if (components)
			{
				delete components;
			}
		}
	private: System::Windows::Forms::Panel^  panel1;
	protected: 
	private: System::Windows::Forms::Button^  button1;

	private:
		/// &lt;summary&gt;
		/// Required designer variable.
		/// &lt;/summary&gt;
		System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
		/// &lt;summary&gt;
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// &lt;/summary&gt;
		void InitializeComponent(void)
		{
			this-&gt;panel1 = (gcnew System::Windows::Forms::Panel());
			this-&gt;button1 = (gcnew System::Windows::Forms::Button());
			this-&gt;SuspendLayout();
			// 
			// panel1
			// 
			this-&gt;panel1-&gt;Location = System::Drawing::Point(72, 32);
			this-&gt;panel1-&gt;Name = L&quot;panel1&quot;;
			this-&gt;panel1-&gt;Size = System::Drawing::Size(352, 184);
			this-&gt;panel1-&gt;TabIndex = 0;
			// 
			// button1
			// 
			this-&gt;button1-&gt;Location = System::Drawing::Point(80, 248);
			this-&gt;button1-&gt;Name = L&quot;button1&quot;;
			this-&gt;button1-&gt;Size = System::Drawing::Size(104, 56);
			this-&gt;button1-&gt;TabIndex = 1;
			this-&gt;button1-&gt;Text = L&quot;button1&quot;;
			this-&gt;button1-&gt;UseVisualStyleBackColor = true;
			this-&gt;button1-&gt;Click += gcnew System::EventHandler(this, &amp;Form1::button1_Click);
			// 
			// Form1
			// 
			this-&gt;AutoScaleDimensions = System::Drawing::SizeF(6, 13);
			this-&gt;AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this-&gt;ClientSize = System::Drawing::Size(486, 338);
			this-&gt;Controls-&gt;Add(this-&gt;button1);
			this-&gt;Controls-&gt;Add(this-&gt;panel1);
			this-&gt;Name = L&quot;Form1&quot;;
			this-&gt;Text = L&quot;Form1&quot;;
			this-&gt;ResumeLayout(false);

		}
#pragma endregion
	private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
                 g-&gt;DrawLine(gcnew Pen(Color::Red),50,50,100,100);
			 }
	};
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/270139/drawline-im-konstruktor</link><generator>RSS for Node</generator><lastBuildDate>Sun, 30 Aug 2026 13:47:55 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/270139.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 07 Jul 2010 09:24:24 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to DrawLine() im Konstruktor on Wed, 07 Jul 2010 09:24:24 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>in dem folgenden Beispiel erzeuge ich im Konstruktor von Form1 ein Graphics-Objekt zu einem Panel (Zeile 25,33), und zeichne dann eine gelbe Linie in das Panel (Zeile 34).<br />
Weiter unten in button1_Click zeichne ich eine rote Linie in das gleiche Panel (Zeile 100). Wenn ich auf Button1 klicke, wird die rote Linie wie erwartet gezeichnet. Aber die gelbe Linie wird nie gezeichnet. Warum geht das nicht?</p>
<p>Gruss Michael</p>
<pre><code class="language-cpp">#pragma once

namespace test_7_7_2010 {

	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;

	/// &lt;summary&gt;
	/// Summary for Form1
	///
	/// WARNING: If you change the name of this class, you will need to change the
	///          'Resource File Name' property for the managed resource compiler tool
	///          associated with all .resx files this class depends on.  Otherwise,
	///          the designers will not be able to interact properly with localized
	///          resources associated with this form.
	/// &lt;/summary&gt;
	public ref class Form1 : public System::Windows::Forms::Form
	{
	public:
		Graphics^ g;

		Form1(void)
		{
			InitializeComponent();
			//
			//TODO: Add the constructor code here
			//
            g = panel1-&gt;CreateGraphics();
			g-&gt;DrawLine(gcnew Pen(Color::Yellow),0,0,50,50);
		}

	protected:
		/// &lt;summary&gt;
		/// Clean up any resources being used.
		/// &lt;/summary&gt;
		~Form1()
		{
			if (components)
			{
				delete components;
			}
		}
	private: System::Windows::Forms::Panel^  panel1;
	protected: 
	private: System::Windows::Forms::Button^  button1;

	private:
		/// &lt;summary&gt;
		/// Required designer variable.
		/// &lt;/summary&gt;
		System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
		/// &lt;summary&gt;
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// &lt;/summary&gt;
		void InitializeComponent(void)
		{
			this-&gt;panel1 = (gcnew System::Windows::Forms::Panel());
			this-&gt;button1 = (gcnew System::Windows::Forms::Button());
			this-&gt;SuspendLayout();
			// 
			// panel1
			// 
			this-&gt;panel1-&gt;Location = System::Drawing::Point(72, 32);
			this-&gt;panel1-&gt;Name = L&quot;panel1&quot;;
			this-&gt;panel1-&gt;Size = System::Drawing::Size(352, 184);
			this-&gt;panel1-&gt;TabIndex = 0;
			// 
			// button1
			// 
			this-&gt;button1-&gt;Location = System::Drawing::Point(80, 248);
			this-&gt;button1-&gt;Name = L&quot;button1&quot;;
			this-&gt;button1-&gt;Size = System::Drawing::Size(104, 56);
			this-&gt;button1-&gt;TabIndex = 1;
			this-&gt;button1-&gt;Text = L&quot;button1&quot;;
			this-&gt;button1-&gt;UseVisualStyleBackColor = true;
			this-&gt;button1-&gt;Click += gcnew System::EventHandler(this, &amp;Form1::button1_Click);
			// 
			// Form1
			// 
			this-&gt;AutoScaleDimensions = System::Drawing::SizeF(6, 13);
			this-&gt;AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this-&gt;ClientSize = System::Drawing::Size(486, 338);
			this-&gt;Controls-&gt;Add(this-&gt;button1);
			this-&gt;Controls-&gt;Add(this-&gt;panel1);
			this-&gt;Name = L&quot;Form1&quot;;
			this-&gt;Text = L&quot;Form1&quot;;
			this-&gt;ResumeLayout(false);

		}
#pragma endregion
	private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
                 g-&gt;DrawLine(gcnew Pen(Color::Red),50,50,100,100);
			 }
	};
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1922590</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1922590</guid><dc:creator><![CDATA[micha7]]></dc:creator><pubDate>Wed, 07 Jul 2010 09:24:24 GMT</pubDate></item><item><title><![CDATA[Reply to DrawLine() im Konstruktor on Wed, 07 Jul 2010 09:30:24 GMT]]></title><description><![CDATA[<p>Hi,</p>
<p>was passiert denn, wenn du das Fenster mit der roten Linie verschiebst oder vergrösserst?<br />
Ich denke, dann ist die rote Linie auch weg oder?<br />
Du musst sowas in der dafür vorgesehenen Funktion (onPaint, onDraw oder sowas ähnliches) zeichnen, sonst wird das wieder übermalt.<br />
Für genauere Informationen solltest du im richtigen Froum nachfragen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1922595</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1922595</guid><dc:creator><![CDATA[Jockelx]]></dc:creator><pubDate>Wed, 07 Jul 2010 09:30:24 GMT</pubDate></item><item><title><![CDATA[Reply to DrawLine() im Konstruktor on Wed, 07 Jul 2010 09:35:52 GMT]]></title><description><![CDATA[<p>micha7 schrieb:</p>
<blockquote>
<p>Warum geht das nicht?</p>
</blockquote>
<p>Ganz einfach...</p>
<p>weil DrawLine() nicht Bestandteil der Standard Library ist... <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f621.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--pouting_face"
      title=":rage:"
      alt="😡"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1922598</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1922598</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Wed, 07 Jul 2010 09:35:52 GMT</pubDate></item><item><title><![CDATA[Reply to DrawLine() im Konstruktor on Wed, 07 Jul 2010 09:38:31 GMT]]></title><description><![CDATA[<p>hallo,</p>
<p>Jockelx schrieb:</p>
<blockquote>
<p>was passiert denn, wenn du das Fenster mit der roten Linie verschiebst</p>
</blockquote>
<p>Dann bleibt die rote Linie sichtbar.</p>
<p>Jockelx schrieb:</p>
<blockquote>
<p>oder vergrösserst?</p>
</blockquote>
<p>Dann bleibt sie ebenfalls sichtbar. Wenn man das Fenster verkleinert und dann wieder vergrössert, dann wäre die Linie weg. Aber das stört mich im Moment nicht. Die Frage ist: Warum wird die gelbe Linie gar nicht erst gezeichnet?<br />
Oder anders gefragt: Wie kann ich eine Linie zeichnen, die nach dem Programmstart sofort sichtbar sein soll?</p>
<p>Gruss<br />
Michael</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1922600</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1922600</guid><dc:creator><![CDATA[micha7]]></dc:creator><pubDate>Wed, 07 Jul 2010 09:38:31 GMT</pubDate></item><item><title><![CDATA[Reply to DrawLine() im Konstruktor on Wed, 07 Jul 2010 09:40:58 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>CSpille schrieb:</p>
<blockquote>
<p>micha7 schrieb:</p>
<blockquote>
<p>Warum geht das nicht?</p>
</blockquote>
<p>Ganz einfach...</p>
<p>weil DrawLine() nicht Bestandteil der Standard Library ist... <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f621.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--pouting_face"
      title=":rage:"
      alt="😡"
    /></p>
</blockquote>
<p>Verstehe ich noch nicht. Wieso funktioniert es dann in Zeile 100?</p>
<p>Gruss<br />
Michael</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1922603</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1922603</guid><dc:creator><![CDATA[micha7]]></dc:creator><pubDate>Wed, 07 Jul 2010 09:40:58 GMT</pubDate></item><item><title><![CDATA[Reply to DrawLine() im Konstruktor on Wed, 07 Jul 2010 09:49:09 GMT]]></title><description><![CDATA[<p>Wie gesagt: Die gelbe Linie wird gezeichnet, aber wieder übergezeichnet (so wie die Rote, bei einem Repaint-Event).<br />
Du musst die Paint-Funktion dafür überschreiben oder das Paint-Event abfangen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1922609</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1922609</guid><dc:creator><![CDATA[Jockelx]]></dc:creator><pubDate>Wed, 07 Jul 2010 09:49:09 GMT</pubDate></item><item><title><![CDATA[Reply to DrawLine() im Konstruktor on Wed, 07 Jul 2010 09:50:52 GMT]]></title><description><![CDATA[<p>micha7 schrieb:</p>
<blockquote>
<p>Hallo,</p>
<p>CSpille schrieb:</p>
<blockquote>
<p>micha7 schrieb:</p>
<blockquote>
<p>Warum geht das nicht?</p>
</blockquote>
<p>Ganz einfach...</p>
<p>weil DrawLine() nicht Bestandteil der Standard Library ist... <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f621.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--pouting_face"
      title=":rage:"
      alt="😡"
    /></p>
</blockquote>
<p>Verstehe ich noch nicht. Wieso funktioniert es dann in Zeile 100?</p>
<p>Gruss<br />
Michael</p>
</blockquote>
<p>Nein... Funktioniert es nicht...</p>
<p>Mein (nahezu Standard-konformer) Compiler kennt keine der Klassen, die du<br />
verwendest...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1922610</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1922610</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Wed, 07 Jul 2010 09:50:52 GMT</pubDate></item><item><title><![CDATA[Reply to DrawLine() im Konstruktor on Wed, 07 Jul 2010 09:50:59 GMT]]></title><description><![CDATA[<p>Zunächst bist du im falschen Unterforum gelandet. Das ist kein C++ sondern C++/CLI. Dafür gibts ein spezielles Unterforum.</p>
<p>Ansonsten kann ich mir vorstellen, dass die Linie zwar gezeichnet wird, aber gleich wieder übermalt wird. Gibt es eine Funktion, die aufgerufen wird, wenn die Form fertig geladen ist bzw. angezeigt wird? Also etwas wie Form_Show oder Form_Load?</p>
<p>Dann solltest du versuchen deinen Code zum Zeichnen dort hineinzupacken.</p>
<p>Sollte das alles nicht zum Erfolg führen, dann zeichne die Linie in der Paint-Funktion.</p>
<p>protected override void OnPaint(PaintEventArgs e)<br />
{<br />
base.OnPaint(e);</p>
<p>// Dein Code<br />
}</p>
<p>In dem Fall müsste die Linie in jedem Fall angezeigt werden. Außerdem dürfte sie nach dem Verkleinern des Fensters nicht verschwunden sein.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1922611</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1922611</guid><dc:creator><![CDATA[uuuuuuuuu]]></dc:creator><pubDate>Wed, 07 Jul 2010 09:50:59 GMT</pubDate></item><item><title><![CDATA[Reply to DrawLine() im Konstruktor on Wed, 07 Jul 2010 09:53:02 GMT]]></title><description><![CDATA[<p>uuuuuuuuu schrieb:</p>
<blockquote>
<p>Zunächst bist du im falschen Unterforum gelandet. Das ist kein C++ sondern C++/CLI. Dafür gibts ein spezielles Unterforum.</p>
</blockquote>
<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f44d.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--thumbs_up"
      title=":+1:"
      alt="👍"
    /></p>
<p>deswegen:</p>
<p>CSpille schrieb:</p>
<blockquote>
<p>weil DrawLine() nicht Bestandteil der Standard Library ist... <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f621.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--pouting_face"
      title=":rage:"
      alt="😡"
    /></p>
</blockquote>
]]></description><link>https://www.c-plusplus.net/forum/post/1922612</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1922612</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Wed, 07 Jul 2010 09:53:02 GMT</pubDate></item><item><title><![CDATA[Reply to DrawLine() im Konstruktor on Wed, 07 Jul 2010 09:56:37 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>uuuuuuuuu schrieb:</p>
<blockquote>
<p>Zunächst bist du im falschen Unterforum gelandet. Das ist kein C++ sondern C++/CLI. Dafür gibts ein spezielles Unterforum.</p>
</blockquote>
<p>Sorry, das war mein Fehler. Ich habe es aus Versehen ins falsche Unterforum geschrieben.</p>
<p>Gruss<br />
Michael</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1922615</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1922615</guid><dc:creator><![CDATA[micha7]]></dc:creator><pubDate>Wed, 07 Jul 2010 09:56:37 GMT</pubDate></item><item><title><![CDATA[Reply to DrawLine() im Konstruktor on Wed, 07 Jul 2010 10:00:39 GMT]]></title><description><![CDATA[<p>Deshalb hab ich dir im ersten Post sofort geschrieben, dass du im richtigen Forum nachfragen sollst.<br />
Die Gefahr, dass sonst einer einen hochroten Kopf und ggf. einen Herzinfakt bekommt, ist hier sonst sehr gross <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1922620</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1922620</guid><dc:creator><![CDATA[Jockelx]]></dc:creator><pubDate>Wed, 07 Jul 2010 10:00:39 GMT</pubDate></item></channel></rss>