|
You should override OnPaint yes, but you should also probably call base.OnPaint() inside it as well.
Anyways, if you have a loop, like
while(loop)
{
}
Its going to run the loop, then draw the 'final frame' as it where.
What you probably want to do (if your not already), is to change the position either in the OnPaint method itself, or in a timer (recommended).
My current favourite word is: Bacon!
-SK Genius
|
|
|
|
|
Why override OnPaint?
Just add it TO OnPaint!
For those who havn't seen my example, it's a yellow block that goes to wherever you click.
You can execute the EXE from INSIDE the .rar file!
Don't know what's so hard about that :p
It shows everything... Eeeevveeryytthing :p
(Including how to stop OnPaint refreshing flickering )
- Reelix
|
|
|
|
|
Since your probably doing all of the drawing to the screen yourself, you should probably use the override, using the event is kinda like this:
override OnPaint
{
Draw form
myPaint();
}
myPaint()
{
Draw over the form anyway
}
You could also override the OnPaintBackground (i think its called) to do nothing, thus reducing any wasted drawing further.
My current favourite word is: Bacon!
-SK Genius
|
|
|
|
|
First off, thanks to you both for the replies and the good news is that I think I have it sorted:
I inserted
Invalidate();
Update();
into the loop that updates the ball's position and it works (although a bit flickery even with Reelix's anti-flicker code but that's not really important).
As far as I can make out these two force the Form to redraw so I suppose that they trigger an OnPaint() event:
protected override void OnPaint(PaintEventArgs paintEvnt)
{
formPaint(paintEvnt);
}
which calls the Form's paint method
private void formPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
aBall.Paint(g);
aBall2.Paint(g);
}
which in turn calls the Ball's paint method:
public void Paint(Graphics g)
{
// System.Drawing.Graphics gx = new Graphics();
System.Drawing.Pen myPen;
myPen = new System.Drawing.Pen(System.Drawing.Color.Tomato);
g.DrawEllipse(myPen, this.XPos, this.YPos, 10, 10);
}
Any comments / corrections / better suggestions are welcomed
Thanks again,
Si
|
|
|
|
|
This code almost works. There is a problem with the compare constructor.
Something is wrong there because it shows everything as correct.
Any ideas?
public void ChkSp()
{
SortedList SL = new SortedList();
SortedList SL2 = new SortedList();
SL.Add(0, "Value1");
SL.Add(1, "Value2");
SL.Add(2, "Value3");
SL.Add(3, "Value4");
SL2.Add(0, richTextBox1.Text);
SL2.Add(1, richTextBox1.Text);
SL2.Add(2, richTextBox1.Text);
SL2.Add(3, richTextBox1.Text);
bool equal = Compare(SL, SL2);
if (equal)
{
richTextBox2.Text = "Correct!";
}
else
{
richTextBox2.Text = "They differ";
}
}
static bool Compare(SortedList SL, SortedList SL2)
{
if (SL.Count != SL2.Count)
{
return false;
}
foreach (DictionaryEntry item in SL)
{
if (!SL2.ContainsKey(item.Key))
{
return false;
}
}
return true;
}
|
|
|
|
|
Hi Dennycrane
You are checking a 'Key value(0 to 3)' only, not a value (Value1). Both collection contain same keys(0 to 4). So always return true.
You can check the values using "ContainsValue" method instead of 'ContainsKey'.
Ex:
if (!SL2.ContainsValue(item.Value))
{
return false;
}
Thanks,
Gopal.S
|
|
|
|
|
That just turns things around.
Now everything is different.
|
|
|
|
|
How do I retrieve an object from an ArrayList?
Can I do that??
Strange, I didnt get much on google!
|
|
|
|
|
ptr2void wrote: Strange, I didnt get much on google!
You clearly didn't try very hard then, two things:
1. Magic[^], looked at the first result, ooo look what do ya know? Some examples of referring to objects in ArrayLists.
2. Unless you're using Framework version 1.1, and using it for a specific reason, please use the generic List<type> instead, they're typesafe and just generally better for you.
He who makes a beast out of himself gets rid of the pain of being a man
|
|
|
|
|
I dont want to know only the types of objects..
Instead I want to use the methods of that type..
Say I have put a ColumnHeader type of object in the ArrayList..
How do I retreive that object and invoke its available methods??
|
|
|
|
|
This is just another reason why you should be using List instead of ArrayList. With List, it's type is known and you can refer to it's methods as you get the object from the list, but with ArrayList you would need to cast the object to the relevant type before being able to access any of it's available methods. In any case, the method for accessing the methods/properties of that object would be the same:
foreach(object myObject in myCollection)
{
myObject.someProperty = true;
myObject.someMethod();
}
He who makes a beast out of himself gets rid of the pain of being a man
|
|
|
|
|
|
hy everyone!
i do have a problem. My program uses general settings and file specific settings. therefore i will need to define sections for every type and the general one e.g. (key 1 etc. have to be replaced by their correct parametersettings, they are just representants for the keys to illustrate my problem!)
<general>
<key 1="">
<key 2="">
</key></key></general>
<doctype1>
<key d1_1="">
<key d1_2="">
</key></key></doctype1>
<doctype2>
<key d2_1="">
<key d2_2="">
</key></key></doctype2>
But i have no clue how to do this in the app.config. because visual studio doesn't allow self defined sections instead of appconfig, startup etc.
could someone provide me a sample of how to do this in the app.config?
thanks.
stephan.
|
|
|
|
|
Hello,
I have a question about converting generic lists. Why cant I use this code?
<br />
List<object> myListObject = new List<object>();<br />
List<string> myListString = new List<string>();<br />
<br />
myListObject = myListString;
</string></string></object></object>
Is there any way to converting these kinds of list?
Thank for reply
Marek
|
|
|
|
|
What's that last line for? This isn't HTML and the type given for a list isn't a tag.
You can't just take two collections of different types and force one of them to be converted.
You'd need to iterate over the List of strings and add them one by one.
He who makes a beast out of himself gets rid of the pain of being a man
modified on Tuesday, April 22, 2008 5:20 AM
|
|
|
|
|
This is convert List<object> to ArrayList.
<br />
<br />
<br />
List<object> myListObject = new List<object>();<br />
myListObject.Add("123");<br />
ArrayList myStringList = new ArrayList(myListObject.ToArray());<br />
<br />
<br />
</object></object>
Convert List<object> to List<string> without loop I don't have idea.
But you write class name "List", I don't know what is it.
|
|
|
|
|
Although that works, that would be the same with any ArrayList as they accept any and all objects (not typesafe) and I think you have missed the point there. Pretty sure the guy wanted generics, and if he is using .NET 2.0 and above (he must be to be using List in the first place) then he should not be using ArrayList.
He who makes a beast out of himself gets rid of the pain of being a man
|
|
|
|
|
Sorry about "" - I dont know how this happened.
|
|
|
|
|
I had a situation where I had to write a Windows Service which runs on a computer which is part of a network, the service runs under Local System account and starts another application upon its startup.
Now the problem is that when I log on into that system hosting service using a remote desktop connection, I don't find the application started by the service, but when I connect to that system into the windows current session using "mstsc /console" command on command prompt, the system shows me the application started by the service.
Regards,
Talha
Muhammad Talha
|
|
|
|
|
Hi,
iam in windows application.
i have DateTime Picker Control...i hvae to select the value from that control,pass the value thru parameters.
string kc=datetimepicker1.value.ToShortDateString();
param = new FbParameter("@kc", FbDbType.Date);
param.Value = kc;
cmd.Parameters.Add(param);
it's giving error "Conversion error form string "2008-04-22" like that.
please post reply.
murali krishna
|
|
|
|
|
Try not converting the date to a string. Add it as a DateTime value to param.
param = new FbParameter("@kc", FbDbType.Date);
param.Value = datetimepicker1.Value;
cmd.Parameters.Add(param);
|
|
|
|
|
Hi,
Working with WinForms, I have a ToolStrip for which I add ToolStripButtons in runtime. I have 2 problems:
1. When the mouse hovers over these ToolStripButtons they constantly flicker.
2. I need to click them twice or three time to invoke the method that is assigned to the MouseClick event.
Is this caused by adding the ToolStripButtons in runtime?
Thanks,
Yoav Ben Zvi
modified on Tuesday, April 22, 2008 3:30 AM
|
|
|
|
|
Hi Yoav,
I have tested this issue, but it works well. I was not able to see this issue here. Please send your sample code, it will helps to solve the problem earlier.
Thanks,
Gopal.S
|
|
|
|
|
th eproblem seems to be with another control teking focus. Thanks anyway.
|
|
|
|
|
Hi
Can Anyone help me for the following Issue?
How can i nvoke a method of a dll written in VB6.0 using C#.net Application?
Tahnks in Advance
sri
|
|
|
|