Frage

The problem is simple:

I have multiple objects on a form and I want to raise the event of an object that has "before" him another object. Practically I want to delegate the event to the next object comming after him.

void EditorNode::onButtonDownClick(System::Object^  sender, System::Windows::Forms::MouseEventArgs^  e) {
    // here I need to call the event of another object - a picturebox
    drawCanvas->OnMouseDown( *e);
}

I'm not sure if this is the right method of doing this. I also get the following error.

'System::Windows::Forms::Control::OnMouseDown': candidate function(s) not accessible

How should I proceed? Whats the best method of doing this?

War es hilfreich?

Lösung

The compiler objects because OnMouseDown() is a protected method. Pretty intentional, it stops you from shooting yourself in the foot. Your are certainly aiming that gun, the e object does not have the correct property values. The Location, X and Y properties are wrong, they are relative from the control's client area.

You will need to add a public method to whatever class represents the drawCanvas object so you can call OnMouseDown(). And take care of giving the MouseEventArgs object the proper values, that typically requires the PointToScreen and PointToClient methods to translate the coordinate value. If it is a PictureBox object then you'll need to derive from it so you can add that public method. All and all a very strong hint that you are doing it wrong.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top