|
Hello,
How can I measure the time that controls are being painted on a panel ?
Thanks,
berlus
|
|
|
|
|
If I understand you correctly you have a Form, a Panel on that Form, and some Controls on the Panel. The Controls get painted whenever there is a need to, and you would like to measure how long it takes to paint them. Correct?
I could explain how to get the measurement done (or what to change so it can be done), however I'd rather tell you that you asking this tells me (1) it is slow, and (2) you should fix that.
Event handlers, including the Paint handler, should execute in a snap, never keeping the GUI thread busy (or waiting) for more than say 20 milliseconds, otherwise the GUI experience would be bad (e.g. a window covering most of your form, then disappearing, would take too long for everything to settle; or you dragging the Form by its title would not follow your mouse smoothly).
I suggest you tell more about your current situation: which controls, showing what kind of data (and where it comes from), etc. Plus a detailed symptom description.
|
|
|
|
|
Thanks for your answer.
I'm developing a GDI+ (can't use direct draw or open GL) framework, and i'm trying to decide between two alternatives to draw a certain symbol.
In order to decide which method to use, i'm creating a PanelWithStopwatch (derived from Panel), and drawing on this panel the desired symbol.
I want to use the stopwathc to measure the time that each panel was painted.
I hope I have clarified the need for the performance test.
Thanks,
Berlus
|
|
|
|
|
I understood you had Controls on the Panel, now you say it is a symbol, so I'm still confused. If there are no listing controls involved (ListBox, TreeView, DataGridView) and no databases, I doubt it will take more than say one millisecond (unless you are messing with huge images, transparency, ...).
Anyway, you could implement one way of painting things, then have a button click handler that contains:
start stopwatch
for (onethousand times) Panel.Refresh
stop stopwatch
This should repaint your panel all the time, whatever it contains. And then you could repeat it with your alternative way of painting things.
When in doubt it really repaints every time, change it a bit, e.g. perform a TranslateTransform.
|
|
|
|
|
Thanks,
By symbol I mean a GDI+ drawings (such as pen, circle, etc).
Do you have any suggestions on how to implement a panel with a textbox, that upon invalidation and repainting, that text box will be updated with the amount of time it took the panel to repaint itself ?
Thanks,
Berlus
|
|
|
|
|
Hi,
you need to be more accurate when explaining things; you first said Control, then symbol, now drawing; and a pen is not a drawing.
I explained how to do it.
Here is working code:
public void RunTimingTest() {
Form f=new Form();
Button btn=new Button();
btn.Text="Start";
btn.Click+=new EventHandler(btn_Click);
btn.Bounds=new Rectangle(20, 20, 200, 40);
f.Controls.Add(btn);
lbl=new System.Windows.Forms.Label();
lbl.Bounds=new Rectangle(20, 80, 400, 30);
f.Controls.Add(lbl);
p=new MyPanel();
p.Bounds=new Rectangle(20, 150, 200, 100);
p.BackColor=Color.Yellow;
f.Controls.Add(p);
f.Show();
}
void btn_Click(object sender, EventArgs e) {
p.Count=0;
lbl.Text="";
Stopwatch sw=new Stopwatch();
sw.Start();
int n=100*r.Next(1, 10);
for (int i=0; i<n; i++) {
p.Text="MyPanel "+i.ToString();
p.Refresh();
}
sw.Stop();
lbl.Text="Did "+p.Count+" paints in "+sw.ElapsedMilliseconds+" msec";
}
public class MyPanel : Panel {
public int Count;
public string Text;
protected override void OnPaint(PaintEventArgs e) {
Count++;
base.OnPaint(e);
e.Graphics.DrawString(Text, Font, Brushes.Black, new Point(20, 20));
}
}
The spoon feeding ends here.
|
|
|
|
|
Thanks for your answer,
I will try to explaing myself better next time.
I hope I won't vommit from your spoon , ....
Thanks,
Berlus
|
|
|
|
|
Did you solve your problem? What is the outcome?
|
|
|
|
|
Hi,
How can I find all the positions of the word hello in string s1?
Note that I do not want to use the built in pattern matching functionality such as:
String::split(), String::indexOf(), String::lastIndexOf(), String::substring(), Regex.Match(),
string s1 = "Hello how are you, hello how are you, hello how are you this morning"
string s2 = "Hello"
The above should return:
1, 20, 39
|
|
|
|
|
|
so write your own little method by walking the string and comparing individual characters.
Extra challenge: make sure you get it right when one or both strings stutter, as in: locating "cucumber" in "I don't like cucucumbers at all".
|
|
|
|
|
This is the C# forum, not C++. You should be asking this in the Managed C++/CLI forum instead.
|
|
|
|
|
Why sir, it is deserted; there is more people on Mount Everest than there is in the C++/CLI forum. And the problem can be solved in any language.
|
|
|
|
|
This is a c# questioin, and apologies I should have placed string.Indexof, etc.
Thanks
|
|
|
|
|
Why do you refuse to use the right tools for the job? If you want to drive a nail, use a hammer. If you want to hit a baseball, use a bat.
Arbitrary restrictions on allowed methods or libraries without explanation smells like "do my homework for me".
But in case it isn't your homework, convert both strings to char arrays. Loop through array 1 until the letter matches the letter in array 2. Increment both indexes and compare, if they match continue incrementing, else reset index on array 2.
|
|
|
|
|
Hello,
string s1 = "Hello how are you, hello how are you, hello how are you this morning"
string s2 = "Hello"
This is what I have now but do not know how to compare one string to the other to see if they match. Can you help please?
Thanks
char[] chars1 = strs1.ToCharArray();
char[] chars2 = strs2.ToCharArray();
for (int i = 0; i < chars1.Length; i++)
{
char letter = chars1[i];
}
|
|
|
|
|
Assume chars2 holds N letters, and chars1 holds at least N.
Now try some index i and check that for all values j in [0,N-1] chars1[i+j] equals chars2[j]; if so, you have a match at position i.
Hence, two nested for loops would be sufficient; it may not be the most efficient way, it is an effective one.
|
|
|
|
|
|
Right. Of course.
But actually, there is no need to explicitly create the char arrays, as a string is perfectly indexable as is: string[i] returns the i-th character all by itself (as it did in C).
|
|
|
|
|
Hi All,
I'm recieving a System.IO.Exception after creating a file and then trying to append text to that file. The message I recieve is:
The process cannot access the file 'File path goes here' because it is being used by another process.
The code to create the file is:
if (!File.Exists(filePath))
File.Create(filePath);
The code I'm using to try and append text to the file is:
StreamWriter sw = File.AppendText(readIDFilePath);
Does any one have any clue to why I am recieving this exception? Does File.Create open the file it's creating?
Is the file already exists then no System.IO.Exception is recieved.
Any feedback would be greatly appreciated.
Thanks,
Mel
|
|
|
|
|
According to the documentation[^], File.Create returns a FileStream that provides read/write access to the file specified in path.
So in answer to your question, yes File.Create does open the file.
Use the returned FileStream to write your data, or call dispose on the filestream before using AppendText.
|
|
|
|
|
Thanks for your feedback, I captured the FileStream that File.Create returns and close/disposed it as you suggested and it works great.
I guess I was just looking at it for too long and over looked the obvious.
Thanks again.
Mel
|
|
|
|
|
You should be able to figure this one out yourself, mainly by reading the documentation on the classes and methods you use.
I would agree with you if you were to say the error message you are getting isn't perfect; when it says "... by another process" that may include your very own process too, so "another process" should really be "some (maybe this) process".
|
|
|
|
|
this file may be opened last time and not be closed.
|
|
|
|
|
right now I have one column header that does not alphabetically sort its self when column header is clicked.
so I figured I can make an event if that column header is clicked to a column header that sorts the it how I need to
Column header Im targeting is gridView.columnFlags
so far I have
private void OnColumnHeaderClick(object sender, Divelements.SandGrid.GridColumnEventArgs e)
{
if (e.GridColumn.Equals(columnTest))
{
}
gms.HandleSort(e.GridColumn);
|
|
|
|
|