|
I am using c# to create web forms in .net and am trying to add hotkeys. I have been unsuccessful in locating any reference material. If anyone knows of any good reference sights on this subject it would be greatly appreciated or if it is a simple process and explanation would be even better.
Thanks,
Rick
|
|
|
|
|
Here's some sample code for you.
private void MyControl_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
switch (e.KeyCode)
{
case Keys.Insert:
if (e.Modifiers == Keys.Shift)
{
e.Handled = true;
}
return;
case Keys.Enter:
e.Handled = true;
return;
case Keys.Up:
if (e.Modifiers == Keys.Shift)
{
if (CanMoveItemUp)
{
MoveItemUp();
e.Handled = true;
}
}
return;
default:
return;
}
}
Tom Clement
Apptero, Inc.
|
|
|
|
|
You can also implenent hotkeys in your menus easily by simply assigning the MenuItem.Shortcut property to the key you want.
For global hotkeys in your application, see the IMessageFilter interface. Implement that and catch the WM_KEYDOWN message (0x0100), then use the Message.WParam member to get which key was pressed (matches up with the Keys enumeration). Using this concept, hotkeys are available throughout your application (if you desire) and you could even implement a simple key mapping to make them easy to change (for example, from a user interface for the benefit of a user). This is common in games, for example, like Quake that allow you to bind functions to practically any key you want.
You can add your implementation at any time using Application.AddMessageFilter .
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
You and other CPains didn't consider that original poster want to do that in a WEB form.
Mazy
"I think that only daring speculation can lead us further and not accumulation of facts." - Albert Einstein
|
|
|
|
|
True. Far be it for us to assume that someone would use the right forums.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Mazy is correct I am talking about a Web application not a Window application.
|
|
|
|
|
I would like to thank everyone for their input. I was able to work out my Hotkey issue. If anyone is interested, here is an example of a button control that is executed by Alt + Q
<asp:button id="Button2" style="Z-INDEX: 103; LEFT: 316px; POSITION: absolute; TOP: 166px" accesskey="Q" runat="server" text="Button">
Rick
|
|
|
|
|
You should use AccessKey property to assign hotkey if you are using asp button control. This way you don't have to code anything.
Cheers
Never comment ur code. If it was hard to write, it should be hard to understand !!!
|
|
|
|
|
I sort of hesitate to say this, but I think we've run across a Winforms bug. I suppose the alternative is that I have a brain bug. Anyway, here's the situation:
Create a trivial application (Form1) with a button that launches a modeless dialog using:
Form2 frm = new Form2();
frm.Owner = this;
frm.Show();
In Form2, a button launches Form3 modally like this:
Form2 frm = new Form3();
frm.ShowDialog();
another button hides Form2 like this:
this.Hide();
Now, if you run the application (Form1), then switch focus to some other application (e.g. Outlook). Then click the button that launches Form2 (modeless), then click the button that launches Form3 (modal). Close Form3, and Hide Form2. Form1 goes into the background and Outlook gets focus.
Does anyone know what underlying mechanism is happening here?
Thanks as always for your help.
Tom Clement
Apptero, Inc.
|
|
|
|
|
if I have a generic class like this for example:
public class GenericExample<T>
{
public GenericExample(T parameter) {}
//...
}
when I instantiate it then:
GenericExample<string> ge1 = new GenericExample<string>(String.Empty);
GenericExample<SolidBrush> ge2 = new GenericExample<SolidBrush>(null);
so here is my question:
how can I verify, whether parameter is null,
or whether it is string.Empty, although I don't know,
if T is an value-Type or reference-type. (yes...I know string is a reference type but I had no other example in mind ).
|
|
|
|
|
[EDIT: Note, this was posted while the < and > brackets were not appearing in the root thread. I leave it here for posterity.]
This is not a template class, which would look like:
public class GenericExmaple<T>
{
public GenericExample(T parameter) {}
} And would be declared as a variable like so:
GenericExample<string> ge = new GenericExample<string>(null); If you want a class that takes a "generic" parameter, use object :
public class GenericExample
{
public GenericExample(object parameter)
{
if (parameter == null) throw new ArgumentNullException("parameter");
}
} When you define the parameter as an object, even if it's a value type it will be boxed as an object and can be compared to null, although it will never be null since value types can't be null. A reference could and thus is subject to the exception if it is null.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I see you fixed your code, which changes things a little bit...
You can always use conditions like so to check if it's null or empty in your constructor regardless of the type (so long as it's a reference type):
if (parameter == null) throw new ArgumentNullException("parameter");
if (parameter.Equals(string.Empty))
throw new ArgumentException("Error", "parameter"); If you want value types to also be valid for your generic class, then you can use something like this in your constructor:
Type t = typeof(T);
if (!t.IsValueType)
{
}
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
thanks, Heath.
the brackets '<' and '>' were missing because I forgot to
check the option 'Don't treat <'s as html-tags' and recognized just later that the brackets were not shown.
|
|
|
|
|
It also helps to put code between <pre></pre> tags, which usually translates the brackets automatically (though not always). This also makes for a nicer fixed-width format (including spaces and tabs you may use) for display code in the forums (and in articles, for that matter).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
thanks for that tip.....I guess a good one
|
|
|
|
|
how to load 3d objects in open gl and is it possible to make these models with 3d studio max and import them to opengl(using C#)?
MTSHEDID
|
|
|
|
|
here[^] and here[^]
---------------------------
He who knows that enough is enough will always have enough.
-Lao Tsu
|
|
|
|
|
thank u very much
i couldn't 've started my assignment without it
|
|
|
|
|
hi all,
I have a windows form which is used to create a user in a database. In this form I have several textfields to enter info such as first name, last name, etc...and I have 2 options using radio buttons, one is the classic "male-female" choice and the other is the classic "yes-no" choice. Only I am not able to separate the groups, I have included each pair in a separate groupBox but I don't know what else to do to make them work as 2 separate entities ...for now, only 1 choice over 4 can be selected.
help anyone?
thanks,
Talal
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning."
--Rich Cook
|
|
|
|
|
Make sure that the RadioButton s are actually added to the container's (i.e., GroupBox , Panel , etc.) Controls collection property. If they are added to the same container (i.e., your Form ) but only positioned inside the separate containers, they will act as a single group.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Ok, I just made it work, I moved the RadioButtons out of the controlBox and then back in and now it works. I also checked the CS code to make sure they are added to the controls collection as you said, and they are indeed now added, each pair in a difference container
thanks!
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning."
--Rich Cook
|
|
|
|
|
sorry, I have another question. Is it possible to remove the border of the controlbox? I don't want it to appear, I have tried putting the visible thing to false but then the radiobuttons disappear also. thank you.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning."
--Rich Cook
|
|
|
|
|
If you don't want the look of the GroupBox , then use a different container like the Panel . Making the change would be easier by just changing the declarations in the source file rather than using the designer and having to cut and paste all your controls again (which un-hook the event handlers but preserve the property values in most cases).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
thanks! Panel works great
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning."
--Rich Cook
|
|
|
|
|
As Heath Stewart said: use another container.
So putting each group of radio buttons on its own panel, instead of group box, should do the trick.
|
|
|
|