|
Hi,
IMO the most important thing is not annoying your users with to heavy licensing
Probably for a game your users are just expecting a serial number. You need to pick where to store it, in your app settings, or the registry. Then you need some code to generate numbers, and some code to check if a serial number is valid.
http://www.codeproject.com/install/LicenseKeyGeneration.asp[^] - seems useful for that.
|
|
|
|
|
I tried using dispose() on a picturebox to remove the file being held open since I am trying to programmatically delete the file. But, it is giving an exception saying that the file is in use.
I am displaying the image in the following way.
pictureBox.Image = System.Drawing.Image.FromFile(path);
How can I remove it from being held open?
|
|
|
|
|
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.
|
|
|
|
|
as Christian Graus said before ,you must Dispose the image not the pictureBox
this.pictureBox1.Image.Dispose();
System.IO.File.Delete(path);
Good Luck
|
|
|
|
|
Hi, if you use a FileStream to read your image, you will not have these problems,
since FromStream does not keep the file open.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
hi everybody!
I have a requirement to identify whether the file I am copying is an image, audio, video, office document etc.
What's the best way to do this apart from checking the extensions?
Anyway, i handled identifying non-images. but, when it comes to identifying video, audio and office docs, I don't think checking on extensions would be a wise move.How can I do it effectively?
Regards,
A
|
|
|
|
|
aravinda777 wrote: What's the best way to do this apart from checking the extensions?
Use GDI+ to attempt to load a file and verify if it's an image. Write code that reads the file itself and attempts to identify the file format, which means you need to look for unique markers for each of these file types, and look for them.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Christian Graus wrote: Use GDI+ to attempt to load a file and verify if it's an image.
Okay. Yeah. but what about other extension (eg: doc)?
Christian Graus wrote: rite code that reads the file itself and attempts to identify the file format, which means you need to look for unique markers for each of these file types, and look for them.
I'm not clear about that. Could you please explain me again?
unique markers
like ??
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.
|
|
|
|
|
Something like how to identify those particular markers and stuff?
|
|
|
|
|
Michael Sync wrote: but what about other extension (eg: doc)?
Exactly as I said
Michael Sync wrote: I'm not clear about that. Could you please explain me again?
You'd have to know that the file format contains the word 'WORD' in the first four bytes, for example, and open the file and examine it for those known markers related to the known file format.
Michael Sync wrote: like ??
I have no idea, I'm not the one with the issue.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Thanks. Christian..
Christian Graus wrote: Exactly as I said
Yeah.
Christian Graus wrote: I have no idea, I'm not the one with the issue.
Okay.
Christian Graus wrote: You'd have to know that the file format contains the word 'WORD' in the first four bytes, for example, and open the file and examine it for those known markers related to the known file format.
Oh.. I didn't know about that.. I will try to check this one.. thanks.
But i think that checking the extension might be more easier than checking the fist four bytes of each file, isn't it?
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.
|
|
|
|
|
Michael Sync wrote: ut i think that checking the extension might be more easier than checking the fist four bytes of each file, isn't it?
The first four bytes is an example off the top of my head. It's not real, Word doesn't do that. But, it may well do *something* to mark it's files.
And yes, checking the extension is going to work 99% of the time, and is a lot easier to do.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
aravinda777 wrote: i handled identifying non-images
non-images files means "*.txt, *.dll, *.exe"?? How did you handle identifying those file type without checking the extension??
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.
|
|
|
|
|
In fact i am using the image to be displayed in a picturebox. When I try non-images, it gives an OutOfMemoryException.
This way I can identify non-images.
|
|
|
|
|
There is no general solution to identifying a file's type; new file types are
created every day.
If you are only interested in whether it is a loadable image, then try to load
the image, and live with the possible exception.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Maybe you will find this site useful:
http://www.wotsit.org/
Greetings, Thomas
|
|
|
|
|
You can check only the extension but it might be incorrect. If you want tighter control then look for magic number[^] in that file
|
|
|
|
|
Hi All,
I facing a problem which i have described briefly in the following paragraph.
Let me tell you a scenario where in the user has to choose any kind of dll he wants, rather be .Net Dll or Native Dll for a connection to his server.
In that he knows the function to Invoke.
I need to write a common user interface to invoke any kind of dll, based on the choice of the user. Is that possible ?. If so help me regarding the stratergy that i have to use or any examples of such accomplishment.
FYI
I know one software which is doing to most of the Dll's.
Thanks in Advance
|
|
|
|
|
You can late bind to .NET dlls, I'm not sure what you can do about native dlls, without having the pinvoke code already in your app.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
There are some articles here on cp which show you how to invoke function from a native dll without pinvoke code in the source.
|
|
|
|
|
hi, i am dealing with a stock market app, which is developing in c#.......... for trade purpose i want to use the QuickFix Protocol........ i was searching for sample codes for the same.... if any one have any idea pls contribute.............
My small attempt...
|
|
|
|
|
|
I had write code on text_change event of richText box in C#.net for wordwrap.
When i created the project and tested it its working fine, so i copy it make exe. Now problem is its showing some problem. so i check this code with oroginal code. In original code its working fine, but in copied code it showing problem.
The problem is like, after 3-4 line, at end of line its giving space in 2 letter like "Him" as "H i m", and adding "/n"at end of text.
Here maxLength is variable for no. of chracter like 65,66 etc per line, And if there is somthing wrong with code then plz help me.(not mismatch of { })
I want to know:
1. Code is for text_changed event & exact same in both, So why it like this?
2. Its only for text_change event and I dont think it has any relation with any other project part, i m using the text but after it has been put by the user.
The code for event is:
<br />
private void txtBody_TextChanged(object sender, eventArgs e)<br />
{<br />
<pre>if(tbWordwrap.Pushed)
{
string[] tempArray = new string(txtBody.Lines.length);
tempArray = txtBody.Lines;
int Prevsel = txtBody.SelectionStart;
string Op = "";
int maxLength = cINI.dbUtils.Pref.DefaultEditorWidth;
bool change= false;
for(int cou = 0; cou < tempArray.Length ; cou++)
{
if (tempArray[cou].length > maxLength)
{
string words = tempArray[cou].split(' ');
int currentLine Length = 0;
string currentLine = "";
foreach(string currentWords in words)
{
if(currentWord.Length > 0)
{
if(currentword.Length >= maxLength)
{
Op += currentword.Insert(maxLength, "\r\n");
break;
}
if(currentLineLength + currentword.Length + 1 < maxLength)
{
currentLine += currentword + " ";
currentLineLength += currentword.Length +1;
}
else
{
Op +=currentLine.Insert(currentLineLength, "\r\n");
currentLine = currentWord;
currentLineLength = currentWord.Length;
}
}
}
if(currentLine !="")
Op += currentLine;
PrevSel++;
change = true;
}
else
{
Op += tempArray[cou] + "\r\n";
}
if(change)
{
txtBody.Text = Op;
txtBody.SelectionStart = prevSel;
}
}
}</pre><br />
<br />
<br />
-- modified at 1:11 Wednesday 22nd August, 2007
|
|
|
|
|
best guess, the control is different sizes on the two forms, and so one version is showing up bugs in your code that are not evident in the other version.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hi techies,
m working on the student management project (School) on C# 2005 and sql 2005 (windows application), i completed 80% , it can
create class , add section , edit student seats in particular section, add subject, add subject to the
particular section, registration of the student acccording to the class and section also display vacant
seat while registration, create first term result , second term result and final term, it can give
grace if student flunking( max 20 marks) , all result are in datagridview , but now i stuk while
printing it , i want to print the datagridview with form control(text box and label) coz it contains the
student information. so any one gimmme favour. (it shud b include print preview , page setting, and
print dialog) .
<<tech-prog>>
|
|
|
|