|
dear all,
I would like to know how can i detect the arrows key (left and right) when key press event handler in window application?
thanks in advance.
regards
cocoonwls
|
|
|
|
|
The KeyPress event is not raised by noncharacter keys; however, the noncharacter keys do raise the KeyDown and KeyUp events.
in KeyDown or KeyUp events you can detect arrows by e.KeyCode.
When you're alone in the Dark, Fear will protect you...
|
|
|
|
|
Simple. With ASCII Code.
lets take an example of pressing the keys in just form1:
if(e.KeyChar==37)<br />
txtStatus.Text = "You've pressed the left arrow key.";<br />
if(e.KeyChar==38)<br />
txtStatus.Text = "You've pressed the up arrow key.";<br />
if(e.KeyChar==39)<br />
txtStatus.Text = "You've pressed the right arrow key.";
This is just a small example to get you started and so that u get to know the use of ASCII char tables.
Edit: Well it would be, if it would work... kinda forgot how i used this stuff.
Heres a good link on explanating the keypress control:
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.keypress(VS.71).aspx[^]
Greets,
Matjaž
Força Barça!
modified on Wednesday, November 5, 2008 1:54 AM
|
|
|
|
|
Hi Pedram Behroozi and max00slo,
I have tried it before, for other char is OK, but i just can't detect the arrows key.It never fire the keydown event. What i am do in my application is, i create the keydown event handler in one of my custom UI control, and it will pass the event args to one of my class via a abstract class.
any ideas are welcome.
thanks in advance
cocoonwls
modified on Wednesday, November 5, 2008 2:16 AM
|
|
|
|
|
cocoonwls wrote: i just can't detect the arrows key
Didn't this work?
if (e.KeyCode == Keys.Right)
{
...
}
When you're alone in the Dark, Fear will protect you...
|
|
|
|
|
Thanks for reply.
yes, i also try it .keycode, but still can't fix it..
|
|
|
|
|
You will need to override ProcessCmdKey method to catch the arrow key press.
|
|
|
|
|
Hi d@nish,
Can you please give me a simple explain on it, where should i put the override code, and should i add the virtual method on it(for override)?
thanks in advance
cocoonwls
|
|
|
|
|
You just need to override the method in your class. This VB.Net[^] code should get you going with it.
|
|
|
|
|
Thanks i got it!
|
|
|
|
|
you must derive a new class that is based on the class of the control that you want, and you override the ProcessCmdKey().
Syntax:
C#:
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
}
Full source code..C# Arrow Key Press
Vayne
|
|
|
|
|
I've got the following code that attaches a thumbnail image coming from an ImageList to a PictureBox. However, it is causing my application to not close once the code block gets executed. I suspect this has got to do with the resource(the photo file) not being released properly, I may be wrong though. Any experts advice would be greatly appreciated. All the best!
<br />
Image.GetThumbnailImageAbort myCallback =<br />
new Image.GetThumbnailImageAbort(ThumbnailCallback);<br />
Image myThumbnail = this.imageList1.Images[0].GetThumbnailImage(this.pictureBox1.Size.Width-5, this.pictureBox1.Size.Height-5, myCallback, IntPtr.Zero);<br />
<br />
this.pictureBox1.Image = myThumbnail;<br />
this.pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage;
----------------------------------------------------------
"unzip; strip; touch; finger; mount; fsck; more; yes; unmount; sleep" - my daily unix command list
|
|
|
|
|
The code works fine for me.
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Image.GetThumbnailImageAbort myCallback = new Image.GetThumbnailImageAbort(ThumbnailCallback);
Image myThumbnail = this.imageList1.Images[0].GetThumbnailImage(this.pictureBox1.Size.Width - 5, this.pictureBox1.Size.Height - 5, myCallback, IntPtr.Zero);
this.pictureBox1.Image = myThumbnail;
this.pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage;
}
private bool ThumbnailCallback()
{
return true;
}
}
And the app exits fine.
Failure to exit is usually caused by a thread not terminating correctly. Does your abort callback get triggered? Does it correctly return?
You don't need to release the Image. This is handled by the Imagelist for you provided that you have added your image list via the designer or correctly disposed of it manually, either way though, this wouldn't prevent your app from closing.
After you have closed your app, and it's stuck without terminating, try hitting the pause button and looking at the call stack to see where it is stuck.
Simon
|
|
|
|
|
hello all,
i am new in window apllication c#. when i load rtf file in richtextbox control with every new paragraph with and <\p>.
i have done this..but can't remove whitespace.
he show with blankspace <\p>.
like..there is five paragraph in file.
aaaaaaaaaaaaaaaaaaaaaaaaaa<\p>
<\p>
<\p>
aaaaaaaaaaaaaaaaaaaaaaaaaa<\p>
aaaaaaaaaaaaaaaaaaaaaaaaaa<\p>
here, i want to remove two blanckspaces..
|
|
|
|
|
what is <\p> ?
xacc.ide - now with TabsToSpaces support IronScheme - 1.0 beta 1 - out now! ((lambda (x) `((lambda (x) ,x) ',x)) '`((lambda (x) ,x) ',x))
|
|
|
|
|
|
how To Add Product key Setup please help me
Piyush Vardhan Singh
p_vardhan14@rediffmail.com
http://holyschoolofvaranasi.blogspot.com
http://holytravelsofvaranasi.blogspot.com
|
|
|
|
|
We cant help if we dont know your specific problem.
xacc.ide - now with TabsToSpaces support IronScheme - 1.0 beta 1 - out now! ((lambda (x) `((lambda (x) ,x) ',x)) '`((lambda (x) ,x) ',x))
|
|
|
|
|
I want to modify this RegisterHotKey func to allow me to set it using HashKey instead of a shortcut key but I'm not exactly sure how to do this.
this is the code for registering the hotkey in the object
protected bool RegisterHotkey(Shortcut key)
{
int mod=0;
Keys k2=Keys.None;
if (((int)key & (int)Keys.Alt)==(int)Keys.Alt) {mod+=(int)Win32.Modifiers.MOD_ALT;k2=Keys.Alt;}
if (((int)key & (int)Keys.Shift)==(int)Keys.Shift) {mod+=(int)Win32.Modifiers.MOD_SHIFT;k2=Keys.Shift;}
if (((int)key & (int)Keys.Control)==(int)Keys.Control) {mod+=(int)Win32.Modifiers.MOD_CONTROL;k2=Keys.Control;}
System.Diagnostics.Debug.Write(mod.ToString()+" ");
System.Diagnostics.Debug.WriteLine((((int)key)-((int)k2)).ToString());
return Win32.User32.RegisterHotKey(m_Window.Handle, this.GetType().GetHashCode(), (int)mod, ((int)key) - ((int)k2));
}
|
|
|
|
|
Hi guys,
I have created a windows based project for my client and it works fine for him. He is my client and want to sell this product to further clients, so for this he wants that in deployment of the project a screen should appear that shows about to insert a license key and it must match with a license which is stored in an online database.
Creation of database and checking of license key is I think is not typical, but the typical act is how to create a screen which appears in the deployment of that project and appears at the time of installation.
If any one help me then I will be highly thankful to that person.
Thanks in Advance
|
|
|
|
|
What you are after, sounds like a Splash Screen:
www.codeproject.com/KB/cs/prettygoodsplashscreen.aspx[^]
You can add additional arguments in the code, which check to see if the project is registered or not, and if it is already registered, to not even display the Splash Screen, and just head to the main screen.
|
|
|
|
|
Hi,
I want to display the messages from Queue in consoleapplication.I am able to read the queues.But while displaying, if i had 6 messages in queue and in that i am able to display only 3.Please help me out in solving this.
My code is as follows:
string QueueName = ".\\Private$\\TestQ";
MessageQueue.EnableConnectionCache = false;
//// open the selected message queue
this.messageQueue = new MessageQueue(QueueName, QueueAccessMode.Receive);
while (true)
{
System.Messaging.Message message = new System.Messaging.Message();
MessageQueueTransaction msgTx = new MessageQueueTransaction();
MessageDetails messageDetails = null;
try
{
msgTx.Begin();
message.Formatter = new BinaryMessageFormatter();
message = messageQueue.Receive(new TimeSpan(0, 0, 0, 10), msgTx);
if (message.Body != null)
{
messageDetails = (MessageDetails)message.Body;
Console.WriteLine(messageDetails.ApplicationName + "\t" + messageDetails.ThreadName + "\t" + messageDetails.Status + "\t" + messageDetails.TimeStamp);
}
msgTx.Commit();
messageQueue.BeginReceive();
}
Thanks in Advance
|
|
|
|
|
is messageQueue subscribed to receive the callback from the BeginReceive() call? if not that'll probably discard every other message in the queue.
|
|
|
|
|
I've tried to capture the desktop with the cursor image using different codes and none manages to draw the IBeam cursor. If I use the Cursor.Current, I always get the waitcursor; using API, I get the correct cursor. Is there a workaround?
|
|
|
|
|
Nothing, guys? From what I've seen during my google searches, this is a common problem so I think there must be a workaround. I know that Ibeam is a xor cursor, but I don't know how to get the xor mask using CursorInfo.
|
|
|
|