|
The only guidelines I can suggest are:
1) How many times a second are you going to repaint your form? If your writting an analog clock that repaints itself every 50 milliseconds, you'll want to create your pens and brushes once and cache them so you're not creating and destroying them a couple hundreds times per second. If you only repaint the form when Windows tell you to, then you could probably get away with creating and destorying your pens and stuff on demand.
2) If you're painting alot of static stuff. In the clock example, the clock face and hands don't change between any repaints. Just the positions of certain items change. In this case you could get away with caching your drawing objects. If you're painting dynamic data that frequently changes the colors of what your drawing between repaints, then you'll have to create and destroy your drawing objects on demand.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Thanks Dave,
Those are some good examples of when caching might be useful.
|
|
|
|
|
Hello everyone,
I am working on a data acquisition project. Every 1/5 second I read data from a device. It's delivered in a two dimesional array. I want to put samples in a file every 2 seconds. Is there a way to add a twodimensional to another twodimensional array?
I did only find the CopyTo, but it only supports onedimensional arrays.
Software: Visual Studio 2003 C#
Thanks in advance,
Souza
|
|
|
|
|
Is it a 2D array or a jagged array ? If a jagged array, I think you add them one single dimensions array at a time.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Hello Christian,
You are right about the jagged array. But I get the smples in a 2d array. And there is nothing there can be changed about that. Thanks for your post anyway.
Souza
|
|
|
|
|
How to get acces to each element of the array, which is a member of the class, on which we are using reflection?
|
|
|
|
|
so in example:
Class Test
{
public int[,] a = new int[4,4];
void fun()
{
Type ClassType = typeof(Test);
FieldInfo[] Values = ClassType.GetFields();
foreach(FieldInfo val in Values)
{
???
}
}
}
|
|
|
|
|
|
I have to make a de/serialization similar to XML, but my own
Nevertheless, there is one more problem. During reflection I may have some different arrays of different types (not only int32, but also double, char, etc).
That`s why i cannot declare
int[,] reflecteda = aField.GetValue(this) as int[,];
The information about type of the array is hidden in aField.FieldType which gives eg. "System.Int32[,]". How to declare the needed array, which type is hiden there?
tnx in advance
|
|
|
|
|
Dear All,
I am trying to call a function from an Intel dll that's originally written in C/C++.
It's original prototype is :
HIGHGUI_API IplImage* cvvLoadImage( const char* filename );
I have marshalled it as :
[DllImport("highgui.dll")]
[return : MarshalAs(UnmanagedType.Struct)]
unsafe public static extern IplImage * cvvLoadImage(string filename);
when I try to run it ,I get the following error.Does anyone know how can I fix that?
Error: Cannot take the address or size of a variable of a managed type ('IplImage')
I have marshaled the originally struct IplImage into :
[StructLayout(LayoutKind.Sequential)]
unsafe public struct IplImage
{
....
};
Best Regards,
E.A.
|
|
|
|
|
i'm working in aproject doing something loke massenger of msn and i wanna form popup to the user when another message to the user
i do the code put the form show in normal way i wanna it
appear sequencly
|
|
|
|
|
Hello,
I have a dataset, and I want to sum up the values from certain column to a certain column (for example, rom comumn 3 to column 7).
So, is there a way of getting the index of the column?
Sort of row[0][column].Index, or something like that?
Thank you
|
|
|
|
|
You could do something of the following....
int[] cols = {2,3,5};
int total = 0;
for(int x=0;x<=cols.length -1;x++)
total += row[0][cols[x]];
above code is untested!
|
|
|
|
|
//this is for each row
foreach ( DataRow row in this.dataTable1.Rows )
{
int sum = Convert.ToInt32(row[3]) + Convert.ToInt32(row[7]);
}
//if you know the row index then use this
int sum = this.dataTable1.Rows[1][3] + this.dataTable1.Rows[1][7];
|
|
|
|
|
Try it with this function:
dataset.Tables["TableName"].Columns.IndexOf("ColumnName");
|
|
|
|
|
Hi Please let me know how to open uneditable word document in windows form C#.net.
It just like preview of document in windows form.
Thanks
|
|
|
|
|
If the file extensio is rtf open it in richtextbox if doc i don not know
but you can use Word object in your.net application
MCAD
|
|
|
|
|
Dear all
i do programming in a desktop application that puts html file on the desktop as a background and rearrange desktop icons and adjust the list view of the desktop and others...
after searching the internet , i found that the only way is to use the IActiveDesktop interface.
so my question is how to implement IActiveDesktop interface in C#?
thx all
|
|
|
|
|
|
I need a way of creating a table insinde an Access database if that's possible using a command or some equal structure ?? Does anybody know how to achieve this ? Or into an MySQL database ?
Lazar Mihai
|
|
|
|
|
Check out the "create table" command in SQL.
---
b { font-weight: normal; }
|
|
|
|
|
I wish to know why OpenFile and SaveFile dialogs change the current directory.
And if there si a way to prevent this, or shoud I use the following methond : Directory.SetCurrentDirectory( path );
This is what I curently use, and wanted to know if there is some other way.
Lazar Mihai
|
|
|
|
|
That's how they are expected to behave. Instead of using CurrentDirectory, you can try using System.AppDomain.CurrentDomain.ApplicationDirectory or something similar.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Your code really shouldn't be depending on the current directory anyway. The general rule-of-thumb in programming is assume nothing!. What this means is you never assume that the file you want to access is in the current directory. Always use fully qualified path names and not just a filename when doing any kind of file access.
This also has other benefits. Say you put up a OpenFileDialog that changed the current directory. After the user picks a file, you try and put the current directory back to what it was. But, your code crashes, for whatever reason, before that can happen! The function ends up returning as failed, but not having restored the current directory. Now what? Your next file access is assuming (there's that word again ) the current directory is correct when it's not, and your app ends up crashing a second time, then a third, forth, fifth, ...
Write your code so it defends itself against itself. Never assume anything is what you expect it to be.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-- modified at 16:07 Monday 12th September, 2005
|
|
|
|
|
Use this:
<br />
System.Windows.Forms.OpenFileDialog dlgOpenFile = new System.Windows.Forms.OpenFileDialog();<br />
...<br />
dlgOpenFile.RestoreDirectory = true;<br />
DialogResult res = dlgOpenFile.ShowDialog();<br />
But listen to dave's answer, he is totaly right about assuming paths.
|
|
|
|