These are the event handlers doing the actual work:
Code:
// Form1.cpp
#include "stdafx.h"
#include "Form1.h"
using namespace LayeredPNGs;
System::Void Form1::trkX_Scroll(System::Object^ sender, System::EventArgs^ e)
{
int x = trkX->Value;
lblX->Text = String::Format("x = {0}", x);
ptOverlayPos.X = x;
pbBack->Invalidate();
}
System::Void Form1::trkY_Scroll(System::Object^ sender, System::EventArgs^ e)
{
int y = trkY->Maximum - trkY->Value;
lblY->Text = String::Format("y = {0}", y);
ptOverlayPos.Y = y;
pbBack->Invalidate();
}
System::Void Form1::pbBack_Paint(System::Object^ sender, System::Windows::Forms::PaintEventArgs^ e)
{
e->Graphics->DrawImage(bmpOverlay, ptOverlayPos);
}
The following is the constructor that sets up the form class:
Code:
public:
Form1(void) : ptOverlayPos(0, 0)
{
InitializeComponent();
//
//TODO: Konstruktorcode hier hinzufügen.
//
/*
// The following is meant to set up the Bitmap object from an image resource. Unfortunately
// it tends to fail regularly (at least for me) due to the "vanishing resource problem".
ComponentResourceManager ^cresm = gcnew ComponentResourceManager(Form1::typeid);
Object ^objResource = cresm->GetObject("Overlay.png");
Diagnostics::Trace::Assert(objResource != nullptr, "Overlay bitmap construction from resource failed");
bmpOverlay = gcnew Bitmap(safe_cast<Drawing::Image ^>(objResource));
*/
// This is the alternative way, constructing the Bitmap object from a disk file
// (wouldn't really like that in a real-life app though):
bmpOverlay = gcnew Bitmap("Overlay.png");
A great deal of this code is really commented out, but I required showing it to you because that's the genuine way of creating the bitmap object. Disappear resource problem occurs whenever the slightest I can alter the form explain, all the resources that are physically added to Form1.resx vanish instantly. Would almost certainly have to put in a resx file in the project that is self-governing of form, but have not managed to do this. Maybe I'm too dumb to understand how to use this managed resource "editor" or just another weird limitation of the Express edition. In fact, I would really like either option.
Bookmarks