Das ist möglich ja. Ihr müsst aber noch etwas abwandeln, da es viele Abhängigkeiten in der von der Hauptklasse zu Unterklassen gibt. Ich bin das ja schon schritt für schritt durchgegangen. Daher verstehe ich das nicht. Da liegt ja das Problem.
die Form1.h:
die Form1.cpp:
Wie gesagt, Ihr müsst die Abhängigkeiten noch löschen, die ihr eh nicht habt. das ist die Betreffende Klasse.
Sagt nichts zu dem Programmierstil, ich arbeite erst seit 3 Monaten mit C++/CLI
die Form1.h:
Code:
#pragma once
#include "stdafx.h"
#include "Antwort.h"
#include "AntwortDaten.h"
#include "Pruefung_hinzufuegen.h"
#include "Pruefung_auswaehlen.h"
#include "SchreibKoordinaten.h"
#include "HackenTest.h"
namespace Correctus {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace System::Drawing::Imaging;
using namespace System::Collections::Generic;
/// <summary>
/// Zusammenfassung für Form1
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
private:
bool mouseDown;
bool radieren;
List<AntwortDaten^> ^faecher;
List<SchreibKoordinaten^>^ point;
int anzahl_gezeichnet;
Graphics^ layer;
Pen ^pen1;
Pen ^penRed;
Point p;
System::Drawing::Region ^region1;
HackenTest ^tester;
System::Windows::Forms::ContextMenu ^contM;
private: System::Windows::Forms::ToolStripMenuItem^ neuePruefungenHinzufuegenToolStripMenuItem;
private: System::Windows::Forms::Label^ label1;
private: System::Windows::Forms::ContextMenuStrip^ contextMenuStrip1;
private: System::Windows::Forms::ToolStripMenuItem^ toolStripMenuItem2;
private: System::Windows::Forms::ToolStripMenuItem^ radierenToolStripMenuItem;
public:
Image ^img;
Form1(void)
{
InitializeComponent();
faecher = gcnew List<AntwortDaten^>();
faecher->Add(gcnew AntwortDaten("Mathe", "2. Semester", "335331"));
faecher->Add(gcnew AntwortDaten("Mathe", "2. Semester", "335332"));
faecher->Add(gcnew AntwortDaten("Mathe", "3. Semester", "335333"));
faecher->Add(gcnew AntwortDaten("Mathe", "3. Semester", "335334"));
faecher->Add(gcnew AntwortDaten("Mathe", "4. Semester", "335335"));
faecher->Add(gcnew AntwortDaten("Mathe", "4. Semester", "335336"));
faecher->Add(gcnew AntwortDaten("Deutsch", "2. Semester", "435331"));
faecher->Add(gcnew AntwortDaten("Deutsch", "2. Semester", "435332"));
faecher->Add(gcnew AntwortDaten("Deutsch", "3. Semester", "435333"));
faecher->Add(gcnew AntwortDaten("Deutsch", "3. Semester", "435334"));
faecher->Add(gcnew AntwortDaten("Deutsch", "4. Semester", "435335"));
faecher->Add(gcnew AntwortDaten("Deutsch", "4. Semester", "435336"));
point = gcnew List<SchreibKoordinaten^>();
anzahl_gezeichnet = 0;
mouseDown = false;
radieren = false;
pen1 = gcnew Pen(Color::Green, 1);
penRed = gcnew Pen(Color::Red, 1);
ResizeRedraw = true;
img = nullptr;
//zuweisung der Scrollbars
hScrollBar1->Parent = pictureBox1;
vScrollBar1->Parent = pictureBox1;
hScrollBar1->Visible = false;
vScrollBar1->Visible = false;
//Definierung und Deklarierung der Open- und SaveDileDialog
openFileDialog1 = gcnew OpenFileDialog();
openFileDialog1->InitialDirectory = ".";
openFileDialog1->Filter = "Windows Bitmap (*.bmp) | *.bmp"
+ "| JPEG (*.jpg) | *.jpg"
+ "| PNG (*.png) | *.png"
+ "| Windows Metafile (*.wmf) | *.wmf"
+ "| Grafikdatei (*.bmp;*.jpg;*.png;*.wmf) "
+ "| *.bmp;*.jpg;*.png;*.wmf";
openFileDialog1->FilterIndex = 5;
openFileDialog1->Multiselect = false;
openFileDialog1->RestoreDirectory = true;
saveFileDialog1 = gcnew SaveFileDialog();
saveFileDialog1->InitialDirectory = ".";
saveFileDialog1->Filter = "Windows Bitmap (*.bmp) | *.bmp"
+ "| JPEG (*.jpg) | *.jpg"
+ "| PNG (*.png) | *.png";
saveFileDialog1->FilterIndex = 1;
saveFileDialog1->RestoreDirectory = true;
}
protected:
/// <summary>
/// Verwendete Ressourcen bereinigen.
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::MenuStrip^ menuStrip1;
protected:
private: System::Windows::Forms::ToolStripMenuItem^ dateiToolStripMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^ oeffnenToolStripMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^ speichernToolStripMenuItem;
private: System::Windows::Forms::ToolStripSeparator^ toolStripSeparator1;
private: System::Windows::Forms::ToolStripMenuItem^ beendenToolStripMenuItem;
private: System::Windows::Forms::PictureBox^ pictureBox1;
private: System::Windows::Forms::SaveFileDialog^ saveFileDialog1;
private: System::Windows::Forms::OpenFileDialog^ openFileDialog1;
private: System::Windows::Forms::HScrollBar^ hScrollBar1;
private: System::Windows::Forms::VScrollBar^ vScrollBar1;
private: System::Windows::Forms::ToolStripMenuItem^ loesungenToolStripMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^ pruefungAuswaehlenToolStripMenuItem;
private: System::ComponentModel::IContainer^ components;
private:
/// <summary>
/// Erforderliche Designervariable.
/// </summary>
#pragma region Windows Form Designer generated code
/// <summary>
/// Erforderliche Methode für die Designerunterstützung.
/// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden.
/// </summary>
void InitializeComponent(void)
{
this->components = (gcnew System::ComponentModel::Container());
this->menuStrip1 = (gcnew System::Windows::Forms::MenuStrip());
this->dateiToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->oeffnenToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->speichernToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->toolStripSeparator1 = (gcnew System::Windows::Forms::ToolStripSeparator());
this->beendenToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->loesungenToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->pruefungAuswaehlenToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->neuePruefungenHinzufuegenToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->radierenToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->pictureBox1 = (gcnew System::Windows::Forms::PictureBox());
this->saveFileDialog1 = (gcnew System::Windows::Forms::SaveFileDialog());
this->openFileDialog1 = (gcnew System::Windows::Forms::OpenFileDialog());
this->hScrollBar1 = (gcnew System::Windows::Forms::HScrollBar());
this->vScrollBar1 = (gcnew System::Windows::Forms::VScrollBar());
this->label1 = (gcnew System::Windows::Forms::Label());
this->contextMenuStrip1 = (gcnew System::Windows::Forms::ContextMenuStrip(this->components));
this->toolStripMenuItem2 = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->menuStrip1->SuspendLayout();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox1))->BeginInit();
this->contextMenuStrip1->SuspendLayout();
this->SuspendLayout();
//
// menuStrip1
//
this->menuStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(3) {this->dateiToolStripMenuItem,
this->loesungenToolStripMenuItem, this->radierenToolStripMenuItem});
this->menuStrip1->Location = System::Drawing::Point(0, 0);
this->menuStrip1->Name = L"menuStrip1";
this->menuStrip1->Size = System::Drawing::Size(712, 24);
this->menuStrip1->TabIndex = 0;
this->menuStrip1->Text = L"menuStrip1";
//
// dateiToolStripMenuItem
//
this->dateiToolStripMenuItem->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(4) {this->oeffnenToolStripMenuItem,
this->speichernToolStripMenuItem, this->toolStripSeparator1, this->beendenToolStripMenuItem});
this->dateiToolStripMenuItem->Name = L"dateiToolStripMenuItem";
this->dateiToolStripMenuItem->Size = System::Drawing::Size(46, 20);
this->dateiToolStripMenuItem->Text = L"&Datei";
//
// oeffnenToolStripMenuItem
//
this->oeffnenToolStripMenuItem->Name = L"oeffnenToolStripMenuItem";
this->oeffnenToolStripMenuItem->Size = System::Drawing::Size(128, 22);
this->oeffnenToolStripMenuItem->Text = L"Ö&ffnen";
this->oeffnenToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::oeffnenToolStripMenuItem_Click);
//
// speichernToolStripMenuItem
//
this->speichernToolStripMenuItem->Name = L"speichernToolStripMenuItem";
this->speichernToolStripMenuItem->Size = System::Drawing::Size(128, 22);
this->speichernToolStripMenuItem->Text = L"S&peichern";
this->speichernToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::speichernToolStripMenuItem_Click);
//
// toolStripSeparator1
//
this->toolStripSeparator1->Name = L"toolStripSeparator1";
this->toolStripSeparator1->Size = System::Drawing::Size(125, 6);
//
// beendenToolStripMenuItem
//
this->beendenToolStripMenuItem->Name = L"beendenToolStripMenuItem";
this->beendenToolStripMenuItem->Size = System::Drawing::Size(128, 22);
this->beendenToolStripMenuItem->Text = L"&Schliessen";
this->beendenToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::beendenToolStripMenuItem_Click);
//
// loesungenToolStripMenuItem
//
this->loesungenToolStripMenuItem->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(2) {this->pruefungAuswaehlenToolStripMenuItem,
this->neuePruefungenHinzufuegenToolStripMenuItem});
this->loesungenToolStripMenuItem->Name = L"loesungenToolStripMenuItem";
this->loesungenToolStripMenuItem->Size = System::Drawing::Size(71, 20);
this->loesungenToolStripMenuItem->Text = L"Lösungen";
//
// pruefungAuswaehlenToolStripMenuItem
//
this->pruefungAuswaehlenToolStripMenuItem->Name = L"pruefungAuswaehlenToolStripMenuItem";
this->pruefungAuswaehlenToolStripMenuItem->Size = System::Drawing::Size(224, 22);
this->pruefungAuswaehlenToolStripMenuItem->Text = L"Prüfung auswählen";
this->pruefungAuswaehlenToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::pruefungAuswaehlenToolStripMenuItem_Click);
//
// neuePruefungenHinzufuegenToolStripMenuItem
//
this->neuePruefungenHinzufuegenToolStripMenuItem->Name = L"neuePruefungenHinzufuegenToolStripMenuItem";
this->neuePruefungenHinzufuegenToolStripMenuItem->Size = System::Drawing::Size(224, 22);
this->neuePruefungenHinzufuegenToolStripMenuItem->Text = L"Neue Prüfungen hinzufügen";
this->neuePruefungenHinzufuegenToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::neuePruefungenHinzufuegenToolStripMenuItem_Click);
//
// radierenToolStripMenuItem
//
this->radierenToolStripMenuItem->Name = L"radierenToolStripMenuItem";
this->radierenToolStripMenuItem->Size = System::Drawing::Size(82, 20);
this->radierenToolStripMenuItem->Text = L"Rückgängig";
this->radierenToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::radierenToolStripMenuItem_Click);
//
// pictureBox1
//
this->pictureBox1->BackColor = System::Drawing::SystemColors::Control;
this->pictureBox1->Dock = System::Windows::Forms::DockStyle::Fill;
this->pictureBox1->Location = System::Drawing::Point(0, 24);
this->pictureBox1->Name = L"pictureBox1";
this->pictureBox1->Size = System::Drawing::Size(712, 272);
this->pictureBox1->SizeMode = System::Windows::Forms::PictureBoxSizeMode::StretchImage;
this->pictureBox1->TabIndex = 1;
this->pictureBox1->TabStop = false;
this->pictureBox1->Visible = false;
this->pictureBox1->Paint += gcnew System::Windows::Forms::PaintEventHandler(this, &Form1::pictureBox1_Paint);
this->pictureBox1->MouseDown += gcnew System::Windows::Forms::MouseEventHandler(this, &Form1::pictureBox1_MouseDown);
this->pictureBox1->MouseMove += gcnew System::Windows::Forms::MouseEventHandler(this, &Form1::pictureBox1_MouseMove);
this->pictureBox1->MouseUp += gcnew System::Windows::Forms::MouseEventHandler(this, &Form1::pictureBox1_MouseUp);
this->pictureBox1->Resize += gcnew System::EventHandler(this, &Form1::pictureBox1_Resize);
//
// openFileDialog1
//
this->openFileDialog1->FileName = L"openFileDialog1";
//
// hScrollBar1
//
this->hScrollBar1->Dock = System::Windows::Forms::DockStyle::Bottom;
this->hScrollBar1->Location = System::Drawing::Point(0, 751);
this->hScrollBar1->Name = L"hScrollBar1";
this->hScrollBar1->Size = System::Drawing::Size(1024, 17);
this->hScrollBar1->TabIndex = 2;
this->hScrollBar1->Scroll += gcnew System::Windows::Forms::ScrollEventHandler(this, &Form1::hScrollBar1_Scroll);
//
// vScrollBar1
//
this->vScrollBar1->Dock = System::Windows::Forms::DockStyle::Right;
this->vScrollBar1->Location = System::Drawing::Point(1007, 24);
this->vScrollBar1->Name = L"vScrollBar1";
this->vScrollBar1->Size = System::Drawing::Size(17, 727);
this->vScrollBar1->TabIndex = 3;
this->vScrollBar1->Scroll += gcnew System::Windows::Forms::ScrollEventHandler(this, &Form1::vScrollBar1_Scroll);
//
// label1
//
this->label1->AutoSize = true;
this->label1->Location = System::Drawing::Point(561, 8);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(35, 13);
this->label1->TabIndex = 2;
this->label1->Text = L"label1";
//
// contextMenuStrip1
//
this->contextMenuStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(1) {this->toolStripMenuItem2});
this->contextMenuStrip1->Name = L"contextMenuStrip1";
this->contextMenuStrip1->Size = System::Drawing::Size(84, 26);
this->contextMenuStrip1->Text = L"Antworten";
//
// toolStripMenuItem2
//
this->toolStripMenuItem2->Name = L"toolStripMenuItem2";
this->toolStripMenuItem2->Size = System::Drawing::Size(83, 22);
this->toolStripMenuItem2->Text = L"1.";
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(712, 296);
this->Controls->Add(this->label1);
this->Controls->Add(this->pictureBox1);
this->Controls->Add(this->menuStrip1);
this->MainMenuStrip = this->menuStrip1;
this->Name = L"Form1";
this->Text = L"Correctus";
this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
this->menuStrip1->ResumeLayout(false);
this->menuStrip1->PerformLayout();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox1))->EndInit();
this->contextMenuStrip1->ResumeLayout(false);
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
private:
//öffnen der gescannten Bilder
System::Void oeffnenToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e);
//Speichern
void speichernToolStripMenuItem_Click(Object^ sender, EventArgs^ e);
//beim laden Fenster Maximieren
System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
WindowState = FormWindowState::Maximized;
}
//Beenden-Methode
System::Void beendenToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
sicherheitsAbfrage();
}
void pictureBox1_Resize(Object^ sender, EventArgs^ e);
//siehe Methodenrumpf
void setScrollBars();
//Refresh bei scrollen der vertikalen Scrollbar
System::Void vScrollBar1_Scroll(System::Object^ sender, System::Windows::Forms::ScrollEventArgs^ e) {
pictureBox1->Refresh();
}
//Refresh bei scrollen der horizontalen Scrollbar
System::Void hScrollBar1_Scroll(System::Object^ sender, System::Windows::Forms::ScrollEventArgs^ e) {
pictureBox1->Refresh();
}
//Neuzeichnung der Imagebox
System::Void pictureBox1_Paint(System::Object^ sender, System::Windows::Forms::PaintEventArgs^ e);
//Prüfung auswählen
System::Void pruefungAuswaehlenToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
Pruefung_auswaehlen^ zeigePruefung_auswaehlen = gcnew Pruefung_auswaehlen(faecher);
zeigePruefung_auswaehlen->ShowDialog();
}
// Neue Lösung in die jeweilige Prüfung einfügen
System::Void neueLoesungenHinzufuegenToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
// faecher->
}
//hier wird eine neue Prüfung dem Array hinzugefügt
System::Void neuePruefungenHinzufuegenToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
Pruefung_hinzufuegen^ zeigePruefung_hinzufuegen = gcnew Pruefung_hinzufuegen(faecher);
zeigePruefung_hinzufuegen->ShowDialog();
}
private: System::Void pictureBox1_MouseDown(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e);
private: System::Void pictureBox1_MouseMove(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e);
private: System::Void pictureBox1_MouseUp(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e);
System::Void menuItem1_Click(System::Object^ sender, System::EventArgs ^e);
void aufbauAntworten();
void zeichneNach();
void sicherheitsAbfrage();
private: System::Void radierenToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e);
void speichern();
};
}
die Form1.cpp:
Code:
#include "stdafx.h"
#include "Form1.h"
namespace Correctus {
void Form1::oeffnenToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
if (openFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK)
{
// Bild laden
img = Image::FromFile(openFileDialog1->FileName);
// Rendering des Bildes anstoßen
pictureBox1->Image = img;
pictureBox1->Visible = true;
layer = Graphics::FromImage(img);
// Bildlaufleisten einstellen
setScrollBars();
}
}
//Speichern
void Form1::speichernToolStripMenuItem_Click(Object^ sender, EventArgs^ e)
{
if (img == nullptr)
return;
speichern();
}
void Form1::speichern() {
// voreingestellten Dateityp an Bildformat anpassen
if (img->RawFormat->Equals(ImageFormat::Bmp))
saveFileDialog1->FilterIndex = 1;
else if (img->RawFormat->Equals(ImageFormat::Jpeg))
saveFileDialog1->FilterIndex = 2;
else
saveFileDialog1->FilterIndex = 3;
if (saveFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK)
{
if (saveFileDialog1->FileName == openFileDialog1->FileName)
{
MessageBox::Show("Zurückschreiben in die alte Datei wird nicht unterstützt");
return;
}
switch (saveFileDialog1->FilterIndex)
{
case 1 : img->Save(saveFileDialog1->FileName, ImageFormat::Bmp);
break;
case 2 : img->Save(saveFileDialog1->FileName, ImageFormat::Jpeg);
break;
case 3 : img->Save(saveFileDialog1->FileName, ImageFormat::Png);
break;
}
}
}
void Form1::pictureBox1_Paint(System::Object^ sender, System::Windows::Forms::PaintEventArgs^ e) {
Graphics ^gc = e->Graphics;
gc->Clear(SystemColors::ControlLight);
if (pictureBox1->Image != nullptr)
{
// Korrektur für möglicherweise eingeblendete Bildlaufleisten
int corrW = 0;
int corrH = 0;
if (vScrollBar1->Visible)
corrW = vScrollBar1->Width;
if (hScrollBar1->Visible)
corrH = hScrollBar1->Height;
//pictureBox1->SizeMode = PictureBoxSizeMode::CenterImage;
gc->DrawImage(pictureBox1->Image,
Rectangle(0, 0,
pictureBox1->Right - corrW,
pictureBox1->Bottom - corrH),
Rectangle(hScrollBar1->Value, vScrollBar1->Value,
pictureBox1->Right - corrW,
pictureBox1->Bottom - corrH),
GraphicsUnit::Pixel);
}
}
void Form1::pictureBox1_Resize(Object^ sender, EventArgs^ e){
//Nicht reagieren, wenn kein Bild geladen oder das
//Fenster minimiert ist.
if (pictureBox1->Image != nullptr && WindowState != FormWindowState::Minimized)
{
setScrollBars();
pictureBox1->Refresh();
}
}
void Form1::setScrollBars()
{
// Bildlaufleisten einblenden, wenn die Bildbreite (-höhe) größer als die PictureBox ist
hScrollBar1->Visible = pictureBox1->Image->Width > pictureBox1->Width;
vScrollBar1->Visible = pictureBox1->Image->Height > pictureBox1->Height;
// nochmals prüfen und sichtbare Bildlaufleisten mit berücksichtigen
if (vScrollBar1->Visible)
hScrollBar1->Visible = pictureBox1->Image->Width > (pictureBox1->Width - vScrollBar1->Width);
if (hScrollBar1->Visible)
vScrollBar1->Visible = pictureBox1->Image->Height > (pictureBox1->Height - hScrollBar1->Height);
// horizontale Bildlaufleiste konfigurieren
hScrollBar1->Value = 0;
hScrollBar1->Minimum = 0;
hScrollBar1->Maximum = pictureBox1->Image->Width - 1;
hScrollBar1->SmallChange = 1;
// LargeChange auf Anzeigebreite setzen
if (hScrollBar1->Visible)
{
if (vScrollBar1->Visible)
hScrollBar1->LargeChange = pictureBox1->Width - vScrollBar1->Width;
else
hScrollBar1->LargeChange = pictureBox1->Width;
}
// vertikale Bildlaufleiste konfigurieren
vScrollBar1->Value = 0;
vScrollBar1->Minimum = 0;
vScrollBar1->Maximum = pictureBox1->Image->Height - 1;
vScrollBar1->SmallChange = 1;
// LargeChange auf Anzeigehöhe setzen
if (vScrollBar1->Visible)
{
if (hScrollBar1->Visible)
vScrollBar1->LargeChange = pictureBox1->Height - hScrollBar1->Height;
else
vScrollBar1->LargeChange = pictureBox1->Height;
}
}
void Form1::pictureBox1_MouseDown(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e) {
if(e->Button == System::Windows::Forms::MouseButtons::Left && !radieren) {
mouseDown = true;
point->Add(gcnew SchreibKoordinaten(e->X + hScrollBar1->Value,e->Y + vScrollBar1->Value));
layer->FillRectangle(Brushes::Green,e->X + hScrollBar1->Value,e->Y + vScrollBar1->Value, 1, 1);
pictureBox1->Invalidate();
}
}
void Form1::pictureBox1_MouseMove(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e) {
if(mouseDown && !radieren) {
p = Point(e->X + hScrollBar1->Value, e->Y + vScrollBar1->Value);
layer->DrawLine(pen1, point[anzahl_gezeichnet]->getKoord(),p);
point[anzahl_gezeichnet]->setKoord(e->X + hScrollBar1->Value, e->Y + vScrollBar1->Value);
region1 = gcnew System::Drawing::Region(Rectangle(e->X + hScrollBar1->Value -20, e->Y + vScrollBar1->Value-20, 40,40));
pictureBox1->Invalidate(region1);
}
}
void Form1::pictureBox1_MouseUp(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e) {
if(e->Button == System::Windows::Forms::MouseButtons::Left) {
if(mouseDown && !radieren) {
p = Point(e->X + hScrollBar1->Value, e->Y + vScrollBar1->Value);
layer->DrawLine(pen1, point[anzahl_gezeichnet]->getKoord(),p);
point[anzahl_gezeichnet]->setKoord(e->X + hScrollBar1->Value, e->Y + hScrollBar1->Value);
mouseDown = false;
pictureBox1->Invalidate();
tester = gcnew HackenTest(point[anzahl_gezeichnet]->listAusgabe());
if (e->X + hScrollBar1->Value < img->Width - img->Width/3) {
if(tester->istHacken()) {
aufbauAntworten();
zeichneNach();
contM->Show(pictureBox1,point[anzahl_gezeichnet]->getKoord() );
point[anzahl_gezeichnet]->setIstHacken();
}
}
++anzahl_gezeichnet;
}
}
}
void Form1::zeichneNach() {
List<Point> ^haken = point[anzahl_gezeichnet]->listAusgabe();
Point a = haken[0];
for each(Point ziel in haken) {
layer->DrawLine(penRed, a,ziel);
a = ziel;
}
}
void Form1::aufbauAntworten() {
try {
List<Antwort^> ^daten;
for each (AntwortDaten ^fach in faecher) {
if (fach->getAusgewaehlt()) {
daten = fach->getAntworten();
}
}
contM = gcnew System::Windows::Forms::ContextMenu();
this->ContextMenu = contM;
for each (Antwort ^antwort in daten){
if(antwort->istSichtbar()) {
MenuItem ^mnuItemOpenWith = gcnew MenuItem();
mnuItemOpenWith->Text = antwort->getAntwort();
mnuItemOpenWith->MenuItems->Add(mnuItemOpenWith);
mnuItemOpenWith->Click += gcnew System::EventHandler(this, &Correctus::Form1::menuItem1_Click);
contM->MenuItems->Add(mnuItemOpenWith);
}
}
}
catch(Exception ^) {
MessageBox::Show("Bitte Prüfung auswählen", "Fehler");
}
}
System::Void Form1::menuItem1_Click(System::Object^ sender, System::EventArgs ^e) {
MenuItem ^item= static_cast<MenuItem^>(sender);
List<Antwort^> ^daten;
for each (AntwortDaten ^fach in faecher)
{
if(fach->getAusgewaehlt()) {
daten = fach->getAntworten();
}
}
for each (Antwort ^antwort in daten) {
if(antwort->getAntwort() == item->Text) {
antwort->abgehackt();
point[anzahl_gezeichnet-1]->setAntwortNr(antwort->getAwNr());
}
}
}
System::Void Form1::radierenToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
if(radieren)
radieren = false;
else
radieren = true;
}
void Form1::sicherheitsAbfrage() {
System::Windows::Forms::DialogResult ^dr = MessageBox::Show("Wollen Sie speichern?", "Beenden", MessageBoxButtons::YesNoCancel);
if(dr == System::Windows::Forms::DialogResult::Yes && img != nullptr) {
speichern();
this->Close();
}
if(dr == System::Windows::Forms::DialogResult::No) {
this->Close();
} else {
return;
}
}
}
Wie gesagt, Ihr müsst die Abhängigkeiten noch löschen, die ihr eh nicht habt. das ist die Betreffende Klasse.
Sagt nichts zu dem Programmierstil, ich arbeite erst seit 3 Monaten mit C++/CLI