|
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);
|
|
|
|
|
As this is a 3rd party control, you are more likely to get help if you ask on their web site. Here[^].
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
Why do programmers often confuse Halloween and Christmas? - Because 31 Oct = 25 Dec.
Business Myths of the Geek #4 'What you think matters.'
|
|
|
|
|
Hello,
I'm using C# in Visual Studio 2008. Is it possible to trap the F1 key in a file dialog (Open or 'Save As')? I've been searching on the internet for the answer to this but I've found none. Any help is appreciated.
Regards,
Mike
|
|
|
|
|
Although I have never done this, my first thought is GetActiveWindow + Global keyboard hook.
|
|
|
|
|
d@nish,
I'm not sure about the GetActiveWindow, but I found a global keyboard hook program. Everything appears to be working now. Thank you for your help.
Regards,
Mike
|
|
|
|