|
I'm lost or maybe I missed something, or both.
Why are you programatically moving the mouse cursor if the cursor is hidden? Only because you were not receiving mousemove events if the cursor left the panel, correct?
If so...
Just capture the mouse on the right button down event and release capture on the up event (of course the Panel class has the IInputElement interface needed for the Mouse.Capture() call - how else would you be handling other mouse input on your panel?).
Then your panel will receive all the mouse move events even if the cursor leaves the panel, so you don't have to move the cursor or unsubscribe/subscribe to the event.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
In part, yes - I won't receive events when the mouse leaves the panel. That's the theory at least. I've done testing and it seems I still receive events even when the cursor is outside my panel, but when the mouse reaches the edge of the monitor, I will stop receiving MouseMove events, because the cursor will have nowhere further to go. At the moment, the user has to perform multiple click + drag operations to keep the camera rotating over long distances.
The other reason I want this behaviour is that when the right button is released, the mouse will appear in the same place the user initiated the operation, rather than some unexpected location across the screen.
As for IInputElement, I'm no C# expert, but my understanding is that Panel and PictureBox are Winforms controls, whereas IInputElement is a WPF interface. WPF has an Image control (similar to PictureBox, but with different behaviour) that would work well for me, but I can't figure out how to enable WPF controls in my project. All the WPF controls are greyed out. I've added the appropriate references but no luck.
Either way, I'm no longer certain that Mouse.Capture() is what I'm after anyway. Everything I've set out to accomplish here is working, with the exception of unsubscribing the event handler + resubscribing after changing the cursor position.
EDIT: Now I simply do this instead:
private Boolean ignoreMouseMove = false;
private void onMouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
if (!ignoreMouseMove)
{
currMousePos = e.Location;
Point delta = currMousePos - prevMousePos;
Cursor.Position = this.panel_RenderWindow.PointToScreen(prevMousePos);
ignoreMouseMove = true;
}
else
{
ignoreMouseMove = false;
}
}
}
This feels kinda dirty but at least it works. I'd still like to know why unsubscribing the handler wasn't working, if anybody knows the answer.
modified on Tuesday, May 10, 2011 10:19 PM
|
|
|
|
|
Cool.
Sorry about that....I don't know how I thought I was still on the WPF board...
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hello,
What is the best way(s) to send strings from java app to .net app?
I have a main c#.net project that runs .jar (java project). The java part must give strings (recognized speech) to the c# part. it's a desktop solution that runs on one computer.
So far I see the following ways to do this:
- use a temporary text file as a buffer;
- sockets;
- windows services;
- web services (imo it's a very bad option);
- free 3d-party tools like ikvm.net and others (tried many, won't work properly, bad option).
Sp what is the best and most effective (and simple) way to do the job?
Thanks.
|
|
|
|
|
I don't know if it qualifies as a socket, but I'd use a Named Pipe.
Named Pipes are used for communication between processes, more info here (wikipedia)[^].
MSDN[^]
I can't find a good article on it (for .Net 3.5) at the moment, I guess I'll have to owe you.
|
|
|
|
|
Thanks! That seems to be a really good thing.
Will the following code work for me?: http://v01ver-howto.blogspot.com/2010/04/howto-use-named-pipes-to-communicate.html
|
|
|
|
|
One way to do this would be to create a wcf service that will be hosted in your main c# app. The Java app can then communicate with the c# app using a known Interface.
...and I have extensive experience writing computer code, including OIC, BTW, BRB, IMHO, LMAO, ROFL, TTYL.....
|
|
|
|
|
Thank you. Seems to be a reliable solution. But could you give me more details on this, please: "The Java app can then communicate with the c# app using a known Interface.".
|
|
|
|
|
CodeGust wrote: The java part must give strings
Explain that in more detail.
Examples:
Is this processing books?
Or a user is typing in words?
CodeGust wrote: So far I see the following ways to do this:
Or stdio.
I would probably use that or sockets.
|
|
|
|
|
>>> Explain that in more detail.
There is a Java program that uses Sphinx4.jar to recognize speech. It must send the recognized speech to the main program (written in .Net) in real time.
|
|
|
|
|
I don't think that answers the question.
First "speech" usually indicates vocal streams and you can't send 'speech' as a vocal stream in a String.
Second I doubt the library must process data in "real time". That might be your goal but is not a limitation of the library. It will accept its input at any time.
Third humans are slow compared to computers. So with care any of the methods you suggested would work.
Again I would use stdio or sockets. For text data. If you are using binary data then I would use a socket.
|
|
|
|
|
Hi,
In c#, I would like to validate the txtEmail by checking if a valid email address has been entered before moving away from the textbox.
If email is not valid then, txtemail should get the focus again.
The code below is what I have for this purpose but whether or not the email is valid the messagebox appears constantly and does not go away.
CAn you please see what is wrong?
Thanks
private static bool IsEmailAllowed(string text)
{
bool blnValidEmail = false;
Regex regEMail = new Regex(@"^[a-zA-Z][\w\.-]{2,28}[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$");
if (text.Length > 0)
{
blnValidEmail = regEMail.IsMatch(text);
}
return blnValidEmail;
}
private void txtEmail_LostFocus(object sender, RoutedEventArgs e)
{
if (IsEmailAllowed(txtEmail.Text.Trim()) == false)
{
MessageBox.Show("E-Mail expected", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
txtEmail.Focus();
}
}
|
|
|
|
|
Perhaps a better way is to use control validation. Take a look at this article as it seems to heading in the direction you want...
Here
|
|
|
|
|
Thanks for the link, But I have to get this to work in the current event.
Thanks
|
|
|
|
|
arkiboys wrote: But I have to get this to work in the current event.
Why? What requirement could possibly say where you have to get this to work?
|
|
|
|
|
Apologies for mis-understanding...
I would like to see if I can get it to work using the events.
Thanks
|
|
|
|
|
LostFocus event is a bad place to write validation code, try Validating (or Validate) event and set a property on the eventagr to flag a validation failure.
The best course of action would be to use built-in validator controls.
Alternatively your regex could be wrong, try stepping through your code.
|
|
|
|
|
Are you able to see if the regular expression is incorrect?
Thanks
|
|
|
|
|
Google for "Expresso". It's a great tool for writing and testing RegExs, and it's free!
As for your approach. it's bad. You're writing your code from the standpoint that users will do nothing else while your app is running. You are preventing them from possibly leaving your form or closing it without first entering a valid email address. What if they left it blank and want to go back to the previous window??
|
|
|
|
|
There is no validate event.
|
|
|
|
|
Hi,
I have this code:
object o = Csla.Serialization.Mobile.MobileFormatter.Deserialize(bin);
object val = ((Csla.Silverlight.PrimitiveCriteria)o).Value;
As you can see I get some object by deserialization. In this particular case I expect the object that is actually of Csla.Silverlight.PrimitiveCriteria type and I can cast the object in second line as I did above. In this case I know the type of object because I've seen it at debug time. But, what to do if I need to determine the type of object at runtime? What to do in case I want to parametrize the whole process? It means the class I get by deserialization can be different. How can I use that class to cast the object in second line?
Thank you in advance.
Goran Tesic
modified on Tuesday, May 10, 2011 6:19 AM
|
|
|
|
|
Tesic Goran wrote: How can I use that class to cast the object in second line?
I'd suggest to use a shared interface/common base class; if all the deserialized classes share something in common, you can use that to access it. That doesn't mean that you're restricted to a single interface; you can ask the object what interfaces are implemented and act based on that information.
I are Troll
|
|
|
|
|
Thank you for your answer.
In this case, there's a basic interface that Csla.Silverlight.PrimitiveCriteria class implements, but that interface contains only basic methods. For example, Value property is specific for Csla.Silverlight.PrimitiveCriteria class. Other properties can be specific for other classes. What to do in that case?
|
|
|
|
|
I'd add my own interface. It doesn't have to be implemented in the CSLA-classes, just in the classes that you're going to serialize.
That would give you the option to deserialize 'unknown', check if it matches an known interface and cast it thereto.
I are Troll
|
|
|
|
|
The problem is that I can't change the code in the classes I deserialize. They are all in some DLL that I use in my DLL.
|
|
|
|