07-24-2013, 10:46 AM
i have loaded image and everything is perfect, but when i try to click with mouse nothing happens.
i have written what someone told me:
//defining the title width and height in pixels
int title_Width = 32;
int title_height = 32;
//our image
Bitmap bmp = null;
private void pictureBox1_MouseClick(object sender, MouseEventArgs e)
{
//getting the mouse location on the image
int mouse_Location_x = e.X;
int mouse_Location_y = e.Y;
//seeing in what title I clicked
int title_x = (mouse_Location_x / title_Width) - 1;
int title_y = (mouse_Location_y / title_height) - 1;
//creating a Rectangle for the image
Rectangle rect = new Rectangle(title_Width * title_x, title_height *
title_y, title_Width, title_height);
//getting the image
bmp = new Bitmap(title_Width, title_height);
pictureBox1.DrawToBitmap(bmp, rect);
}
but when i click nothing happens, so i dont know what are wrong because this function clearly draws a rectangle.
P.S. i have loaded image in a bitmap.
Bitmap myImage = new Bitmap("Images/ItemBtn" + comboBox1.SelectedIndex + ".jpg");
pictureBox1.ClientSize = new Size(512, 512);
pictureBox1.Image = (Image)myImage;

