|
How are you accessing the image data? What do you use for screen capture?
xacc.ide - now with TabsToSpaces support IronScheme - 1.0 beta 1 - coming soon ((lambda (x) `((lambda (x) ,x) ',x)) '`((lambda (x) ,x) ',x))
|
|
|
|
|
leppie wrote: How are you accessing the image data? What do you use for screen capture?
Hi leppie, I'm using the Graphics class to get the screenshot (only 3 lines of code). Accessing the image data is very slow using safe code (GetPixel) so I'm using unsafe to access the memory.
|
|
|
|
|
|
Hey guys
I'm just wrote a simple struct to contain an int and two boolean values. Its is as follows..
struct NodeModuleLevelStruct
{
public NodeModuleLevelStruct(int ModuleID, bool IsActive, bool IsAdvanced)
{
moduleID = ModuleID;
moduleActive = IsActive;
level = IsAdvanced;
}
private bool moduleActive;
public bool IsActive
{
get { return moduleActive; }
set { moduleActive = value; }
}
private bool level;
public bool IsAdvanced
{
get { return level; }
set { level = value; }
}
private int moduleID;
public int ModuleID
{
get { return moduleID; }
set { moduleID = value; }
}
}
Now i need to query a NodeModuleLevelStruct[] using Linq so i have to inherit IEnumerable right?
so ive got
struct NodeModuleLevelStruct : IEnumerable<int>
...int cause i want to check if the given moduleID exists within that array
now the compiler is moaning that i havnt implemented System.Collections.Generic.IEnumerable<int>.GetEnumerator() or System.Collections.IEnumerable.GetEnumerator()
1) Am I on the right track here?
2) How do i implement those interfaces in my struct?
Thanks
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
you.suck = (you.Passion != Programming & you.Occupation == jobTitles.Programmer)
1000100 1101111 1100101 1110011 100000 1110100 1101000 1101001 1110011 100000 1101101 1100101 1100001 1101110 100000 1101001 1101101 100000 1100001 100000 1100111 1100101 1100101 1101011 111111
|
|
|
|
|
Harvey Saayman wrote: Am I on the right track here?
No, you are doing it wrong
NodeModuleLevelStruct[] is already IEnumerable<NodeModuleLevelStruct> . So all you need to do is:
NodeModuleLevelStruct[] l = ...;
var q = from x in l
where x.ModuleID == 12345
select x;
Also, you should not use a struct in this case AFAICS.
xacc.ide - now with TabsToSpaces support IronScheme - 1.0 beta 1 - coming soon ((lambda (x) `((lambda (x) ,x) ',x)) '`((lambda (x) ,x) ',x))
|
|
|
|
|
leppie wrote: NodeModuleLevelStruct[] is already IEnumerable<nodemodulelevelstruct>
ah, i didnt know that... it works by just querying the NodeModuleLevelStruct[]
leppie wrote: Also, you should not use a struct in this case AFAICS.
what do u think i should use? And when should one use a struct anyway?
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
you.suck = (you.Passion != Programming & you.Occupation == jobTitles.Programmer)
1000100 1101111 1100101 1110011 100000 1110100 1101000 1101001 1110011 100000 1101101 1100101 1100001 1101110 100000 1101001 1101101 100000 1100001 100000 1100111 1100101 1100101 1101011 111111
|
|
|
|
|
Harvey Saayman wrote: what do u think i should use?
A class. Structs are mostly useless in .NET unless you require their special semantics. Example:
MyType[] list = new MyType[10];
Now define MyType as a class and see what the content is in 'list'. Now do the same but define MyType as struct.
An important point to notice is the way 'instances' are passed around. With structs, a copy of the value of the instance will be made, where classes will just send a reference to itself. So if used wrong, structs can become a big performance/memory killer. There are also other considerations, like modifying structs and things to keep in mind like boxing, that just blurs everything!
xacc.ide - now with TabsToSpaces support IronScheme - 1.0 beta 1 - coming soon ((lambda (x) `((lambda (x) ,x) ',x)) '`((lambda (x) ,x) ',x))
|
|
|
|
|
thanks leppie
as always you rock
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
you.suck = (you.Passion != Programming & you.Occupation == jobTitles.Programmer)
1000100 1101111 1100101 1110011 100000 1110100 1101000 1101001 1110011 100000 1101101 1100101 1100001 1101110 100000 1101001 1101101 100000 1100001 100000 1100111 1100101 1100101 1101011 111111
|
|
|
|
|
I slightly disagree with Leppie on this one.
I've seen it written many times that classes are easier to deal with and everyone says use them in C#.
If your example is really as simple as you've posted then seeing as each NodeModuleLevelStruct is going to be very small and is only using value types for properties/fields I'd be tempted to keep it as a struct. Small basic structs are easy to deal with, and if you want it to act like a reference type in a method you can always use the ref keyword. I find using structs very useful as I can be sure (so long as I've coded them properly) that my original instance is unchanged and if I want to change it, I can use ref or assign a copy's values to it.
It depends on how big it is, what it contains, and how you plan on using it.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
DaveyM69 wrote: I slightly disagree with Leppie on this one.
What disagreement? Ok, it's ever so slight.
I think a good rule of thumb is to use structs only for small immutable types (the OP's is mutable, and hence can fall into the 'modification' trap).
xacc.ide - now with TabsToSpaces support IronScheme - 1.0 beta 1 - coming soon ((lambda (x) `((lambda (x) ,x) ',x)) '`((lambda (x) ,x) ',x))
|
|
|
|
|
leppie wrote: ever so slight
It's a good rule of thumb but one that can be ignored (carefuly) if the structure is only using integral types (as in the OP's) or other structs that only contain integral types. Take the Size struct as an example. It's not immutable, but a struct makes perfect sense and using it within your own struct would be good too.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
DaveyM69 wrote: Take the Size struct as an example. It's not immutable, but a struct makes perfect sense and using it within your own struct would be good too.
The Size struct is not a very good example, just because it's mutable.
If you need a type that is mutable, you should use a class, not a struct. It's so easy to accidentally change a copy of the struct instead of the struct.
As I am sure that you know, to safely change a property in a struct in an array you would have to:
NodeModuleLevelStruct temp;<br />
temp = theArray[42];<br />
temp.IsActive = true;<br />
theArray[42] = temp;
With a class, you can just do:
theArray[42].IsActive = true
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Yeah - and that's exactly why I like to use them - only when appropriate of course.
I can work on the copy, make any changes I like and then just forget the whole thing if I don't want/need to commit them. If it's a class, to have that flexibility you have to implement some sort of cloning method and work on the clone, then you still have to remember to reassign.
I know where you're coming from, and agree to a point, but the blanket statement that if it's mutatble you should use a class, whilst it may prevent errors, isn't strictly true IMHO.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
DaveyM69 wrote: I can work on the copy, make any changes I like and then just forget the whole thing if I don't want/need to commit them. If it's a class, to have that flexibility you have to implement some sort of cloning method and work on the clone, then you still have to remember to reassign.
I see your point, and that would work as long as it's only you who work with the code. If someone else has to take over your code, they can easily be fooled by this uncommon usage of structs.
A struct is a value type, and the semantics of a value type is to represent a single value of some kind. If you have several distinct values in a struct it doesn't behave as a value type any more, and you should use a class instead.
Also, a struct should not be larger than 16 bytes. A small struct can be copied using only a pair of machine instruction, while a large struct requires a loop to copy the memory area each time.
It's easier to use a struct for cloning instead of implementing proper cloning for a class, but you get worse performance.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Guffa wrote: a large struct requires a loop to copy the memory area each time.
It's easier to use a struct for cloning instead of implementing proper cloning for a class, but you get worse performance.
I've read alot on this, especially today, and those two points I didn't come accross anywhere! Valid and noted.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
I have all my data in MySQL as char data type in "en" locale.
That means all int and float and double type data are stored
as char data without thousand separator, but float and double data have
ofcourse with decimal (.) separator.
My question is : How can I display those data according to program's locale
setting. Since the data already in char type I could not find out a smouth
way to display the data returned from database accordingly. My program can change
the locale settings at run time according to user request.
By the way I use DataGridView for the display control on my win form.
Thanks,
Muharrem
|
|
|
|
|
Use one of the TryParse overloads for the data type that you need to display.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
hi
i have a code that does not response
dataGridview1.DataSource = dataset1;
i`m sore that dataset is fill
and when i use following code dbgrid creates as same record number as exist
in dataset but the value of rows in dbgrid are empty
dataGridview1.DataSource = dataset1.Tables[0];
|
|
|
|
|
Hi,
try to use the datagridview1.DataBind() method to finally bind the dataset to the datagridview.
Regards
Sebastian
|
|
|
|
|
Hi,
That´s not working? error not there
reza assar wrote: dataGridview1.DataSource = dataset1.Tables[0];
Datatable as to be empty! if you have only 1 databable in the dataset, just create the table. Bellow i didn´t create a dataset.
Change the routine code to fit your demands.
public static void DataGridView_Fill(DataGridView dgv, string store_procedure)
{
SqlConnection sql_conn = new SqlConnection(connection_string);
SqlCommand sql_cmd = new SqlCommand();
sql_cmd.Connection = sql_conn;
sql_cmd.CommandText = store_procedure;
sql_cmd.CommandType = CommandType.StoredProcedure;
sql_conn.Open();
SqlDataAdapter sql_da = new SqlDataAdapter();
sql_da.SelectCommand = sql_cmd;
DataTable dt = new DataTable();
sql_da.Fill(dt);
sql_conn.Close();
dgv.DataSource = dt;
}
nelsonpaixao@yahoo.com.br
trying to help & get help
|
|
|
|
|
hi
what can i do to have a shortcut for click event of a LinkLabel
|
|
|
|
|
Shortcut to what?
Web page / program etc... use System.Diagnostics.Process.Start method.
[Edit]The tag property of the linklabel can be a useful place to store your URL or path etc... you'll have to cast back to string to retrieve the data.[/Edit]
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
Im generating a Pdf of a table that contains about 200 000 records, each containig a differen image file too. so my pdf has to draw 200 000 little images, i get out of memory erro or GDI+ error after a while. The code does work for less records (checked on 100 - 1000). the code also works if I delete the image = new PdfBitmap("path for a different image for every cell of the table"); line and draw the same image in every row.
Please any suggestions would be appreciated.
public PdfImage image = new PdfBitmap("l.jpg");
void table_EndCellLayout(object sender, EndCellLayoutEventArgs args)
{
int cellIndex = args.CellIndex;
if ((cellIndex == 5) )
{
PdfGraphics g = args.Graphics;
try
{
image = new PdfBitmap("path for a different image for every cell of the table");
RectangleF bounds = args.Bounds;
PointF point1 = bounds.Location;
//obliczanie srodkowego punku komorki
g.DrawImage(image,point1.X, point1.Y, 30, 30);
}
catch
{
}
}
}
|
|
|
|
|
You should be disposing of any 'new' disposable instances you create, ie PdfBitmap.
That said, I have never seen that class, and there could be other issues involved.
xacc.ide - now with TabsToSpaces support IronScheme - 1.0 beta 1 - coming soon ((lambda (x) `((lambda (x) ,x) ',x)) '`((lambda (x) ,x) ',x))
|
|
|
|
|
I have tried that but maybe Im not doing it right
I cant do image.dispose(). tried
image=null;
and then calling garbage collector..
Im a begginer c# programmer, pls could u write the ideas u have in code?
|
|
|
|