|
Look at the KeyDown event. There are other events that work similar, but this (or KeyUp ) is the easiest since you're passed the KeyCode that was pressed.
As far as how to do it, well, you're going to have to learn. In VS.NET, you can switch to the events tab in the Property Grid, find one of those events I mentioned and double-click it for a default name. Start reading the documentation for the KeyEventArgs that is passed and you'll even find some good examples.
Blindly fumbling through code and relying soly on IntelliSense won't teach you anything. Researching most definitely will and is required for good development skills. If you still can't figure it out, post to the forum what exactly is wrong (compile errors, exceptions thrown, etc.) but try to figure it out first. It's the only way to truly learn especially when you're a n00b.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Your post didn't help at all since I'm a n00b and there are too many topics about KeyEventArgs in the MSDN and there's no example that I was looking for.
http://www.hentaitheme.com
Free Public Ragnarok Online Game Server
|
|
|
|
|
Well, there's only one way to learn, bubba. Start reading the topics in MSDN and start-off basic if you can't understand the "advanced" (even though it's not) stuff. Making guesses and asking others for complete examples won't teach you anything.
Here's a (rather thorough) tip, though: handle the KeyDown event and in the KeyEventArgs check if the KeyEventArgs.KeyCode property is set to KeyCode.Escape . Then either call Show or Hide on the Form . The only problem is that once the form is hidden, it won't receive keyboard events because it doesn't have the focus. So, you'll have to have another Window that is capable of showing the window again if the [ESC] key is pressed again.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
wha?? that's bullshit and so much trouble, I saw other programs made in C++, it doesn't look so hard and hassle, I start off with C# because I thought it's easier than C++, now I think C# is bullshit, so little examples to learn from and people aren't even helpful, there are tons of examples with C++ about that hide/show menu but I wanted it in C# but no examples....
http://www.hentaitheme.com
Free Public Ragnarok Online Game Server
|
|
|
|
|
Look, a window can't receive input if it doesn't have the focus! Period. If can't have the focus if it isn't visible! Period. If you don't believe me, read the damn Windows Manager section in the Platform SDK. The only other way is to install a hook and remove it when visible again.
And it's so much trouble to actually READ the documentation? Right. You'll learn a lot that way.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
I currently have a collection of custom business objects which is a datasource for my DataGrid. I would like a property of this custom object to be an image which is displayed in the datagrid. I am using column styles and DataGridTextBoxColumns for all other properties. How do I display an image?
I need the solution to be generic, so I can't be using delegates or other solutions that require a hardcoded function for a particular image.
I have not found anywhere on the net that describes how this can be done. Does anyone have any sugguestions?
Please help.
Thanks.
|
|
|
|
|
I’m pretty sure that you'll find all that you need about DataGrid at
Windows Forms FAQ:
http://www.syncfusion.com/FAQ/Winforms/
Best Regards,
Daniel Zaharia
|
|
|
|
|
I think this is a valid solution. Any Sugguestions?
I have created a class called GridIconOnlyColumn which implements DataGridTextBoxColumn
protected override void Paint(System.Drawing.Graphics g, System.Drawing.Rectangle bounds, System.Windows.Forms.CurrencyManager source, int rowNum, System.Drawing.Brush backBrush, System.Drawing.Brush foreBrush, bool alignToRight)
{
try
{
g.FillRectangle(backBrush, bounds);
if (mobjGrid == null)
{
mobjGrid = (Prud.Controls.Grid)this.TextBox.Parent;
}
// Get Custom Object
object objRow = mobjGrid.Rows[rowNum];
//Draw Image
g.DrawImage((System.Drawing.Image)PropertyDescriptor.GetValue(objRow), bounds);
}
catch (Exception err)
{
throw err;
}
}
|
|
|
|
|
Assume my windows based program is named 'App1'.
How can I write
If App1 == Already running
{
then exit and do not run a second instance
}
thanks
|
|
|
|
|
using System.Diagnostics;
In the Main function for your app...
Process proc = Process.GetCurrentProcess();
Process[] procs = Process.GetProcessesByName(proc.ProcessName);
if (procs.Length > 1)
Application.Exit();
else
Application.Run(new Form1());
|
|
|
|
|
|
Jeff,
Shouldn't that read:
if (procs.Length > 0)
Thanks,
Alvaro
He who laughs last, thinks slowest.
|
|
|
|
|
No. The first instance of the program would never run because the Process array includes the current running process. So changing it to Length > 0 would cause the program to never run.
|
|
|
|
|
Of course!
Thanks for clarifying.
Regards,
Alvaro
He who laughs last, thinks slowest.
|
|
|
|
|
While getting the process list is one way to do it, it relies on nobody else running an executable with the same name.
The approach most people seem to use is creating a "named mutex". A mutex is an object that can only be owned by one thread. If you make this a "named" mutex, then its effect is machine wide (as opposed to just process wide).
The approach is you try to create a named mutex with a unique name (use a GUID and you'll never have to worry about some other program using the same name). If you are able to create it and own the mutex, then you're the first instance running. If you can't create it, someone else is already running.
For an example of this technique, use this link I found in a Google search:
Link
Look at the 2nd reply (third message) from "Adam".
I, for one, do not think the problem was that the band was down. I think that the problem may have been that there was a Stonehenge monument on the stage that was in danger of being crushed by a dwarf.
-David St. Hubbins
|
|
|
|
|
|
I have a form that I need to set a vlaue in from another form. I know I can do this with a property. the problem is that form I want to set the property on is already active. The olny way I know to set the property is to do somthing like
formname f = new formname();
f.propName = my vlaue;
f.show();
this would create a new form not use the one I already have and I am at a lost as to how to set the prop in the form that is already loaded.
thanks for any help.
|
|
|
|
|
in your main form clas create a member variable (reference)
formname f;
in the load event of the main form :
f = new formname();
then in your code:
f.propName = my vlaue;<br />
f.show();
this way you always use the same formname instance..
i wish this can help..
|
|
|
|
|
dose this not create a new instance of the form and not reffrence the one I curently have open.
I was able to make it work by making it static. Is this a good way of doing it or did I gat lucky
|
|
|
|
|
I think my way (member variable) is more clear nad reasonable.
|
|
|
|
|
So, what do you want?
Do you want to set value to Properties which is already defined in Form class or your own property defined in your customized Form class?
|
|
|
|
|
I am a novice developer and am trying to do this:
I have created a custom event which I want to fire from within the constructor of MyClass. Now when it tired to fire I get a runtime error which says "Null Reference", possibly pointing at "this"-
Here is the snippet:
public delegate void MyLogEventHandler(object sender, LogEventArgs e);
public class BotNode : GoGeneralNode
{
public event MyLogEventHandler BotCreatedEvent;
public BotNode()
{
LogEventArgs myLogEventArgs = new LogEventArgs("Bot Node Created");
BotCreatedEvent(null, myLogEventArgs);
}
Question: Is it impossible to pass "this" as a parameter to an event within the constructor of a class? At this point, can I only use this within the class, or can I safely pass it as part of an event invocation.
If so:
1) Why can't I use it that way within the constructor?
2) How do I solve this?
Maybe I am just making a stupid mistake. Apologies for my ignorance.
HEELP!
Andy
|
|
|
|
|
You can't fire an event in the constructor. Here's why (and the answer to your problem). Events in .NET are based on the listener principal. Each even has a collection of listeners associated with it (by default). If there are no listeners, the event list is null. That's why you're getting the NullReference exception. You can't do this in your constructor because until your constructor finishes and an instance is created, callers must wait before attaching an event handler to the event. If you want to fire an event while your object is being created, then you should use static events which work the same way:
public class MyClass
{
public static event EventHandler Created;
public MyClass()
{
if (Created != null) Created(this, EventArgs.Empty);
}
} See how I checked if the event was null (i.e., the event handler collection is empty)? There is a more common practice for this, especially with instance events. The .NET BCL (base class library) does it throughout and it's a good idea to do in your code, that way derived classes don't have to listen to the event which is a little slower. You use a protected virtual method that raises the event and simply call that:
public class MyClass
{
public MyClass()
{
}
public event EventHandler MyEvent;
protected virtual void OnMyEvent(EventArgs e)
{
if (MyEvent != null) MyEvent(this, e);
}
}
public class MyClass2 : MyClass
{
public MyClass2()
{
}
protected override void OnMyEvent(EventArgs e)
{
if (e != null) DoSomething();
base.OnMyEvent(e);
}
}
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
1) Very good response
2) It works!
3) I learned something important.
and finally ...
4) You're my hero!
Thanks for the very good and easy to understand explanation including sample code (!). Can't ask for more than that.
Andy
|
|
|
|
|
andrewstan wrote:
3) I learned something important.
I'm glad to hear it! I may come off as a bit of an ass sometimes to some people, but this is all I'm trying to foster - education. I'm glad I could help!
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|