|
Giorgi Dalakishvili wrote: How can a file be in use if you are creating it?
It can,
Assume you created file and some other user in the network accessed the file. So when my application tries to modify the contents of the file, it will raise exception. For modification, I am recreating the file with same name. Is this making the problem ? So I was searching for a better approach for this problem.
|
|
|
|
|
Hi all, I'm trying to get a "read only" behaviour from common controls such as check boxes and comboboxes (disabling them is not an option, though, due to the color of the resulting text).
What I thought to do was catching a few events and, if the control is read only, then avoiding the control to respond to it.
Is there a way to 'handle' the event as with key events or with dispose with Java?
Would you otherwise suggest other approaches to get the read only behaviour?
Thank you
Alessandro
|
|
|
|
|
Hello,
Most controls react on the MouseDown event!
So it would be an option to inherit your special control from the control you would liek to modify.
Then you just have to add some properties which tell you how to react.
Your inherited control can than override the method which fires the MouseDown event, and block the call of the base method.
This will, of course lead to an unexpected reaction (nothing happens) for the user of your control.
Because if you do not change the colors or do some other notivication, he would expect the MouseDown to fir and for example the CheckBox changing their Checked state.
Here is an example for the CheckBox, where I just added a property called "ReadOnly" and overrided "OnMouseDown":
using System;
using System.ComponentModel;
namespace YourNamespace
{
public class ReadOnlyCheckBox : System.Windows.Forms.CheckBox
{
public ReadOnlyCheckBox()
{
}
private bool _readonly = true;
[Category("ReadOnlySpecials")]
[Description("This property enables/disables the functonality of the control")]
[DefaultValue(true)]
public bool ReadOnly
{
get
{
return _readonly;
}
set
{
if(value!=_readonly)
{
_readonly = value;
}
}
}
protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e)
{
if(!ReadOnly)
base.OnMouseDown (e);
}
}
}
Hope it helps!
All the best,
Martin
|
|
|
|
|
Thank you for replying, but I don't think this solves my problem: we already make it working for both comboboxes and checkboxes (the first thank to an article here on codeproject, the second using the property AutoCheck). We were also able to simulate read only behaviour for numericupdown, by setting Increment to 0 and readonly property to true;
Now we are trying with datetimepicker, without much success, and overriding the On****() methods seem to have no effect on the control...
Other ideas?
Thank you again,
Alessandro
|
|
|
|
|
Hello,
If you want to disable the Key Input, you have to override the OnKeyPress and set e.Handled to true:
protected override void OnKeyPress(System.Windows.Forms.KeyPressEventArgs e)
{
if(ReadOnly)
{
e.Handled = true;
}
base.OnKeyPress (e);
}
All the best,
Martin
|
|
|
|
|
Hello friends,
We have developed a small game(Windows Application) and now we wish to distribute it.
We just want to do authentication of user. That is licensed user only should use the software.
I just want to know, what steps should we follow and what are different techniques available to
achieve this.
Thanks in advance.
Rahul Kulkarni
|
|
|
|
|
one way of authentication is digital certificates
http://www.google.com.pk/search?hl=en&q=digital+certificates&btnG=Google+Search&meta=
|
|
|
|
|
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
|
|
|
|