|
Well, I tried using dispose() on the picturebox.
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?
|
|
|
|
|
I have a datagridview that I can rows using the down error and enterkey. I have DataGridView.Focus() firing after my method to addrows. The focus is on the proper cell but the cell is not active to type in. Does any have any suggestions on how to make the cell active?
|
|
|
|
|
you can select a cell with set the Selected property of that cell to true
like
this.dataGridView1[0, 0].Selected=true;
hope the post would be useful
good luck
|
|
|
|
|
Hello everyone!
I'm working on an application that converts hex data to decimal. Essentially what I do is send a command to an attached device via serial port and it spits back data to me.
The attached device spits data back in hex format and what I need to do is do a bit by bit comparision and convert some specific data to decimal format so I can do some calculations.
I'm at the point where the application I wrote spits this out:
55 55 FF AA 91 30 43 30 30 30 30 36 33 38 37 36 45 42 35 45 34 38 34 39 34 FF
The above data is just a sample. What I need to do is convert the data to decimal. The device that sends the data sends it back in asci format and i pass the data from a byte array into a function that converts it to hex digits.
What classes would I need to use to convert the data into decimal format? I have the initial data read into a byte array.
Sorry wasn't brief but I wanted to be as specific as possible
|
|
|
|
|
Int32.Parse(String, NumberStyles) First parameter is the string you want to convert to int. Use second parameter to specify that the string can be representation of hex number
|
|
|
|
|
Oh great thanks. I have tried that and the application crashes at runtime. So I ran the debugger and it says input string was not in correct format
//here is the method I created for this action
public int processArray(string data)
{
return Int32.Parse(data, NumberStyles.Integer);
}
here is where I call the method
string convertedS
convertedS = System.Text.Encoding.ASCII.GetString(buffer);
convert.processArray(convertedS);
maybe I'm doing something wrong from the very begining... Using .net 2.0 is it possible to read the data in the buffer I created for the serial port straight into a char array?
|
|
|
|
|
David Amyotte wrote: return Int32.Parse(data, NumberStyles.Integer);
Yes, it will produce an error because you are telling the compiler that the string is representation of number but in reality it is representation of HEX number so you should specify NumberStyles.HexNumber
|
|
|
|
|
You could convert the bytes directly using System.BitConverter.ToIntXX. Using a BinaryReader and a MemoryStream might be more convenient as you dont need to keep track of the array index.
|
|
|
|
|
thanks for your help so far.
What I'm doing so far is writing the data in the buffer into a Byte array then converting it to stringbuilder and the output so far is:
55 55 FF AA 91 30 43 30 30 30 30 36 33 38 37 36 45 42 35 45 34 38 34 39 34 FF
what I need to do is find an easy way to extract this data:
36 33 38 37 36 45 42 35 45 34 and convert it to decimal so I can do some calculations on the data. I'm new to .net so I figured this would be a good training exercise for me
Regards
|
|
|
|
|
It depends on the format of the data, you will need to look it up or work it out.
36 could be a byte
36 33 could be short
36 33 38 37 could be an int/float
36 33 38 37 36 45 42 35 could be a long/double
...
...
Example if 36 33 38 37 36 45 42 35 45 34 consits of 5 shorts:
byte[] data = {0x36, 0x33, 0x38, 0x37, 0x36, 0x45, 0x42, 0x35, 0x45, 0x34};
BinaryReader r = new BinaryReader(new MemoryStream(data));
for (int i = 0; i < 5; i++)
Console.WriteLine(r.ReadInt16());
|
|
|
|
|
In my old c++ days, I would use my old function below;
BOOL IsValidFilename(const char *szFilename)<br />
{<br />
<br />
if ( (!szFilename) || (!strlen(szFilename)) )<br />
return (FALSE);<br />
<br />
if ( (strchr(szFilename, '.')) || (strchr(szFilename, '\\')) ||<br />
(strchr(szFilename, '/')) || (strchr(szFilename, ':')) ||<br />
(strchr(szFilename, '<')) || (strchr(szFilename, '>')) ||<br />
(strchr(szFilename, '*')) || (strchr(szFilename, '?')) ||<br />
(strchr(szFilename, '|')) || (strchr(szFilename, '\"')) )<br />
return (FALSE);<br />
<br />
return (TRUE);<br />
}
I thought there might be a cleaner way to test a string before I used it for a file name.
Programmer
Glenn Earl Graham
Austin, TX
|
|
|
|
|
Maybe slightly cleaner. The
Path.GetInvalidFileNameChars should give you an array of invalid chars, which you can iterate and check
IndexOf in your candidate file name.
"Once in Africa I lost the corkscrew and we were forced to live off food and water for weeks." - Ernest Hemingway
My New Blog
|
|
|
|
|
Thanks here is the final code it works perfectly...
bool IsValidFilename(String ^fileName)
{
if ( String::IsNullOrEmpty( fileName ) == true )
return false;
array<Char>^ invalidFileChar = System::IO::Path::GetInvalidFileNameChars();
for each ( Char ^i in invalidFileChar )
{
if ( fileName->Contains(String::Format("{0}", i)) )
{
String ^tmp = String::Format(L" '{0}' is invalid in a file name.\n", i);
System::Windows::Forms::MessageBox::Show(gcnew String(tmp),gcnew String(L"Warning"),
MessageBoxButtons::OK);
return false;
}
}
return true;
}
Programmer
Glenn Earl Graham
Austin, TX
|
|
|
|
|
That doesn't look like C# to me.
|
|
|
|
|
String.IndexOfAny() seems appropriate here.
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
|
|
|
|
|
I'd just try it and catch the exception if any.
Let the OS/framework determine validity; it knows best.
|
|
|
|
|
But if its speed you want, catching the exception may not be the best solution.
Phil
|
|
|
|
|
Absolutely, why check what the OS/framework will check anyway? That's wasteful.
The custom check may be faulty, causing a false valid or invalid. A false valid will likely result in an exception anyway, so you've wasted the time on the extra check, plus the time writing the faulty check.
I know I couldn't write a filename validity checking routine as fast and accurate as the built-in one.
You don't know to what OSs the framework may be ported in future (I know, it's unlikely) and what their validity rules are.
I could certainly see adding some additional checking, like ensuring the name doesn't include a SPACE, or is 8.3 or something, but other than that you're just wasting your time.
This is a wheel best not reinvented.
|
|
|
|
|
Or a Regular Expression, matching any of the invalid characters.
|
|
|
|
|
I like that idea. A regex over a path size string should be blindingly fast as well.
"Once in Africa I lost the corkscrew and we were forced to live off food and water for weeks." - Ernest Hemingway
My New Blog
|
|
|
|
|
Hi All,
Is there any control/method/class/namespace available that i can use in my code in order to get windows XP like left menu.
Thank you!
"Mess with the Best, Die like the rest"
|
|
|
|
|
|
That was very helpful.
Thank You!
"Mess with the Best, Die like the rest"
|
|
|
|
|
Hi..
I have a web application(ASP.NET 2.0, C#), in which I am exporting a xml file.
The web page has a button called Export. When the user clicks the Export button, the File Download pops up, in which it has the Open,Save and Cancel Butons as in a normal file download pop-up. Being an xml file, the page also opens up,without the content behind the File download pop-up,
When the user clicks Cancel button, the file download pop up is gone, but the xml page(without the contents) is still open. This also happens when the user has successfully downloaded the xml file(Xml page is open)
Is it possible to close the xml page after the user clicks the cancel button and after the user saves the xml file? I am using Internet Explorer 6, Windows xp, SP1.
Please help.. Thanks
Thanks & Regards,
Venkat
|
|
|
|
|
i want to create a shape Control like that you got here. But his Control can t draw antialiased linies =/
How can i draw smooth linies ?
|
|
|
|