It's pointing to the error in line 164, which is as below:
frm1.pictureBox5.Image = Image.FromStream(mst);
The exception message is: "System.Argument.Exception: Parameter is not valid. at System.Drawing.Image.FromStream(Stream stream, Boolean useEmbeddedColorManagement, Boolean validateImageData) at System.Drawing.Image.FromStream(Stream stream)at btnResearch_Click(Object sender, EventArgs e) in D:\Mat\frmRecSearch.cs: line 164.
Cool, no issues. It points to a null parameter in the debugger. But the same code, when executed with just an image add and retrieve (a new c# project), the application works really well. I am unable to determine what is the problem here :(
So you need to find out why mst is null at this point. Your code is assuming that you always get a valid byte array from r (whatever that is), and hence a valid stream. However, if either of these commands do not return the expected result you are going to have a problem which you are not catering for. You should never assume that method calls like this will always succeed; add some error checks so you can diagnose it properly when it fails.
One of these days I'm going to think of a really clever signature.
I have a form that has an array of text boxes dynamically added to a splitcontainer on a form. I use the same array to add text boxes to the form twice (different data for different table). I would like to use an event handler, preferably once, to change background color to yellow when textbox[i] receives focus, and back to white when it loses focus. I am currently going around in circles. Can anyone help me? Thanks for your input
Add in a lambda, at the point where you create the textboxes. Like the example below;
var tb = new TextBox();
tb.GotFocus += delegate (object s, EventArgs a)
(s as TextBox).BackColor = Color.Red;
tb.LostFocus += delegate(object s, EventArgs a)
(s as TextBox).BackColor = Color.Green;
I am rewriting a desktop application in VS2010 that was written in .Net 1.1. While doing so, I decided to add a couple of features to the app. One is a data source for a drop down list. I am using a local database file (.sdf) for the data.
I noticed in the .Properties.Settings file that the connection string is a hard link to where I entered the file location (which is C:\Users\\Documents\db\). I need this to be more dynamic, due to the fact this app will be on many different computers.
I tried editing to :
But I receive the following error at compile time:
Error 1 An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type C:\Users\brian\AppData\Local\Temporary Projects\latefeedisc\Properties\Settings.Designer.cs 29 68 latefeedisc
// This code was generated by a tool.
// Runtime Version:4.0.30319.544
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
You aren't supposed to modify that file. You should set the property in the constructor of your window.
Don't. It wasn't "ignorant", just overlooked some semantics that "could" give a hint.
It's a real settings-file; now, if only the database-name (or path) is going to differ, it'd might be neat to use a connection-string with a literal set of characters in the place where the databasename should be, and to Replace the literal with the actual path just before using the string.
So, you want the system to do a simple literal replace for you, but you want to roll your own config file implementation? Clever . Are you also going to write all the cool stuff that you get for free with config files such as encryption, versioning, editing through a simple GUI in VS, backwards compatibility, etc?
How do you integrate with the Visual Studio designer?
Configuration files via the designer? Myself I absolutely despise that. Every time you touch it it re-writes the file. Which means that all formatting is lost. And all documentation.
So you have a file that is intended to be manually edited not using VS which has no formatting and no documentation. And which isn't even necessarily guaranteed the have the same ordering between point releases.
It does mess up the formatting, I'll agree with that. Since it's an XML file, I just hit the "Format Document" button and it fixes it. Not enough of an annoyance to give up the designer editor IMO.
And all documentation.
You put documentation in your config file? Thats an extremely odd place for documentation seeing as the .config files are NOT meant to be edited manually by end users. They are meant to be edited by people who know what the settings are (i.e. developers, etc).
guaranteed the have the same ordering between point releases
Last time I checked, XML and .config files were unordered formats. If you are relying on the order of tags in an XML and/or .config file... "ur doin' it wrong".
You put documentation in your config file? Thats an extremely odd place for
documentation seeing as the .config files are NOT meant to be edited manually by
end users. They are meant to be edited by people who know what the settings are
(i.e. developers, etc).
No idea what kind of "end users" you have but my end users are Operations and Support personnel. And they are specifically the people that need to edit the configuration values.
Also no idea how you release software but busienss needs often drive new feature releases along, of course with bug fixes. And those can all require configuration values. So changes happen frequently.
Also although it might be nice to have a formal operations manual actually producing that seems to be a problem at most places I work at. And configuration files that have more than just a couple entries require documentation. Which either means putting it in the configuration file or putting it in another file. If it is put in another file then Operations/Support must be told about it. Repeatedly.
And of course to create a actual operations manual means that I, and no one else, would need to produce the documentation in the first place. Far as I am concerned since I know Operations/Support will be looking to the file anyways the documentation that is in there is going to be the source for the formal document anyways.
Last time I checked, XML and .config files were unordered formats.
Both of those are entirely incorrect.
XML can be unordered or ordered.
And MS config files have some sections that require specific ordering.
But that doesn't have anything to do with what I am talking about...
If you are relying on the order of tags in an XML and/or .config file... "ur
doin' it wrong".
If if fact that had anything to do with delivering a configuration file then you would in fact be correct. But it doesn't.
The order however does matter when Operations/Support uses standard difference tools to compare configuration files. Such as what they might do when they need to install a new major version or point release and they want to insure production machines have the same values with a new configuration file and the old one.
No idea what kind of "end users" you have but my end users are Operations and
Support personnel. And they are specifically the people that need to edit the
Same kind. I've noticed they are often too retarded to manually edit config files, so I usually provide an easy to use GUI for them (or at the very least, send them a whole new config file they just replace the old one with). For applications that go out to end users, asking an end user to change a config file is asking for trouble. Your GUI should do all that.
I know where you're going next... web.configs, web services, etc. don't have GUIs. Well, for a production application, I usually have an admin app or admin portal that controls the system. Much better design.
Also, if you want a simple generic thing, you could do what I did. Have a simple property grid dialog that edits any config file generically and can pull in "documentation" either from an xml file or reflection.
XML can be unordered or ordered.
Entirely incorrect. The XML spec says specifically that attributes and siblings are unordered and can be returned in any order the parser wants. It just so happens that every parser returns siblings and attributes in document order, but that is NOT guaranteed. If you are relying on something that the XML spec says specifically is not guaranteed, I'd hate to be you when your ops team deploys "XML v17" which has some awesome performance optimization, but no longer returns in doc order and breaks all your stuff.
The proper way to do ordering in an XML file is by using a key.
I will admit however, that it's unlikely that a parser will start returning stuff in non document order, simply because some apps rely on that incorrectly.
The order however does matter when Operations/Support uses standard
difference tools to compare configuration files. Such as what they might do
when they need to install a new major version or point release and they want to
insure production machines have the same values with a new configuration file
and the old one.
What does this have to do with anything? .NET has this cool versioning thing that automagically updates your config files for you and adds in any missing attributes. Yes, I'll admit that the missing attributes may be added in a different order depending on code path (**UNLESS** you do it correctly -- in which case, the attributes will always be added in the same order).
Is that why you rolled your own .config file system? Simply so your ops team can run windiff on the files to make sure they are identical?
Seems like a proper implementation of upgrading the config files would be a better solution then re-inventing everything and having a non standard API, but thats just me.
See the first example which says "which must contain the following five elements in order"
which has some awesome performance optimization,
Yes the high volume tps servers that I have been delivering for the past 15 years do have measured and proven production performance abilities.
The proper way to do ordering in an XML file is by using a key.
The proper way is to understand more about what "XML" means.
What does this have to do with anything?
What it has to do with is documentation. Please read what I said. Trivial applications might have config values that are understood without documentation but more complex apps require substantial documentation so someone besides the original developer has any chance of understanding what the values mean, how they should be set, what the relationship between different values, etc.
...and having a non standard API, but thats just me.
Yes it is you, because I didn't say anything like that.
I don't know that the file should be stored in the user's documents directory, it doesn't sound like the right place.
I think a better place is APPDATA (APPDATA=C:\Users\Xxxxx\AppData\Roaming), then you can refer to it as @"%APPDATA%\dbs\latefee.sdf" and then use System.Environment.ExpandEnvironmentVariables before opening it.
Thank you all for dropping all this knowledge on me. It's been a while since I have done any coding, and I am not a programmer by trade. I am in IT for the company I work for, doing mostly tech work (very small business). I write small desktop apps for reporting from our POS system and use C# as I understood it most with VS 2003 (.net 1.1).
As I saw a need to update from XP to Win 7, I am trying to rewrite these programs with .net 4, so I am just now, as a few days ago, trying to learn the new IDE in VS 2010, the new classes and deprecated classes, etc, etc.
Thank you for your understanding and patience. Trying to google and study everything while taking calls all day for every problem from 'the internet is down' to 'this document is not printing correctly' is quite a task.
hi to all
i have a simple question please tell me,how can i close all methods by shortcut key and collapse all again.yes this is a basic question but i need it and i cant find this shortcut .thanks for help
I am new to DirectX and I am stuck in one basic scenario. So my requirement is -
I am having C# Windows Form. Now on top of that form I have to Slide one Image on top of another Image. Both Images are passed to my this translating class.
I used the concept of Sprite after going through the online Samples. But the problem is when the Sprite is moving the background is set to the color which is provided in the Device.Clear() method. I didn't find any way by which I can overcome this. There is no way to set the background image of the Device too.
I also tried using the concept of Microsoft.DirectX.DirectDraw.Surface too. PFB the code which I tried -
// Code Snippet Begin
SurfaceDescription description = new SurfaceDescription();
In fact, the Serial port can (and will, and does) send anything just fine.
The moment the external box starts sending us data, this method apparently stops and goes into an eternal loop on the last line.
Stopping the app in debug produces not a yellow arrow on the instruction (i.e., the last one in this method) but a green one instead.
Hovering over that green arrow produces this message..
"This is the next statement to execute when this thread returns from the current function"
I do not understand what thread the debugger has in mind, because I didn't start a thread. The only thing I can think of that even strikes the thought of the word "thread" in my mind is the background event handler that is doing the receive.
Just for good measure, I've set some breakpoints in the event handler that responds to bytes received on that same serial port, and it is properly receiving the bytes from the external box.
In fact, that's how we determined that conflict that was causing this. (We made the external box go silent; never sending any data, so this app can send without any response back.)
If it makes any difference, the send method and the receive method are in different classes.