Advertisement
reteppeter

Grafikprogrammierung

Jan 22nd, 2013
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 26.85 KB | None | 0 0
  1. #pragma once
  2.  
  3.  
  4.  
  5. namespace cpbs13_6 {
  6.  
  7.  
  8.  
  9.     using namespace System;
  10.  
  11.     using namespace System::ComponentModel;
  12.  
  13.     using namespace System::Collections;
  14.  
  15.     using namespace System::Windows::Forms;
  16.  
  17.     using namespace System::Data;
  18.  
  19.     using namespace System::Drawing;
  20.  
  21.  
  22.  
  23.     /// <summary>
  24.  
  25.     /// Zusammenfassung für Form1
  26.  
  27.     /// </summary>
  28.  
  29.     public ref class Form1 : public System::Windows::Forms::Form
  30.  
  31.     {
  32.  
  33.     public:
  34.  
  35.         Form1(void)
  36.  
  37.         {
  38.  
  39.             InitializeComponent();
  40.  
  41.             //
  42.  
  43.             //TODO: Konstruktorcode hier hinzufügen.
  44.  
  45.             //
  46.  
  47.         }
  48.  
  49.  
  50.  
  51.     protected:
  52.  
  53.         /// <summary>
  54.  
  55.         /// Verwendete Ressourcen bereinigen.
  56.  
  57.         /// </summary>
  58.  
  59.         ~Form1()
  60.  
  61.         {
  62.  
  63.             if (components)
  64.  
  65.             {
  66.  
  67.                 delete components;
  68.  
  69.             }
  70.  
  71.         }
  72.  
  73.  
  74.  
  75.     private:
  76.  
  77.         Graphics ^zeichenflaeche;
  78.  
  79.         Color linienFarbe;
  80.  
  81.         Color hintergrundFarbe;
  82.  
  83.  
  84.  
  85.         //für die Linienstile
  86.  
  87.         static array <Drawing2D::DashStyle> ^linienstil = {Drawing2D::DashStyle::Dash,
  88.  
  89.             Drawing2D::DashStyle::DashDot,
  90.  
  91.             Drawing2D::DashStyle::DashDotDot,
  92.  
  93.             Drawing2D::DashStyle::Dot,
  94.  
  95.             Drawing2D::DashStyle::Solid};
  96.  
  97.  
  98.  
  99.         //für die Hintergrundmuster
  100.  
  101.         static array <Drawing2D::HatchStyle> ^fuellstil = {Drawing2D::HatchStyle::BackwardDiagonal,
  102.  
  103.             Drawing2D::HatchStyle::Cross,
  104.  
  105.             Drawing2D::HatchStyle::DottedGrid,
  106.  
  107.             Drawing2D::HatchStyle::ForwardDiagonal,
  108.  
  109.             Drawing2D::HatchStyle::Sphere,
  110.  
  111.             Drawing2D::HatchStyle::Vertical,
  112.  
  113.             Drawing2D::HatchStyle::Wave,
  114.  
  115.             Drawing2D::HatchStyle::ZigZag};
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.     private: System::Windows::Forms::Panel^  panel1;
  124.  
  125.     private: System::Windows::Forms::GroupBox^  groupBox1;
  126.  
  127.     private: System::Windows::Forms::Label^  label3;
  128.  
  129.     private: System::Windows::Forms::Label^  label2;
  130.  
  131.     private: System::Windows::Forms::Label^  label1;
  132.  
  133.     private: System::Windows::Forms::NumericUpDown^  numericUpDownLinieStaerke;
  134.  
  135.     private: System::Windows::Forms::ListBox^  listBoxLinieStil;
  136.  
  137.     private: System::Windows::Forms::GroupBox^  groupBox2;
  138.  
  139.     private: System::Windows::Forms::Label^  label5;
  140.  
  141.     private: System::Windows::Forms::Label^  label4;
  142.  
  143.     private: System::Windows::Forms::ListBox^  listBoxHintergrundMuster;
  144.  
  145.     private: System::Windows::Forms::RadioButton^  radioButtonHintergrundMuster;
  146.  
  147.     private: System::Windows::Forms::RadioButton^  radioButtonHintergrundFarbe;
  148.  
  149.     private: System::Windows::Forms::RadioButton^  radioButtonHintergrundOhne;
  150.  
  151.     private: System::Windows::Forms::GroupBox^  groupBox3;
  152.  
  153.     private: System::Windows::Forms::RadioButton^  radioButtonLinie;
  154.  
  155.     private: System::Windows::Forms::RadioButton^  radioButtonRechteck;
  156.  
  157.     private: System::Windows::Forms::RadioButton^  radioButtonKreis;
  158.  
  159.     private: System::Windows::Forms::Button^  buttonStart;
  160.  
  161.     private: System::Windows::Forms::Button^  buttonLoeschen;
  162.  
  163.     private: System::Windows::Forms::Button^  buttonBeenden;
  164.  
  165.     private: System::Windows::Forms::TrackBar^  trackBar1;
  166.  
  167.     private: System::Windows::Forms::Panel^  panelLinieFarbeVorschau;
  168.  
  169.     private: System::Windows::Forms::Button^  buttonLinieFarbe;
  170.  
  171.     private: System::Windows::Forms::ColorDialog^  colorDialog1;
  172.  
  173.     private: System::Windows::Forms::Panel^  panelHintergrundFarbeVorschau;
  174.  
  175.     private: System::Windows::Forms::Button^  buttonHintergrundFarbe;
  176.  
  177.  
  178.  
  179.     private:
  180.  
  181.         /// <summary>
  182.  
  183.         /// Erforderliche Designervariable.
  184.  
  185.         /// </summary>
  186.  
  187.         System::ComponentModel::Container ^components;
  188.  
  189.  
  190.  
  191. #pragma region Windows Form Designer generated code
  192.  
  193.         /// <summary>
  194.  
  195.         /// Erforderliche Methode für die Designerunterstützung.
  196.  
  197.         /// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden.
  198.  
  199.         /// </summary>
  200.  
  201.         void InitializeComponent(void)
  202.  
  203.         {
  204.  
  205.             this->panel1 = (gcnew System::Windows::Forms::Panel());
  206.  
  207.             this->groupBox1 = (gcnew System::Windows::Forms::GroupBox());
  208.  
  209.             this->panelLinieFarbeVorschau = (gcnew System::Windows::Forms::Panel());
  210.  
  211.             this->buttonLinieFarbe = (gcnew System::Windows::Forms::Button());
  212.  
  213.             this->label3 = (gcnew System::Windows::Forms::Label());
  214.  
  215.             this->label2 = (gcnew System::Windows::Forms::Label());
  216.  
  217.             this->label1 = (gcnew System::Windows::Forms::Label());
  218.  
  219.             this->numericUpDownLinieStaerke = (gcnew System::Windows::Forms::NumericUpDown());
  220.  
  221.             this->listBoxLinieStil = (gcnew System::Windows::Forms::ListBox());
  222.  
  223.             this->groupBox2 = (gcnew System::Windows::Forms::GroupBox());
  224.  
  225.             this->panelHintergrundFarbeVorschau = (gcnew System::Windows::Forms::Panel());
  226.  
  227.             this->label5 = (gcnew System::Windows::Forms::Label());
  228.  
  229.             this->buttonHintergrundFarbe = (gcnew System::Windows::Forms::Button());
  230.  
  231.             this->label4 = (gcnew System::Windows::Forms::Label());
  232.  
  233.             this->listBoxHintergrundMuster = (gcnew System::Windows::Forms::ListBox());
  234.  
  235.             this->radioButtonHintergrundMuster = (gcnew System::Windows::Forms::RadioButton());
  236.  
  237.             this->radioButtonHintergrundFarbe = (gcnew System::Windows::Forms::RadioButton());
  238.  
  239.             this->radioButtonHintergrundOhne = (gcnew System::Windows::Forms::RadioButton());
  240.  
  241.             this->groupBox3 = (gcnew System::Windows::Forms::GroupBox());
  242.  
  243.             this->radioButtonLinie = (gcnew System::Windows::Forms::RadioButton());
  244.  
  245.             this->radioButtonRechteck = (gcnew System::Windows::Forms::RadioButton());
  246.  
  247.             this->radioButtonKreis = (gcnew System::Windows::Forms::RadioButton());
  248.  
  249.             this->buttonStart = (gcnew System::Windows::Forms::Button());
  250.  
  251.             this->buttonLoeschen = (gcnew System::Windows::Forms::Button());
  252.  
  253.             this->buttonBeenden = (gcnew System::Windows::Forms::Button());
  254.  
  255.             this->trackBar1 = (gcnew System::Windows::Forms::TrackBar());
  256.  
  257.             this->colorDialog1 = (gcnew System::Windows::Forms::ColorDialog());
  258.  
  259.             this->groupBox1->SuspendLayout();
  260.  
  261.             (cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->numericUpDownLinieStaerke))->BeginInit();
  262.  
  263.             this->groupBox2->SuspendLayout();
  264.  
  265.             this->groupBox3->SuspendLayout();
  266.  
  267.             (cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->trackBar1))->BeginInit();
  268.  
  269.             this->SuspendLayout();
  270.  
  271.             //
  272.  
  273.             // panel1
  274.  
  275.             //
  276.  
  277.             this->panel1->BackColor = System::Drawing::Color::White;
  278.  
  279.             this->panel1->BorderStyle = System::Windows::Forms::BorderStyle::FixedSingle;
  280.  
  281.             this->panel1->Location = System::Drawing::Point(12, 12);
  282.  
  283.             this->panel1->Name = L"panel1";
  284.  
  285.             this->panel1->Size = System::Drawing::Size(300, 300);
  286.  
  287.             this->panel1->TabIndex = 0;
  288.  
  289.             //
  290.  
  291.             // groupBox1
  292.  
  293.             //
  294.  
  295.             this->groupBox1->Controls->Add(this->panelLinieFarbeVorschau);
  296.  
  297.             this->groupBox1->Controls->Add(this->buttonLinieFarbe);
  298.  
  299.             this->groupBox1->Controls->Add(this->label3);
  300.  
  301.             this->groupBox1->Controls->Add(this->label2);
  302.  
  303.             this->groupBox1->Controls->Add(this->label1);
  304.  
  305.             this->groupBox1->Controls->Add(this->numericUpDownLinieStaerke);
  306.  
  307.             this->groupBox1->Controls->Add(this->listBoxLinieStil);
  308.  
  309.             this->groupBox1->Location = System::Drawing::Point(326, 12);
  310.  
  311.             this->groupBox1->Name = L"groupBox1";
  312.  
  313.             this->groupBox1->Size = System::Drawing::Size(200, 111);
  314.  
  315.             this->groupBox1->TabIndex = 0;
  316.  
  317.             this->groupBox1->TabStop = false;
  318.  
  319.             this->groupBox1->Text = L"Linie";
  320.  
  321.             //
  322.  
  323.             // panelLinieFarbeVorschau
  324.  
  325.             //
  326.  
  327.             this->panelLinieFarbeVorschau->BackColor = System::Drawing::Color::Black;
  328.  
  329.             this->panelLinieFarbeVorschau->Location = System::Drawing::Point(51, 19);
  330.  
  331.             this->panelLinieFarbeVorschau->Name = L"panelLinieFarbeVorschau";
  332.  
  333.             this->panelLinieFarbeVorschau->Size = System::Drawing::Size(24, 22);
  334.  
  335.             this->panelLinieFarbeVorschau->TabIndex = 7;
  336.  
  337.             //
  338.  
  339.             // buttonLinieFarbe
  340.  
  341.             //
  342.  
  343.             this->buttonLinieFarbe->Location = System::Drawing::Point(92, 19);
  344.  
  345.             this->buttonLinieFarbe->Name = L"buttonLinieFarbe";
  346.  
  347.             this->buttonLinieFarbe->Size = System::Drawing::Size(30, 23);
  348.  
  349.             this->buttonLinieFarbe->TabIndex = 6;
  350.  
  351.             this->buttonLinieFarbe->Text = L"...";
  352.  
  353.             this->buttonLinieFarbe->UseVisualStyleBackColor = true;
  354.  
  355.             this->buttonLinieFarbe->Click += gcnew System::EventHandler(this, &Form1::buttonLinieFarbe_Click);
  356.  
  357.             //
  358.  
  359.             // label3
  360.  
  361.             //
  362.  
  363.             this->label3->AutoSize = true;
  364.  
  365.             this->label3->Location = System::Drawing::Point(6, 85);
  366.  
  367.             this->label3->Name = L"label3";
  368.  
  369.             this->label3->Size = System::Drawing::Size(41, 13);
  370.  
  371.             this->label3->TabIndex = 5;
  372.  
  373.             this->label3->Text = L"Stärke:";
  374.  
  375.             //
  376.  
  377.             // label2
  378.  
  379.             //
  380.  
  381.             this->label2->AutoSize = true;
  382.  
  383.             this->label2->Location = System::Drawing::Point(6, 47);
  384.  
  385.             this->label2->Name = L"label2";
  386.  
  387.             this->label2->Size = System::Drawing::Size(24, 13);
  388.  
  389.             this->label2->TabIndex = 4;
  390.  
  391.             this->label2->Text = L"Stil:";
  392.  
  393.             //
  394.  
  395.             // label1
  396.  
  397.             //
  398.  
  399.             this->label1->AutoSize = true;
  400.  
  401.             this->label1->Location = System::Drawing::Point(6, 19);
  402.  
  403.             this->label1->Name = L"label1";
  404.  
  405.             this->label1->Size = System::Drawing::Size(37, 13);
  406.  
  407.             this->label1->TabIndex = 3;
  408.  
  409.             this->label1->Text = L"Farbe:";
  410.  
  411.             //
  412.  
  413.             // numericUpDownLinieStaerke
  414.  
  415.             //
  416.  
  417.             this->numericUpDownLinieStaerke->Location = System::Drawing::Point(47, 83);
  418.  
  419.             this->numericUpDownLinieStaerke->Maximum = System::Decimal(gcnew cli::array< System::Int32 >(4) {20, 0, 0, 0});
  420.  
  421.             this->numericUpDownLinieStaerke->Minimum = System::Decimal(gcnew cli::array< System::Int32 >(4) {1, 0, 0, 0});
  422.  
  423.             this->numericUpDownLinieStaerke->Name = L"numericUpDownLinieStaerke";
  424.  
  425.             this->numericUpDownLinieStaerke->Size = System::Drawing::Size(120, 20);
  426.  
  427.             this->numericUpDownLinieStaerke->TabIndex = 2;
  428.  
  429.             this->numericUpDownLinieStaerke->Value = System::Decimal(gcnew cli::array< System::Int32 >(4) {1, 0, 0, 0});
  430.  
  431.             //
  432.  
  433.             // listBoxLinieStil
  434.  
  435.             //
  436.  
  437.             this->listBoxLinieStil->DrawMode = System::Windows::Forms::DrawMode::OwnerDrawFixed;
  438.  
  439.             this->listBoxLinieStil->FormattingEnabled = true;
  440.  
  441.             this->listBoxLinieStil->Location = System::Drawing::Point(46, 47);
  442.  
  443.             this->listBoxLinieStil->Name = L"listBoxLinieStil";
  444.  
  445.             this->listBoxLinieStil->Size = System::Drawing::Size(120, 30);
  446.  
  447.             this->listBoxLinieStil->TabIndex = 1;
  448.  
  449.             this->listBoxLinieStil->DrawItem += gcnew System::Windows::Forms::DrawItemEventHandler(this, &Form1::listBoxLinieStil_DrawItem);
  450.  
  451.             //
  452.  
  453.             // groupBox2
  454.  
  455.             //
  456.  
  457.             this->groupBox2->Controls->Add(this->panelHintergrundFarbeVorschau);
  458.  
  459.             this->groupBox2->Controls->Add(this->label5);
  460.  
  461.             this->groupBox2->Controls->Add(this->buttonHintergrundFarbe);
  462.  
  463.             this->groupBox2->Controls->Add(this->label4);
  464.  
  465.             this->groupBox2->Controls->Add(this->listBoxHintergrundMuster);
  466.  
  467.             this->groupBox2->Controls->Add(this->radioButtonHintergrundMuster);
  468.  
  469.             this->groupBox2->Controls->Add(this->radioButtonHintergrundFarbe);
  470.  
  471.             this->groupBox2->Controls->Add(this->radioButtonHintergrundOhne);
  472.  
  473.             this->groupBox2->Location = System::Drawing::Point(326, 129);
  474.  
  475.             this->groupBox2->Name = L"groupBox2";
  476.  
  477.             this->groupBox2->Size = System::Drawing::Size(200, 110);
  478.  
  479.             this->groupBox2->TabIndex = 1;
  480.  
  481.             this->groupBox2->TabStop = false;
  482.  
  483.             this->groupBox2->Text = L"Hintergrund";
  484.  
  485.             //
  486.  
  487.             // panelHintergrundFarbeVorschau
  488.  
  489.             //
  490.  
  491.             this->panelHintergrundFarbeVorschau->BackColor = System::Drawing::Color::Black;
  492.  
  493.             this->panelHintergrundFarbeVorschau->Location = System::Drawing::Point(51, 41);
  494.  
  495.             this->panelHintergrundFarbeVorschau->Name = L"panelHintergrundFarbeVorschau";
  496.  
  497.             this->panelHintergrundFarbeVorschau->Size = System::Drawing::Size(24, 22);
  498.  
  499.             this->panelHintergrundFarbeVorschau->TabIndex = 9;
  500.  
  501.             //
  502.  
  503.             // label5
  504.  
  505.             //
  506.  
  507.             this->label5->AutoSize = true;
  508.  
  509.             this->label5->Location = System::Drawing::Point(6, 69);
  510.  
  511.             this->label5->Name = L"label5";
  512.  
  513.             this->label5->Size = System::Drawing::Size(24, 13);
  514.  
  515.             this->label5->TabIndex = 7;
  516.  
  517.             this->label5->Text = L"Stil:";
  518.  
  519.             //
  520.  
  521.             // buttonHintergrundFarbe
  522.  
  523.             //
  524.  
  525.             this->buttonHintergrundFarbe->Location = System::Drawing::Point(92, 42);
  526.  
  527.             this->buttonHintergrundFarbe->Name = L"buttonHintergrundFarbe";
  528.  
  529.             this->buttonHintergrundFarbe->Size = System::Drawing::Size(30, 23);
  530.  
  531.             this->buttonHintergrundFarbe->TabIndex = 8;
  532.  
  533.             this->buttonHintergrundFarbe->Text = L"...";
  534.  
  535.             this->buttonHintergrundFarbe->UseVisualStyleBackColor = true;
  536.  
  537.             this->buttonHintergrundFarbe->Click += gcnew System::EventHandler(this, &Form1::buttonHintergrundFarbe_Click);
  538.  
  539.             //
  540.  
  541.             // label4
  542.  
  543.             //
  544.  
  545.             this->label4->AutoSize = true;
  546.  
  547.             this->label4->Location = System::Drawing::Point(6, 45);
  548.  
  549.             this->label4->Name = L"label4";
  550.  
  551.             this->label4->Size = System::Drawing::Size(37, 13);
  552.  
  553.             this->label4->TabIndex = 6;
  554.  
  555.             this->label4->Text = L"Farbe:";
  556.  
  557.             //
  558.  
  559.             // listBoxHintergrundMuster
  560.  
  561.             //
  562.  
  563.             this->listBoxHintergrundMuster->DrawMode = System::Windows::Forms::DrawMode::OwnerDrawFixed;
  564.  
  565.             this->listBoxHintergrundMuster->FormattingEnabled = true;
  566.  
  567.             this->listBoxHintergrundMuster->Location = System::Drawing::Point(47, 69);
  568.  
  569.             this->listBoxHintergrundMuster->Name = L"listBoxHintergrundMuster";
  570.  
  571.             this->listBoxHintergrundMuster->Size = System::Drawing::Size(120, 30);
  572.  
  573.             this->listBoxHintergrundMuster->TabIndex = 4;
  574.  
  575.             this->listBoxHintergrundMuster->DrawItem += gcnew System::Windows::Forms::DrawItemEventHandler(this, &Form1::listBoxHintergrundMuster_DrawItem);
  576.  
  577.             //
  578.  
  579.             // radioButtonHintergrundMuster
  580.  
  581.             //
  582.  
  583.             this->radioButtonHintergrundMuster->AutoSize = true;
  584.  
  585.             this->radioButtonHintergrundMuster->Location = System::Drawing::Point(137, 19);
  586.  
  587.             this->radioButtonHintergrundMuster->Name = L"radioButtonHintergrundMuster";
  588.  
  589.             this->radioButtonHintergrundMuster->Size = System::Drawing::Size(57, 17);
  590.  
  591.             this->radioButtonHintergrundMuster->TabIndex = 2;
  592.  
  593.             this->radioButtonHintergrundMuster->Text = L"Muster";
  594.  
  595.             this->radioButtonHintergrundMuster->UseVisualStyleBackColor = true;
  596.  
  597.             //
  598.  
  599.             // radioButtonHintergrundFarbe
  600.  
  601.             //
  602.  
  603.             this->radioButtonHintergrundFarbe->AutoSize = true;
  604.  
  605.             this->radioButtonHintergrundFarbe->Location = System::Drawing::Point(70, 19);
  606.  
  607.             this->radioButtonHintergrundFarbe->Name = L"radioButtonHintergrundFarbe";
  608.  
  609.             this->radioButtonHintergrundFarbe->Size = System::Drawing::Size(52, 17);
  610.  
  611.             this->radioButtonHintergrundFarbe->TabIndex = 1;
  612.  
  613.             this->radioButtonHintergrundFarbe->Text = L"Farbe";
  614.  
  615.             this->radioButtonHintergrundFarbe->UseVisualStyleBackColor = true;
  616.  
  617.             //
  618.  
  619.             // radioButtonHintergrundOhne
  620.  
  621.             //
  622.  
  623.             this->radioButtonHintergrundOhne->AutoSize = true;
  624.  
  625.             this->radioButtonHintergrundOhne->Checked = true;
  626.  
  627.             this->radioButtonHintergrundOhne->Location = System::Drawing::Point(9, 19);
  628.  
  629.             this->radioButtonHintergrundOhne->Name = L"radioButtonHintergrundOhne";
  630.  
  631.             this->radioButtonHintergrundOhne->Size = System::Drawing::Size(49, 17);
  632.  
  633.             this->radioButtonHintergrundOhne->TabIndex = 0;
  634.  
  635.             this->radioButtonHintergrundOhne->TabStop = true;
  636.  
  637.             this->radioButtonHintergrundOhne->Text = L"ohne";
  638.  
  639.             this->radioButtonHintergrundOhne->UseVisualStyleBackColor = true;
  640.  
  641.             //
  642.  
  643.             // groupBox3
  644.  
  645.             //
  646.  
  647.             this->groupBox3->Controls->Add(this->radioButtonLinie);
  648.  
  649.             this->groupBox3->Controls->Add(this->radioButtonRechteck);
  650.  
  651.             this->groupBox3->Controls->Add(this->radioButtonKreis);
  652.  
  653.             this->groupBox3->Location = System::Drawing::Point(326, 245);
  654.  
  655.             this->groupBox3->Name = L"groupBox3";
  656.  
  657.             this->groupBox3->Size = System::Drawing::Size(200, 52);
  658.  
  659.             this->groupBox3->TabIndex = 2;
  660.  
  661.             this->groupBox3->TabStop = false;
  662.  
  663.             this->groupBox3->Text = L"Figur";
  664.  
  665.             //
  666.  
  667.             // radioButtonLinie
  668.  
  669.             //
  670.  
  671.             this->radioButtonLinie->AutoSize = true;
  672.  
  673.             this->radioButtonLinie->Location = System::Drawing::Point(137, 19);
  674.  
  675.             this->radioButtonLinie->Name = L"radioButtonLinie";
  676.  
  677.             this->radioButtonLinie->Size = System::Drawing::Size(47, 17);
  678.  
  679.             this->radioButtonLinie->TabIndex = 2;
  680.  
  681.             this->radioButtonLinie->Text = L"Linie";
  682.  
  683.             this->radioButtonLinie->UseVisualStyleBackColor = true;
  684.  
  685.             //
  686.  
  687.             // radioButtonRechteck
  688.  
  689.             //
  690.  
  691.             this->radioButtonRechteck->AutoSize = true;
  692.  
  693.             this->radioButtonRechteck->Location = System::Drawing::Point(61, 19);
  694.  
  695.             this->radioButtonRechteck->Name = L"radioButtonRechteck";
  696.  
  697.             this->radioButtonRechteck->Size = System::Drawing::Size(72, 17);
  698.  
  699.             this->radioButtonRechteck->TabIndex = 1;
  700.  
  701.             this->radioButtonRechteck->Text = L"Rechteck";
  702.  
  703.             this->radioButtonRechteck->UseVisualStyleBackColor = true;
  704.  
  705.             //
  706.  
  707.             // radioButtonKreis
  708.  
  709.             //
  710.  
  711.             this->radioButtonKreis->AutoSize = true;
  712.  
  713.             this->radioButtonKreis->Checked = true;
  714.  
  715.             this->radioButtonKreis->Location = System::Drawing::Point(9, 19);
  716.  
  717.             this->radioButtonKreis->Name = L"radioButtonKreis";
  718.  
  719.             this->radioButtonKreis->Size = System::Drawing::Size(48, 17);
  720.  
  721.             this->radioButtonKreis->TabIndex = 0;
  722.  
  723.             this->radioButtonKreis->TabStop = true;
  724.  
  725.             this->radioButtonKreis->Text = L"Kreis";
  726.  
  727.             this->radioButtonKreis->UseVisualStyleBackColor = true;
  728.  
  729.             //
  730.  
  731.             // buttonStart
  732.  
  733.             //
  734.  
  735.             this->buttonStart->Location = System::Drawing::Point(326, 347);
  736.  
  737.             this->buttonStart->Name = L"buttonStart";
  738.  
  739.             this->buttonStart->Size = System::Drawing::Size(75, 23);
  740.  
  741.             this->buttonStart->TabIndex = 4;
  742.  
  743.             this->buttonStart->Text = L"Los geht\'s";
  744.  
  745.             this->buttonStart->UseVisualStyleBackColor = true;
  746.  
  747.             this->buttonStart->Click += gcnew System::EventHandler(this, &Form1::buttonStart_Click);
  748.  
  749.             //
  750.  
  751.             // buttonLoeschen
  752.  
  753.             //
  754.  
  755.             this->buttonLoeschen->Location = System::Drawing::Point(407, 347);
  756.  
  757.             this->buttonLoeschen->Name = L"buttonLoeschen";
  758.  
  759.             this->buttonLoeschen->Size = System::Drawing::Size(75, 23);
  760.  
  761.             this->buttonLoeschen->TabIndex = 5;
  762.  
  763.             this->buttonLoeschen->Text = L"Löschen";
  764.  
  765.             this->buttonLoeschen->UseVisualStyleBackColor = true;
  766.  
  767.             this->buttonLoeschen->Click += gcnew System::EventHandler(this, &Form1::buttonLoeschen_Click);
  768.  
  769.             //
  770.  
  771.             // buttonBeenden
  772.  
  773.             //
  774.  
  775.             this->buttonBeenden->Location = System::Drawing::Point(488, 347);
  776.  
  777.             this->buttonBeenden->Name = L"buttonBeenden";
  778.  
  779.             this->buttonBeenden->Size = System::Drawing::Size(75, 23);
  780.  
  781.             this->buttonBeenden->TabIndex = 6;
  782.  
  783.             this->buttonBeenden->Text = L"Beenden";
  784.  
  785.             this->buttonBeenden->UseVisualStyleBackColor = true;
  786.  
  787.             this->buttonBeenden->Click += gcnew System::EventHandler(this, &Form1::buttonBeenden_Click);
  788.  
  789.             //
  790.  
  791.             // trackBar1
  792.  
  793.             //
  794.  
  795.             this->trackBar1->Location = System::Drawing::Point(326, 303);
  796.  
  797.             this->trackBar1->Maximum = 3;
  798.  
  799.             this->trackBar1->Minimum = 1;
  800.  
  801.             this->trackBar1->Name = L"trackBar1";
  802.  
  803.             this->trackBar1->Size = System::Drawing::Size(200, 45);
  804.  
  805.             this->trackBar1->TabIndex = 3;
  806.  
  807.             this->trackBar1->Value = 2;
  808.  
  809.             //
  810.  
  811.             // Form1
  812.  
  813.             //
  814.  
  815.             this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
  816.  
  817.             this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
  818.  
  819.             this->ClientSize = System::Drawing::Size(584, 382);
  820.  
  821.             this->Controls->Add(this->buttonLoeschen);
  822.  
  823.             this->Controls->Add(this->buttonBeenden);
  824.  
  825.             this->Controls->Add(this->buttonStart);
  826.  
  827.             this->Controls->Add(this->groupBox3);
  828.  
  829.             this->Controls->Add(this->groupBox2);
  830.  
  831.             this->Controls->Add(this->groupBox1);
  832.  
  833.             this->Controls->Add(this->panel1);
  834.  
  835.             this->Controls->Add(this->trackBar1);
  836.  
  837.             this->Name = L"Form1";
  838.  
  839.             this->Text = L"Eine Spielerei";
  840.  
  841.             this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
  842.  
  843.             this->groupBox1->ResumeLayout(false);
  844.  
  845.             this->groupBox1->PerformLayout();
  846.  
  847.             (cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->numericUpDownLinieStaerke))->EndInit();
  848.  
  849.             this->groupBox2->ResumeLayout(false);
  850.  
  851.             this->groupBox2->PerformLayout();
  852.  
  853.             this->groupBox3->ResumeLayout(false);
  854.  
  855.             this->groupBox3->PerformLayout();
  856.  
  857.             (cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->trackBar1))->EndInit();
  858.  
  859.             this->ResumeLayout(false);
  860.  
  861.             this->PerformLayout();
  862.  
  863.  
  864.  
  865.         }
  866.  
  867. #pragma endregion
  868.  
  869.  
  870.  
  871. private: System::Void buttonBeenden_Click(System::Object^  sender, System::EventArgs^  e) {
  872.  
  873.              Close();
  874.  
  875.          }
  876.  
  877. private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
  878.  
  879.             //die Linienfarbe auf Schwarz setzen
  880.  
  881.              linienFarbe = Color::Black;
  882.  
  883.              //und auch die Hintergrundfarbe
  884.  
  885.              hintergrundFarbe = Color::Black;
  886.  
  887.              //die Einträge für die Linienstile erzeugen
  888.  
  889.             for each (Drawing2D::DashStyle element in linienstil)
  890.  
  891.                 listBoxLinieStil->Items->Add("");
  892.  
  893.             //und für die Hintergrundmuster
  894.  
  895.             for each (Drawing2D::HatchStyle element in fuellstil)
  896.  
  897.                 listBoxHintergrundMuster->Items->Add("");
  898.  
  899.             //einen Handle auf die Zeichenfläche des Panels setzen
  900.  
  901.             //zeichenflaeche ist als Attribut der Klasse Form1 vereinbart
  902.  
  903.             zeichenflaeche = panel1->CreateGraphics();
  904.  
  905.          }
  906.  
  907. private: System::Void buttonLoeschen_Click(System::Object^  sender, System::EventArgs^  e) {
  908.  
  909.              //die Zeichenfläche löschen
  910.  
  911.              zeichenflaeche->Clear(panel1->BackColor);
  912.  
  913.          }
  914.  
  915. private: System::Void buttonStart_Click(System::Object^  sender, System::EventArgs^  e) {
  916.  
  917.             //eine lokale Variable für die Größe
  918.  
  919.             Int32 groesse;
  920.  
  921.             //einen schwarzen Stift erzeugen
  922.  
  923.             Pen ^stift = gcnew Pen(linienFarbe);
  924.  
  925.             //einen schwarzen Pinsel erzeugen
  926.  
  927.             SolidBrush ^pinsel = gcnew SolidBrush(hintergrundFarbe);
  928.  
  929.             //die Dicke des Stiftes setzen
  930.  
  931.             stift->Width=Convert::ToSingle(numericUpDownLinieStaerke->Value);
  932.  
  933.             //den Linienstil setzen
  934.  
  935.             if (listBoxLinieStil->SelectedIndex>=0)
  936.  
  937.                 stift->DashStyle=linienstil[listBoxLinieStil->SelectedIndex];
  938.  
  939.  
  940.  
  941.             //die Größe der Figur ermitteln
  942.  
  943.             switch (trackBar1->Value) {
  944.  
  945.                 case 1: groesse=125;
  946.  
  947.                         break;
  948.  
  949.                 case 2: groesse=100;
  950.  
  951.                         break;
  952.  
  953.                 case 3: groesse=75;
  954.  
  955.                         break;
  956.  
  957.             }
  958.  
  959.             //Figur ermitteln
  960.  
  961.             //beim Kreis und beim Rechteck auch die Füllung überprüfen
  962.  
  963.             if (radioButtonKreis->Checked == true) {
  964.  
  965.                 if (radioButtonHintergrundOhne->Checked == true)
  966.  
  967.                     zeichenflaeche->DrawEllipse(stift, panel1->ClientRectangle.Left + groesse, panel1->ClientRectangle.Top + groesse, panel1->ClientRectangle.Width - (groesse*2), panel1->ClientRectangle.Height - (groesse * 2));
  968.  
  969.                 if (radioButtonHintergrundFarbe->Checked == true)
  970.  
  971.                     zeichenflaeche->FillEllipse(pinsel, panel1->ClientRectangle.Left + groesse, panel1->ClientRectangle.Top + groesse, panel1->ClientRectangle.Width - (groesse*2), panel1->ClientRectangle.Height - (groesse * 2));
  972.  
  973.                 //soll mit Muster gezeichnet werden und ist ein Muster ausgewählt?
  974.  
  975.                 if (radioButtonHintergrundMuster->Checked == true && listBoxHintergrundMuster->SelectedIndex>=0) {
  976.  
  977.                     //einen neuen Pinsel für das Muster erzeugen
  978.  
  979.                     //die Vordergrundfarbe kommt vom Stift, der Hintergrund ist immer weiß
  980.  
  981.                     Drawing2D::HatchBrush ^musterPinsel = gcnew Drawing2D::HatchBrush(fuellstil[listBoxHintergrundMuster->SelectedIndex], stift->Color, Color::White);
  982.  
  983.                     zeichenflaeche->FillEllipse(musterPinsel,panel1->ClientRectangle.Left+groesse, panel1->ClientRectangle.Top+groesse,panel1->ClientRectangle.Width-(groesse*2), panel1->ClientRectangle.Height-(groesse*2));
  984.  
  985.                     delete musterPinsel;
  986.  
  987.                 }
  988.  
  989.             }
  990.  
  991.             if (radioButtonRechteck->Checked == true) {
  992.  
  993.                 if (radioButtonHintergrundOhne->Checked == true)
  994.  
  995.                     zeichenflaeche->DrawRectangle(stift, panel1->ClientRectangle.Left + groesse, panel1->ClientRectangle.Top + groesse, panel1->ClientRectangle.Width - (groesse*2), panel1->ClientRectangle.Height - (groesse * 2));
  996.  
  997.                 if (radioButtonHintergrundFarbe->Checked == true)
  998.  
  999.                     zeichenflaeche->FillRectangle(pinsel, panel1->ClientRectangle.Left + groesse, panel1->ClientRectangle.Top + groesse, panel1->ClientRectangle.Width - (groesse*2), panel1->ClientRectangle.Height - (groesse * 2));
  1000.  
  1001.                  //soll mit Muster gezeichnet werden und ist ein Muster ausgewählt?
  1002.  
  1003.                  if (radioButtonHintergrundMuster->Checked == true && listBoxHintergrundMuster->SelectedIndex>=0) {
  1004.  
  1005.                      //einen neuen Pinsel für das Muster erzeugen
  1006.  
  1007.                      //die Vordergrundfarbe kommt vom Stift, der Hintergrund ist immer weiß
  1008.  
  1009.                      Drawing2D::HatchBrush ^musterPinsel = gcnew Drawing2D::HatchBrush(fuellstil[listBoxHintergrundMuster->SelectedIndex], stift->Color, Color::White);
  1010.  
  1011.                      zeichenflaeche->FillRectangle(musterPinsel,panel1->ClientRectangle.Left+groesse, panel1->ClientRectangle.Top+groesse,panel1->ClientRectangle.Width-(groesse*2), panel1->ClientRectangle.Height-(groesse*2));
  1012.  
  1013.                      delete musterPinsel;
  1014.  
  1015.                  }
  1016.  
  1017.             }
  1018.  
  1019.             if (radioButtonLinie->Checked == true)
  1020.  
  1021.                 zeichenflaeche->DrawLine(stift, panel1->ClientRectangle.Left + groesse, panel1->ClientRectangle.Height / 2, panel1->ClientRectangle.Width - groesse, panel1->ClientRectangle.Height / 2);
  1022.  
  1023.             //Stift und Pinsel löschen
  1024.  
  1025.             delete stift;
  1026.  
  1027.             delete pinsel;
  1028.  
  1029.          }
  1030.  
  1031. private: System::Void buttonLinieFarbe_Click(System::Object^  sender, System::EventArgs^  e) {
  1032.  
  1033.             //den Dialog zur Farbauswahl anzeigen
  1034.  
  1035.             if (colorDialog1->ShowDialog() == Windows::Forms::DialogResult::OK) {
  1036.  
  1037.                 //die Hintergrundfarbe für das Panel auf die ausgewählte Farbe setzen
  1038.  
  1039.                 panelLinieFarbeVorschau->BackColor=colorDialog1->Color;
  1040.  
  1041.                 //und die Linienfarbe
  1042.  
  1043.                 //linienFarbe ist ein Attribut der Klasse Form1
  1044.  
  1045.                 linienFarbe=colorDialog1->Color;
  1046.  
  1047.             }
  1048.  
  1049.          }
  1050.  
  1051. private: System::Void buttonHintergrundFarbe_Click(System::Object^  sender, System::EventArgs^  e) {
  1052.  
  1053.             //den Dialog zur Farbauswahl anzeigen
  1054.  
  1055.             if (colorDialog1->ShowDialog() == Windows::Forms::DialogResult::OK) {
  1056.  
  1057.                 //die Hintergrundfarbe für das Panel auf die ausgewählte Farbe setzen
  1058.  
  1059.                 panelHintergrundFarbeVorschau->BackColor=colorDialog1->Color;
  1060.  
  1061.                 //und die eigentliche Hintergrundfarbe
  1062.  
  1063.                 //hintergrundFarbe ist ein Attribut der Klasse Form1
  1064.  
  1065.                 hintergrundFarbe=colorDialog1->Color;
  1066.  
  1067.                 //die Auswahl Farbe aktivieren
  1068.  
  1069.                 radioButtonHintergrundFarbe->Checked=true;
  1070.  
  1071.             }
  1072.  
  1073.         }
  1074.  
  1075. private: System::Void listBoxLinieStil_DrawItem(System::Object^  sender, System::Windows::Forms::DrawItemEventArgs^  e) {
  1076.  
  1077.             //eine lokale Variable für die Berechnung der Mitte
  1078.  
  1079.             Int32 Y;
  1080.  
  1081.             //ein neuer lokaler Stift
  1082.  
  1083.             Pen ^boxStift = gcnew Pen(Color::Black);
  1084.  
  1085.             //die Mitte berechnen
  1086.  
  1087.             Y=(e->Bounds.Top + e->Bounds.Bottom)/2;
  1088.  
  1089.             //den Hintergrund zeichnen
  1090.  
  1091.             e->DrawBackground();
  1092.  
  1093.             //und die Linie
  1094.  
  1095.             boxStift->DashStyle=linienstil[e->Index];
  1096.  
  1097.             e->Graphics->DrawLine(boxStift, e->Bounds.Left+1, Y, e->Bounds.Right-1, Y);
  1098.  
  1099.             //den Stift löschen
  1100.  
  1101.             delete boxStift;
  1102.  
  1103.          }
  1104.  
  1105. private: System::Void listBoxHintergrundMuster_DrawItem(System::Object^  sender, System::Windows::Forms::DrawItemEventArgs^  e) {
  1106.  
  1107.             //ein neuer lokaler Pinsel für das Muster
  1108.  
  1109.             Drawing2D::HatchBrush ^boxPinsel = gcnew Drawing2D::HatchBrush(fuellstil[e->Index], Color::Black, Color::White);
  1110.  
  1111.             //den Hintergrund zeichnen
  1112.  
  1113.             e->DrawBackground();
  1114.  
  1115.             //und das Rechteck
  1116.  
  1117.             e->Graphics->FillRectangle(boxPinsel, e->Bounds.Left+1, e->Bounds.Top+1, e->Bounds.Width-1, e->Bounds.Height-1);
  1118.  
  1119.             //den Pinsel löschen
  1120.  
  1121.             delete boxPinsel;
  1122.  
  1123.          }
  1124.  
  1125. };
  1126.  
  1127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement