I did it like this:
MainForm(void)
{
InitializeComponent();
this->pictureBox1->Click += gcnew System::EventHandler(this, &AI_Events::MainForm::OnClick);
this->rnd = gcnew Random(1234);
this->imgFile = gcnew String("D:\\Code\\star.png");
this->Init();
}
void MainForm::Init()
{
this->pictureBox1->SizeMode = PictureBoxSizeMode::Zoom;
this->pictureBox1->Image = Image::FromFile(this->imgFile);
}
void MainForm::OnClick(System::Object ^sender, System::EventArgs ^e)
{
Rectangle rt = this->panel1->Bounds;
Rectangle rp = this->pictureBox1->Bounds;
int xrnd = this->rnd->Next(rt.Left, rt.Right - rp.Width);
int yrnd = this->rnd->Next(rt.Top, rt.Bottom - rp.Height);
Point p(xrnd, yrnd);
this->pictureBox1->Location = p;
String^ t = xrnd.ToString();
t += "," + yrnd.ToString();
this->Msg(t);
}