|
How do I get the protected override void OnMouseMove() event
to stop firing when the mouse has stopped moving over the parent application? Thx
modified on Wednesday, May 14, 2008 5:02 PM
|
|
|
|
|
You have described the method and not the event. If you register and unregister the event you should have no problems.
Need a C# Consultant? I'm available.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
|
|
|
|
|
By describing the method I wanted everyone to know that I was not registering an event, but using the native .net OnMouseMove method.
Why does it fire when the mouse is not moving?
Any suggestions?
|
|
|
|
|
Because it is designed to fire. The underlying class physically calls it every time a windows message comes for a mouse move. The only way to keep it from firing it to override the OnMessage? method and strip out the mouse move event.
Need a C# Consultant? I'm available.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
|
|
|
|
|
I have an app that builds but I get an "Item already exist" deployment error. I brought down the project from MS TFS and can't run it to debug. I've been fighting this for long enough. Can anyone help?
|
|
|
|
|
I have a c# application which call another exe. I need to relenquish cpu cycles from the parent application so the child executes efficiently.
example of my code in parent:
myProcess.StartInfo.Arguments = Rfmt_Arg;
myProcess.StartInfo.FileName = "rfmat32.exe";
myProcess.StartInfo.CreateNoWindow = false;
myProcess.Start();
// wait
for(;!myProcess.HasExited;){}
The problem is the task manager shows the parent application is still using 50% of the cpu cycles.
And the child application needs all the cycles it can get.
|
|
|
|
|
Put a Thread.Sleep(0); in the loop. That makes it give up the rest of the time slot (instead of using it to repeatedly check a value that can't change because the child application doesn't get to do anything until the time slot ends).
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
did you try myProcess.WaitForExit(); ?
|
|
|
|
|
When I uncomment the last four lines I get an error. "Cannot convert from int/char to object" Can anyone help. Thanx in advance.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Ch07Structs
{
public class Employee
{
private int emp;
public Employee(int i)
{
emp = i;
}
public override string ToString()
{
return emp.ToString();
}
}
class Program
{
public static void Display(object[] o)
{
foreach (object f in o)
Console.WriteLine("{0} ",f.ToString());
Console.WriteLine();
}
static void Main()
{
Employee[] emp = new Employee[5];
for (int i = 0; i < emp.Length; i++)
{
emp[i] = new Employee(i + 5);
}
Display(emp);
string[] st = { "hello" };
Display(st);
Console.ReadKey();
}
}
}
|
|
|
|
|
you need to cast the int / char array's before calling Display.
eg:
<br />
char[] stArray = { 'h','e','l','l','o' };<br />
object[] obj = (object[])stArray;<br />
Display(obj);<br />
<font color="blue">Csharp</font> me = (<font color="blue">Csharp</font>)Dynamic_Sysop; <font color="#008000">// My Signature.</font><br><font color="#008000">$twins</font> = <font color="#008000">me.twins</font>(<font color="#800080">"Taylor"</font> , <font color="#800080">"Delta"</font>); <font color="#C0C0C0">// My twin daughters.</font><br>echo <font color="#008000">$twins</font>;</br></br>
|
|
|
|
|
Csharp™ wrote: you need to cast the int / char array's before calling Display.
eg:
char[] stArray = { 'h','e','l','l','o' };
object[] obj = (object[])stArray;
You can't cast a char array to an object array.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
You misread the error message. If you check again, it says that you can't cast int[] or char[] to object[]. You can't cast an int array or a char array into an object array. You have to cast each item in the array:
int[] i = { 2, 2, 2, 2 };
object[] oi = new object[i.Length];
for (int j = 0; j < i.Length; j++) io[j] = i[j];
Display(oi);
char[] stArray = { 'h','e','l','l','o' };
object[] ostArray = new object[stArray.Length];
for (int j = 0; j < stArray.Length; j++) ostArray[j] = stArray[j];
Display(ostArray);
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Thanx now I understand that you have to convert the values of the array and not the array itself. But I still dont understand how come the string and the Employee arrays are being accepted by the display method. Has it got something to do with reference and value types. Because when I changed the Employee class to a struct I got an error. If you explain. How is it the object array is giving preference to ref types and not to value types, if all have been derived from object.
|
|
|
|
|
All value types (built-in value types and structs) inherit from the abstract class ValueType, which is treated differently by the compiler by storing the data inline instead of using a reference.
When you declare an array of strings, the array contains references to the strings, and the strings are stored outside the array. When you declare an array of ints, the array contains the int values themselves.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Yes but what I dont understand is, why is the object array, accepting string[] and not int[].
where as an object variable will accept a string or an int or anything. Sorry if I am being trouble.
|
|
|
|
|
humayunlalzad wrote: Yes but what I dont understand is, why is the object array, accepting string[] and not int[]. where as an object variable will accept a string or an int or anything.
When you store a string reference in an object reference variable, it's simply cast into an object reference. As the compiler knows that it's safe to store a string reference in an object reference variable, there is actually no conversion at all, the reference is just stored in the variable.
When you store an int value in an object reference variable, the value itself is not stored in the variable. Instead a new object is created on the heap, the int value is stored in this object, and the reference to the object is stored in the object reference variable. This is called boxing.
A string array can be handled as an object array, as they both contain references. An int array can not be handled as an object array, as it doesn't contain references. Instead each int in the array has to be boxed, and the references placed in an object array.
Boxing of single value types is done automatically, but there is no automatic boxing of all items in an array, as this could get very inefficient. Creating a value type array is efficient as it's still only one object, but if you could trigger an automatic boxing of all items in the array, you could accidentally create thousands of new objects.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Thank you so much, now everything is crystal clear
|
|
|
|
|
Like others have said, you can't cast an array of something into an array of something else. Ever. You have to loop, one way or the other. This is part of the philosophical heritage of C# - stuff that's very expensive to execute shouldn't be so simple to write that it routinely fools people into thinking it's inexpensive.
However, the .NET Framwork doesn't necessarily play by those rules, so a look in the class library can sometimes help you avoid writing the loop yourself. Look at System.Array.Copy and System.Array.ConstrainedCopy, for instance (or ConvertAll).
In your particular example I would suggest a generic version of Display(), though, as in:
public static void Display<T>(T[] arr)
{
foreach (T e in arr)
{
Console.WriteLine("{0} ", e.ToString());
}
Console.WriteLine();
}
public static void Display(object[] oarr)
{
Display<object>(oarr);
}
Provided that you rename the array called "i" (name clashes with the for loop counter, at least in VS2005) you can remove the comments and it will work like a charm. Note that you DON'T need to specify the type (as in Display<int>(intArray); ), as it is inferred by the compiler.
For added value, you can also insert the keyword "params" before the parameter declarations, as in:
public static void Display<T>(params T[] arr)
public static void Display(params object[] oarr)
That way, you can invoke them like this:
Display(1, "hello", 2, "word");
Display<int>(1, 2, 3, 4);
If you do anything more complex than ToString() (or something else that's inhereted from System.Object ) on the elements, you will probably have to constrain T (using the where keyword) to make sure that it implements some interface or other.
I still think generics are sexy... wonder how long that will last...
Later,
--
Peter
modified on Wednesday, May 14, 2008 6:19 PM
|
|
|
|
|
Great, it did work like a charm. And now you've made me a fan of Generics too. And as you said I didn't specify the type and it was working fine.
Thanx a lot.
|
|
|
|
|
I am trying to save in image into an MS SQl amd keep getting this error "Must Declare the Scalar Variable"
below is my code for the insertion;
OdbcCommand cmd = new OdbcCommand("INSERT INTO dbo.photo (photo) VALUES (@BLOBData)", myConnection);
//Save image from PictureBox into MemoryStream object.
MemoryStream ms = new MemoryStream();
picture.Save(ms, ImageFormat.Jpeg);
//Read from MemoryStream into Byte array.
Byte[] bytBLOBData = new Byte[ms.Length];
ms.Position = 0;
ms.Read(bytBLOBData, 0, Convert.ToInt32(ms.Length));
//Create parameter for insert statement that contains image.
OdbcParameter prm = new OdbcParameter("@BLOBData", OdbcType.VarBinary, bytBLOBData.Length, ParameterDirection.Input, false,0, 0, null, DataRowVersion.Current, bytBLOBData);
cmd.Parameters.Add(prm);
myConnection.Open();
cmd.ExecuteNonQuery();
myConnection.Close();
}
catch (OdbcException ex)
{
MessageBox.Show(ex.Message);
}
Any help?
a novice
|
|
|
|
|
|
I need a little help with my ctcss coder/encoder i have to programs coder and encoder. First take signal from microfone and put signal (100 or 200hz) an d send to second computer using audio cabel (that i have). On second pc i need detect ton and if its is set to this what i send it will remove it. Could You tell me how to remove this signals? some codes? the signals is in array of byte (length 400) sampling rate 8000.
|
|
|
|
|
Dears,
I've a web application in which every this is working okay offline, but after piblishing the app online i had a problem saving arabic data from the application into the database which in my case sql server 05 it is saved as ???????????????????? 'question marks' columns collations is set to Arabic_CI_AS and my fields are all nvarchar or nchar and when i manually enter any arabic data into the database server online it is saved correctly and i can also read it correctly from my application
it would be gr8 if some one has got a solution for this.
Thanks in advance
Yours
Ahmad Abubakr.
|
|
|
|
|
Posted in three forums.
Does it matter what I write here? Someone just has to say something about it.
|
|
|
|
|
Can any one help
How to create the Setup file in C# Console Application in .Net
|
|
|
|