|
|
Thanks, this sounds like what I'm looking for. There's a minor hitch though, I'm using a Panel control as my render window. It seems that this control doesn't inherit the IInputElement interface required for Mouse.Capture(). My second choice would be a PictureBox control, however that doesn't implement the interface either. Now the question becomes, what control implementing IInputElement can I use that would be suitable for rendering my 3D scene to?
|
|
|
|
|
I'm not familiar with WPF, so I can't help you in any specific way, however a quick glance brought me this sentence, which might help:
In particular, UIElement descends from Visual, which provides the lower-level graphics support for rendering a ContentElement to a rectangular region within a composited window, whereas ContentElement defers rendering so that concepts more common to document scenarios, such as flow and wrapping, are more easily supported. These two related classes also implement the common interfaces IInputElement and IAnimatable.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Back to my initial question, I've spotted a few mistakes which are complicating things a little...
The first mistake was updating prevMousePos to the value in currMousePos, and later using that value to update the position of the cursor.
...
currMousePos = e.Location;
...
The second mistake was assuming that the mouse coordinates in the event were relative to the screen. They are relative to the client rect of the control.
...
Cursor.Position = this.panel_RenderWindow.PointToScreen(prevMousePos);
...
Now the cursor's position is reset correctly, however the problem of the recursive MouseMove events still remains - if I remove Cursor.position = prevMousePos , then my application continues to update in the background, however if I don't everything else freezes until I release the right mouse button - including the 3D render window where the user is expecting to see updates to the camera position. The event is definitely not being unsubscribed correctly, though I can't figure out the correct way.
EDIT: I've been googling for hours and this[^] is the only thread I could turn up that dealt with this specific issue, and the answer he get was less than helpful.
modified on Tuesday, May 10, 2011 11:38 AM
|
|
|
|
|
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
|
|
|
|