|
Thank you for your reply, I did what you said and I get this :
The type or namespace name 'Image' does not exist in the namespace 'System.Drawing' (are you missing an assembly reference?)
Thanks.
|
|
|
|
|
Do you reference System.Drawing.dll in your project?
--
"My software never has bugs. It just develops random features."
|
|
|
|
|
I'm sorry if I am wrong, but I would rather do this as follows. I guess this is a better way of loading the file dynamically
Uri filename1 = new Uri(@"C:\images\mainicon.jpg");
image1.Source = new BitmapImage(filename1);
Is this something helpful?
|
|
|
|
|
i have two forms, in one form i have three textboxes
and in another form i have one datagrid view control,
i want that the data i entered in textboxes will shown in datagridview control after i click on add button all the records will store in it may it is n number of record all n number of record will be shown in datagridview control but without creating database..
Is there any mechanism how to do this..????
|
|
|
|
|
This is so simple to do.
Create a class which contains 3 properties for all three text boxes.
Say for example here is the sample code
public class Form1Class
{
public string TextBox1Value { get; set; }
public string TextBox2Value { get; set; }
public string TextBox3Value { get; set; }
}
Now say for example you have a button named Button1 and on the click even, you need to open Form2 and bind the textbox values to datagridview.
For this, first you have to create an object of Form1Class which will take these three textbox values into my object (here it is Form1Class). Once you created an object, you need to pass the object to Form2
Here, you have to think about data passing mechanism from one form to another form (Form1 to Form2).
There are many methods that we can pass data from one form to another.
1. You can use sessions, querystring etc...
For detailed view of how to pass data from one form to another form in asp.net , have a look at below links
MSDN article
or this article also gives you an idea
Null Skull link
Once you pass the data from From1 to Form2 and the receiver side (i.e Form2) you need to receive the data and bind it to the datagridview.
As you are passing a single object from Form1 to Form2 and you need to see how to bind an object to datagridivew.
here is the stackoverflow answer on how to bind an object or a list of object(s) to a datagridview.
Stack Overflow answer
Once you are bind the data to a datagrid view, you can able to see the data that you enter in textbox(es) in Form1.
Try this and let us know, if it is working or else facing any issues.
Happy coding
Regards,
Ganesh
|
|
|
|
|
In this case what you can do is create a custom data table in the form, having three columns as the three text box,
Once you have this structure in place you can create a data row and append it to the table and set the datatable as the data source of the gridview.
let me know if you have any question.
|
|
|
|
|
I have a random class (determined at runtime)... this class constructor may or may not have parameters (determined via a lookup table). I need to new up said class as fast as humanly possible. So I went with expression trees. Since I don't know how many parameters the constructor will have (until I'm building the expression tree), my concept is to get the parameters into an object[] and then type cast o[0], o[1], o[2], etc. to the proper types. The expression comes out as:
.Lambda #Lambda1<System.Func`2[System.Object[],System.Object]>(System.Object[] $var1) {
.New ConsoleApplication1.Test(
(System.String)$var1[0],
(System.Int32)$var1[1],
(System.Drawing.Color)$var1[2])
}
So I'm getting a Func<object[], object>... seems kind of slow (relatively) to be honest... is compiling it to a lambda causing overhead? or is there some other overhead I'm not seeing? Since the params can be any type, I don't know how I could store them in anything else other then an object[]. Seems like I might be generating a method vs. doing it inline?
Any ideas? This code is called *a lot*, so every ms counts .
|
|
|
|
|
Are you creating the expression tree every time you need a new instance of one of the classes, or are you caching the compiled Func<object[], object> for each class type?
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I'm caching the Func<object[], object>'s in a dictionary. Just seems slower then doing a normal new up for the same # of iterations and I was under the impression its supposed to be just about the same performance. I realize my code has other overhead, of course, but still...
|
|
|
|
|
Seems like it might have something to do with the parameters. Right now the constructor for the test class is:
public Test(string str, int i, Color color)
{
}
and new'ing up 1M takes 475ms with my current code. By doing NOTHING but changing the constructor to just:
public Test(/*string str, int i, Color color*/)
{
}
it drops to 200ms. So I tried adding 1 param back and it jumps to 312ms. 2 params = 390ms.
So... every additional param is adding quite a bit of time .
Now, adding back the first param was +112ms, but the 2nd one was only an additional +78ms. I would expect adding back the first param would be expensive since it would now travel down the param code path where without params it skips all that. However, I expected adding the 2nd param would be much cheaper since its just adding another iteration to the param loop.
A standard new up with all 3 params for 1M iterations takes only 31ms.
I'm estimating that there is about 140ms of overhead built into my dynamic new up code, I'm just not getting why adding params is so expensive. So I tried one more test...
for (int i = 0; i < 1000000; i++)
{
int j = 5;
string s = "hello";
Color cr = Color.Red;
// 0ms
//int k = j;
// 15ms
//object k1 = j;
// 0ms
//object k2 = s;
// 46ms!!
object k3 = cr;
}
Seems like the boxing & type casting of the int and color is killing the performance. Boxing a string seems to be pretty cheap. The int and color are structs though...
|
|
|
|
|
Boxing and unboxing is notoriously "slow" - although that's a relative term; it's still significantly faster that accessing the disk.
Without knowing the precise details of how you're creating and calling the delegates, it's hard to see whether there's a better alternative.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
The requirements are to create objects on the fly with any number of constructor arguments. Almost like DI, but with a different spin. The only way I thought of being able to do that is to create an object[] as an input parameter and pass the arguments to the constructor as array[0], array[1], array[2] and type casting to the proper type (from ConstructorInfo and ParameterInfo). Hmm... I added support for making constructor params byref, but that didn't help. Also doesn't seem to make a big performance diff if I pass in classes.
|
|
|
|
|
SledgeHammer01 wrote: I need to new up said class as fast as humanly possible. Do you have any control over how the class/constructor looks? If yes, you could use a delegate as shown here[^].
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Eddy Vluggen wrote: Do you have any control over how the class/constructor looks? If yes, you could
use a delegate as shown here[^].
Nope. It can be any class.
|
|
|
|
|
Hello all,
Lets say I have a solution (A) or a project (A) which is working properly and its framework is 2.0.
And I have a seperate empty project(B) which is I set its framework to 3.5. When I add my working project(A) to that blank solution what will be my working project's solution? Is it going to be updated to 3.5 automatically from 2.0 to 3.5?
If not, changing project (B)'s(-where project (A) is already been added to project (B) ) framework manually from the solution's property window to 4.0 also changes project (A)'s framework as well(will .Net automatically change that project framework)?
Thanks in advance
|
|
|
|
|
Target framework is a project property and not solution property. It's possible that a solution has different projects with different target framework.
If you have a working project with specific framework and you do not mean to change/extend functionality - do not change target framework...
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)
|
|
|
|
|
I am using .net framework wcf client and server . The signature of the WCF service interface is simple:
ResponseMessage SendMessage(RequestMessage message)
I create a new type that inherits from "ResponseMessage". This type holds 1 property:
public class TestResponseMessage : ResponseMessage
{
public List<ISomeInterface> Members { get; set; }
}
According to:
http:
http:
It is said that "Members" property should be able to serialize without the need of the [DataContract] on the class and [DataMember] on the property, but it doesn't work - if I don't use it, I get null in the TestResponse.
The reason for asking this is that we've encountered a very strange behavior in our product - sometimes this serialization works and sometimes it doesn't, and it seems to behave differently with same client/server versions on different machines.
Any insights about this will be very welcome.
modified 3-Sep-14 12:07pm.
|
|
|
|
|
I think certain kinds of "advice" without reference to the actual documentation is worthless (as in this case).
If one consults the actual documentation (help) re: "Data Contracts" it notes that:
"All .NET Framework primitive types, such as integers and strings, as well as certain types treated as primitives, such as DateTime and XmlElement, can be serialized with no other preparation and are considered as having default data contracts."
and
"New complex types that you create must have a data contract defined for them to be serializable."
I would say that your "Members" property is NOT a "primitive" type and therefore must have a "data contract".
(The SO example conveniently only shows primitive types).
|
|
|
|
|
Hi,
I am trying to view a photo blob from MySQL on a picture control using the following code:
byte[] rawData = new byte[0];
rawData = (byte[])sql_reader["photo"];
int len = new int();
len = rawData.GetUpperBound(0);
FileStream fs = new FileStream(photo_file, FileMode.OpenOrCreate, FileAccess.Write);
fs.Write(rawData, 0, len);
fs.Close();
curImage = Image.FromFile(photo_file);
pictureEmployee.Image = curImage;
but getting the following error:
Non-negative number required. Parameter name : count
Technology News @ www.JassimRahma.com
|
|
|
|
|
Jassim Rahma wrote: but getting the following error: On which line?
|
|
|
|
|
no line!
the error shows when I put it in a try-catch block
but If I remove the try-catch I don't get any error but I also don't get the image shown!
Technology News @ www.JassimRahma.com
|
|
|
|
|
You'll still get a line number in the stack track of the exception.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
nothing.
I also noticed the file was not properly created.
is the code ok?
Technology News @ www.JassimRahma.com
|
|
|
|
|
this is the code I am using to create the image and save it to the database:
byte[] employee_photo;
memory_stream = new MemoryStream();
pictureEmployee.Image.Save(memory_stream, System.Drawing.Imaging.ImageFormat.Png);
binary_reader = new BinaryReader(memory_stream);
employee_photo = binary_reader.ReadBytes((int)memory_stream.Length);
binary_reader.Close();
memory_stream.Close();
sql_command.Parameters.AddWithValue("param_photo", employee_photo).MySqlDbType = MySqlDbType.Blob;
Technology News @ www.JassimRahma.com
|
|
|
|
|
You haven't reset the position of the MemoryStream before you try to read it with the BinaryReader , so I suspect you're saving an empty byte array to the database.
Since you're using a MemoryStream , you don't need to worry about the BinaryReader - just use the ToArray method[^] instead:
using (var memoryStream = new MemoryStream())
{
pictureEmployee.Image.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Png);
byte[] employee_photo = memoryStream.ToArray();
sql_command.Parameters.AddWithValue("param_photo", employee_photo).MySqlDbType = MySqlDbType.Blob;
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|