Jump to content
  • Advertisement
Sign in to follow this  
CodeCriminal

[.net] C# Windows Forms Events Question

This topic is 3401 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi there, im a bit of a beginner in C# and so far its been quite a smooth ride coming from a C++ background. I would like to use it for tool development in some future games that i might make. There are a few things i would like to know, any help from you guys is appreciated. [smile] - What other ways ( besides double clicking on a control in the windows form ), can i add Events to my application? Im going to be needing access to the applications Idle event, KeyDown, MouseMove, MouseClick and so on events, and just double clicking on a control in a form is not enough, I needed a greater level of control over how my applications events are handled. - I notice when creating a ToolStrip or MenuStrip there is a slight gradiented look to it, but when you change its color ( and without pressing ctrl+Z ) its seems impossible to get the gradient back, why? can i make my own custom gradients? if so then how?. - Im going to be using slimDX and was hoping that i could run it through some panel on the form ( as a sort of viewport ), is this possible? If not, can i just run on it on the main form and use the panel as a guide for placing the direct3d viewport? This means i need to know how to access the window resized events. Thats all for now folks [smile] Thanks a bunch! ~CC

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by CodeCriminal
- What other ways ( besides double clicking on a control in the windows form ), can i add Events to my application? Im going to be needing access to the applications Idle event, KeyDown, MouseMove, MouseClick and so on events, and just double clicking on a control in a form is not enough, I needed a greater level of control over how my applications events are handled.

The list of events for controls is given in the events tab of the property grid in design mode. Double clicking there will wire up an event and put that wiring code in the designer generated file. You can always write that code by hand, and indeed are required to do so for non-control classes. Here's a quick example:[/quote]


Application.Idle += HandleIdle;

void HandleIdle(object sender, EventArgs e)
{
}



Quote:

- I notice when creating a ToolStrip or MenuStrip there is a slight gradiented look to it, but when you change its color ( and without pressing ctrl+Z ) its seems impossible to get the gradient back, why? can i make my own custom gradients? if so then how?.

Doing custom drawing on controls isn't easy. For tool strips, you can implement your own ToolStripRenderer which can do any kind of drawing you want.

Quote:
- Im going to be using slimDX and was hoping that i could run it through some panel on the form ( as a sort of viewport ), is this possible? If not, can i just run on it on the main form and use the panel as a guide for placing the direct3d viewport? This means i need to know how to access the window resized events.


When you create a Direct3D device in SlimDX, you are required to pass an IntPtr to a window that will be used for rendering. Simply pass the Handle property of whichever control you want to be the render target and it will all work properly.

Share this post


Link to post
Share on other sites
Ummm sorry, but i dont see any events tab, am i looking in the wrong place, this is what i see:

Accessability
----
Appearance
----
Behavior
----
Data
----
Design
----
Layout


Ive looked inside those tabs also, no "events" tab anywhere [sad]
Any help?

Share this post


Link to post
Share on other sites
The tabs are the buttons above the grid area of the property grid control. The events tab is the button with a lightning bolt icon.

Share this post


Link to post
Share on other sites
Oh yeah, i see thank you! [smile]
Just one more thing, i have something like this set up
menuItemSave.Click += OnSaveClick;
toolStripItemOpen.Click += OnOpenClick;
toolStripItemSave.Click += OnSaveClick;
//....
private void OnSaveClick(object sender, EventArgs e)
{
MapEd.SaveFile();
}

private void OnOpenClick(object sender, EventArgs e)
{
MapEd.OpenFile();
}


But i want to check which save button was pressed, the Save As or Save, so i can skip opening a dialog if the file loaded into the application is not a brand new file. Like other applications do. Do i have to check against sender? if so how?

Share this post


Link to post
Share on other sites
Have a "Save As" button that saves the file after requesting a file name. Store the filename somewhere for future reference.

Have a "Save" button that checks if the current file name differs from the stored file name. If different, call the "Save As" button. If the same, just save the file.

Share this post


Link to post
Share on other sites
Quote:
Original post by CodeCriminal
Oh yeah, i see thank you! [smile]
Just one more thing, i have something like this set up
*** Source Snippet Removed ***

But i want to check which save button was pressed, the Save As or Save, so i can skip opening a dialog if the file loaded into the application is not a brand new file. Like other applications do. Do i have to check against sender? if so how?


Yes the control that triggered the event is the sender param. To check you can just do something like: if(sender==toolStripItemSave)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!