Click here to Skip to main content
15,899,937 members
Home / Discussions / C#
   

C#

 
AnswerRe: "handling" an event on controls Pin
Martin#21-Aug-07 22:09
Martin#21-Aug-07 22:09 
GeneralRe: "handling" an event on controls Pin
cignox122-Aug-07 0:22
cignox122-Aug-07 0:22 
GeneralRe: "handling" an event on controls Pin
Martin#22-Aug-07 1:16
Martin#22-Aug-07 1:16 
QuestionSoftware Licening.. Pin
Rahul.RK21-Aug-07 20:40
Rahul.RK21-Aug-07 20:40 
AnswerRe: Software Licening.. Pin
Nouman Bhatti21-Aug-07 21:00
Nouman Bhatti21-Aug-07 21:00 
AnswerRe: Software Licening.. Pin
Mark Churchill21-Aug-07 21:18
Mark Churchill21-Aug-07 21:18 
QuestionDeleting a file being loaded in a picturebox Pin
aravinda77721-Aug-07 20:17
aravinda77721-Aug-07 20:17 
AnswerRe: Deleting a file being loaded in a picturebox Pin
Michael Sync21-Aug-07 20:39
Michael Sync21-Aug-07 20:39 
Try this code ~

 private void button1_Click(object sender, EventArgs e)<br />
        {<br />
            string p = "C:\\a.bmp";<br />
            Image img = Image.FromFile (p);<br />
            pictureBox1.Image = img;<br />
            MessageBox.Show ("Image added.");<br />
            img.Dispose ();<br />
<br />
            if ( !CheckIfFileIsBeingUsed (p) )<br />
            {<br />
                System.IO.File.Delete (p);<br />
                MessageBox.Show ("Image deleted.");<br />
            }<br />
            <br />
        }<br />
        public bool CheckIfFileIsBeingUsed(string fileName)<br />
        {<br />
             System.IO.FileStream fs;<br />
            try<br />
            {<br />
<br />
                fs = System.IO.File.Open (fileName, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.None);<br />
                fs.Close();<br />
            }<br />
            catch ( Exception exp )<br />
            {<br />
                Console.WriteLine (exp.Message);<br />
                return true;<br />
            }<br />
            return false;<br />
<br />
        }


Note that you should not directly set the image to PictureBox. Instead, use one buffer and dispose it if you don't need anymore.

Ref: This CheckIfFileIsBeingUsed method is from http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=547070&SiteID=1[^]

Hope it helps..




Thanks and Regards,
Michael Sync ( Blog: http://michaelsync.net)

If you want to thank me for my help, please vote my message by clicking one of numbers beside "Rate this message". Why vote? Plz Read it here. Thank you. Smile | :)

AnswerRe: Deleting a file being loaded in a picturebox Pin
Hessam Jalali21-Aug-07 20:41
Hessam Jalali21-Aug-07 20:41 
AnswerRe: Deleting a file being loaded in a picturebox Pin
Luc Pattyn22-Aug-07 1:01
sitebuilderLuc Pattyn22-Aug-07 1:01 
QuestionIdentifying the type of file Pin
aravinda77721-Aug-07 19:57
aravinda77721-Aug-07 19:57 
AnswerRe: Identifying the type of file Pin
Christian Graus21-Aug-07 20:01
protectorChristian Graus21-Aug-07 20:01 
GeneralRe: Identifying the type of file Pin
Michael Sync21-Aug-07 20:19
Michael Sync21-Aug-07 20:19 
GeneralRe: Identifying the type of file Pin
aravinda77721-Aug-07 20:32
aravinda77721-Aug-07 20:32 
GeneralRe: Identifying the type of file Pin
Christian Graus21-Aug-07 20:45
protectorChristian Graus21-Aug-07 20:45 
GeneralRe: Identifying the type of file Pin
Michael Sync21-Aug-07 21:59
Michael Sync21-Aug-07 21:59 
GeneralRe: Identifying the type of file Pin
Christian Graus22-Aug-07 0:10
protectorChristian Graus22-Aug-07 0:10 
AnswerRe: Identifying the type of file Pin
Michael Sync21-Aug-07 20:03
Michael Sync21-Aug-07 20:03 
GeneralRe: Identifying the type of file Pin
aravinda77721-Aug-07 20:13
aravinda77721-Aug-07 20:13 
GeneralRe: Identifying the type of file Pin
Luc Pattyn22-Aug-07 1:04
sitebuilderLuc Pattyn22-Aug-07 1:04 
GeneralRe: Identifying the type of file Pin
Thomas Krojer23-Aug-07 0:53
Thomas Krojer23-Aug-07 0:53 
AnswerRe: Identifying the type of file Pin
Giorgi Dalakishvili21-Aug-07 22:07
mentorGiorgi Dalakishvili21-Aug-07 22:07 
QuestionHelp me in Invoking Dll's Pin
kandy_soliton21-Aug-07 19:38
kandy_soliton21-Aug-07 19:38 
AnswerRe: Help me in Invoking Dll's Pin
Christian Graus21-Aug-07 20:00
protectorChristian Graus21-Aug-07 20:00 
GeneralRe: Help me in Invoking Dll's Pin
Giorgi Dalakishvili21-Aug-07 22:09
mentorGiorgi Dalakishvili21-Aug-07 22:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.