Announcement

Collapse
No announcement yet.

OnPaint

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • OnPaint

    hallo ich habe folgendes problem
    Ich habe bis jetzt in c# programiert doch da ich auch andere Sprachen beherschen will habe ich mit c++ begonnen.

    In c# habe ich schon 2D spiele und auch schon kleine 3D spiele(laufen, hüpfen, leveleditor,...) gemacht.

    Mitlerweile Binn ich in der Console genauso gut wie in c# nur bei 2D anwendungen habe ich es nicht fertig gebracht (trotz mehrstündiger googlesuche) in c++ die OnPaint methode zu überschreiben

    Da ich ohne dem weder 2D noch 3D spiele programieren kann bitte ich um hilfe.

    Danke für die schnellen antworten.


    //Ein ausschnitt aus einem c# 3D programm
    //Mit Render wird das eigentliche Spiel angezeigt und die zwei linien sind das visier
    protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
    {
    Graphics g = e.Graphics;
    pen = new Pen(Color.Black);
    g.DrawLine(pen, bildschirmGroese.X / 2 + 5, bildschirmGroese.Y / 2, bildschirmGroese.X / 2 - 5, bildschirmGroese.Y / 2);
    g.DrawLine(pen, bildschirmGroese.X / 2, bildschirmGroese.Y / 2 + 5, bildschirmGroese.X / 2, bildschirmGroese.Y / 2 - 5);
    this.Render();
    this.Invalidate();
    }

  • #2
    http://msdn.microsoft.com/en-us/libr...ty(VS.80).aspx

    http://msdn.microsoft.com/en-us/libr...41(VS.85).aspx
    Christian

    Comment


    • #3
      /*wo liegt der fehler bei diesem quellcode:
      Theoretisch müste er das feld fom hintergrund (offenen fenster zb. Internetexplorer) nehmen und einen strich hineinzeichnen da ich die OnPaint methode unten überschrieben habe und ihm darin befohlen habe einen strich zu zeichnen statdeses benützt er diese methoder (merkt man beim Debuggen) nicht einmal*/

      #pragma once


      namespace OnPaintTest {

      using namespace System;
      using namespace System::ComponentModel;
      using namespace System::Collections;
      using namespace System::Windows::Forms;
      using namespace System:ata;
      using namespace System:rawing;

      /// <summary>
      /// 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.
      /// </summary>
      public ref class Form1 : public System::Windows::Forms::Form
      {
      public:
      Form1(void)
      {
      InitializeComponent();
      //
      //TODO: Add the constructor code here
      //
      }
      protected:
      /// <summary>
      /// Clean up any resources being used.
      /// </summary>
      ~Form1()
      {
      if (components)
      {
      delete components;
      }
      }

      private:
      /// <summary>
      /// Required designer variable.
      /// </summary>
      System::ComponentModel::Container ^components;

      #pragma region Windows Form Designer generated code
      /// <summary>
      /// Required method for Designer support - do not modify
      /// the contents of this method with the code editor.
      /// </summary>
      void InitializeComponent(void)
      {
      this->components = gcnew System::ComponentModel::Container();
      this->Size = System:rawing::Size(300,300);
      this->Text = L"Form1";
      this->Padding = System::Windows::Forms::Padding(0);
      this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
      this->SetStyle(ControlStyles::AllPaintingInWmPaint, true);
      this->SetStyle(ControlStyles::UserPaint, true);
      this->SetStyle(ControlStyles::OptimizedDoubleBuffer, true);
      this->BackColor::set(Color::Yellow);
      this->Cursor->Hide();
      this->Cursor->Show();
      this->Invalidate();
      }
      protected:
      virtual void OnPaint(System::Object^ sender, PaintEventArgs^ e ) override
      {
      Form:OnPaint( e );
      Pen^p = gcnew Pen(Color::Black);
      e->Graphics->DrawLine(p,0,0,10,10);
      e->Graphics->DrawLine(p,10,10,0,0);
      }
      #pragma endregion
      };
      }
      Zuletzt editiert von MrPerfekt2; 24.12.2008, 18:46.

      Comment

      Working...
      X