Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi
i have got some images in dictionary from database ,i want to fetch that same image on to the canvas in the middle position of it using dictionary.
need help urgently.....
Posted

To draw an image onto a control, you should override that control's OnPaint() method.
C#
override void OnPaint(object sender, PaintEventArgs e)
{
    System.Drawing.Image image = _dictionary[keyToTheImage];

    // Used to place image onto center
    int imageWidth = image.Width;
    int imageHeight = image.Height;

    e.Graphics.DrawImage(
        image,
        new RectangleF(
            (this.Width - imageWidth) / 2F,
            (this.Height - imageHeight) / 2F,
            imageWidth,
            imageHeight
        )
    );
}
 
Share this answer
 
Comments
ravithejag 15-Feb-12 3:54am    
thanks for your solution
C#
string itemPath = null;
foreach (var item in arrAllItems)
{
    if (itemC[i] == item.id)
    {
         itemPath = item.imgPathLarge;
    }
}


by using these code i am able to get the image from the database into the new canvas
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900