Does anyone know how to do things when a form is closing in C#? I've tried using the FormClosing and FormClosed events, but I haven't been able to get them to work.
[QUOTE=SamPerson123;21541691]Does anyone know how to do things when a form is closing in C#? I've tried using the FormClosing and FormClosed events, but I haven't been able to get them to work.[/QUOTE]
They work fine. Using those events is the right way to do it.
[QUOTE=Darwin226;21522966]I don't really think that would solve my issue (which isn't really an issue but it would be convenient if it were possible).
I have a Liner class that is in charge of drawing vector graphics. It has a var Image that is the image it draws on.
If I have nested classes they would all have to draw on the SAME image (meaning I would have to pass references to that image) and as far as I know you can't have variables in namespaces alone, only classes.[/QUOTE]
I thought you wanted a static class? If that's the case, you can't put variables in them. Otherwise, you can just put a Variables class in your namespace and use that?
-snip, shit wrong thread-
I think that was meant for the WAYWO thread. Very nice anyways.
May I ask how long have you been programing in general?
Also, what was up with that downtime?
Is there a way to change the color of user defined methods in Visual Studio 2010?
I can't find the option in fonts and colors.
Need some exemple network code, currently writing a peer-to-peer chat program in C#, console based.
How would I access and play an embedded resource .wav file, using System.Media.SoundPlayer? (C#)
[QUOTE=jA_cOp;21542401]They work fine. Using those events is the right way to do it.[/QUOTE]
I know they're the right way to do it, but they're not working for me. I've been trying to make it so you can't have more than one of the same form open at once, but it won't allow me to open another one once I close the first.
If you see anything wrong with this, please tell me what it is.
from the Input class
[CODE]private void Input_FormClosed(Object sender, FormClosedEventArgs e)
{
Mb.formexists = false;
}
[/CODE]
from the Mandelbrot class
[CODE]if (keybState.IsKeyDown(Keys.Q))
{
if (!formexists)
{
InputForm = new Input();
InputForm.Show();
InputForm.Mb = this;
formexists = true;
}
}[/CODE]
[QUOTE=Joshyy;21537384][URL]http://www.geekpedia.com/tutorial55_Mouse-coordinates.html[/URL]
Enjoy, no one is giving you code. Work it out yourself via google. Since that's where I pulled that from. Searching "How to get mouse position in C#"[/QUOTE]
Did I ask for code? No. Stop being a moron.
[QUOTE=Chad Mobile;21550484]Did I ask for code? No. Stop being a moron.[/QUOTE]
You always do
No, I dont...
[QUOTE=Chad Mobile;21550594]No, I dont...[/QUOTE]
Last time I helped you you complained that the tutorial I sent didn't have completed code at the end.
I said I didn't understand it.
Please, not this shit again.
Don't let it grow into a 3 page argument.
I didn't start anything, [URL="http://www.facepunch.com/member.php?u=141251"]Hypershadsy[/URL] did.
[QUOTE=Chad Mobile;21551282]I didn't start anything, [URL="http://www.facepunch.com/member.php?u=141251"]Hypershadsy[/URL] did.[/QUOTE]
You snapped at Joshyy.
Nice subject change.
[QUOTE=Chad Mobile;21551371]Nice subject change.[/QUOTE]
I meant the whole thing was your fault. Got eyes?
Now let's be fair, Joshyy did write "No one is giving you code" to wind up Chad. And yes, Chad did bight back and start name calling but you can't push the whole thing on to him. And the whole "he started" it thing should of been dropped once you entered the age of 6.
[sp]1234 posts![/sp]
[QUOTE=SamPerson123;21549357]I know they're the right way to do it, but they're not working for me. I've been trying to make it so you can't have more than one of the same form open at once, but it won't allow me to open another one once I close the first.
If you see anything wrong with this, please tell me what it is.
from the Input class
[CODE]private void Input_FormClosed(Object sender, FormClosedEventArgs e)
{
Mb.formexists = false;
}
[/CODE]
from the Mandelbrot class
[CODE]if (keybState.IsKeyDown(Keys.Q))
{
if (!formexists)
{
InputForm = new Input();
InputForm.Show();
InputForm.Mb = this;
formexists = true;
}
}[/CODE][/QUOTE]
Make sure Input_FormClosed is actually registered with the FormClosed event. Make sure your code gets run (in the second example; as you're hiding the context), you can for example set breakpoints or use MessageBox.Show.
But maybe what you really want is a dialog window - instead of Form.Show, you can use Form.ShowDialog: while the new form is open the old one can't receive focus. Only when the dialog closes can the parent window be used.
Lastly, the public Mb variable is a pretty bad way of passing it around. You should receive it as a parameter in the constructor and store it internally for later use, other objects shouldn't know about it.
Exceptions are one of those things I never bothered to teach myself, but now I'm wondering if they will be useful.
Basically my situation is:
[code]for i in 1..200
methodThatSometimesCrashes(i)
end
[/code]
methodThatSometimesCrashes crashes for certain values of i. However, if it does crash I want the program to say that it crashed for that i and then continue on to the next value of i. Is this sort of thing possible with exceptions?
Yes, but exceptions are slow to handle, which isn't a problem because exceptions aren't meant to be thrown often; but if you use them wrong then you might end up with some awfully slow code.
You could have two functions part of your interface, one returning a bool whether or not the given number is valid input, the other doing the actual operation on that number. The latter could call the former and throw an exception if the user forgot (or intentionally left out) validation of the input. That way you get the best of both worlds: when you're only doing the operation now and then in between other, more important code, an exception would be thrown for bad input, immediately signaling an error that may or may not be a fixable logic error. At the same time, you can still do the operation in a big loop without a big performance loss by constantly throwing and catching exceptions by using the separate validation method.
edit:
If you tell us what programming language you are using, I can show you how to work with exceptions if you're unsure.
[QUOTE=jA_cOp;21582840]You could have two functions part of your interface, one returning a bool whether or not the given number is valid input, the other doing the actual operation on that number.[/QUOTE]
That isn't possible, unfortunately. The method in question processes numerical examples for my research and these examples tend to behave somewhat erratically. So there's really no way of knowing ahead of time which inputs will cause it to crash.
Speed is kind of an issue though. As it is, it often takes several hours for my program to chew through all of the data I throw at it. Still, there doesn't seem to be a way around it, so I guess I'll give exceptions a try.
[b]Edit:[/b] I'll be more specific. Here's what's causing the method to crash (the language is Ruby)
[code]
@expansion[i] = ((x[i] + y[i] * Math.sqrt(d)) / z[i]).to_i
[/code]
The error I'm getting is "Bignum out of Float range". I think that the problem is that x[i],y[i], and z[i] can be extremely huge integers but Math.sqrt(d) is a float - so it tries to convert them to floats in order carry out the operations but they're too big. I have no idea how to get around this problem.
[QUOTE=Larikang;21583347]The method in question processes numerical examples for my research and these examples tend to behave somewhat erratically. So there's really no way of knowing ahead of time which inputs will cause it to crash.[/QUOTE]
You need to identify the problem to get anywhere with this. Although in some languages stuff like access violations are thrown as exceptions, you don't seem to know what even causes the "crash". You can't throw exceptions on your own without knowing that there is a problem.
[editline]05:04PM[/editline]
[QUOTE=Larikang;21583347][b]Edit:[/b] I'll be more specific. Here's what's causing the method to crash (the language is Ruby)
[code]
@expansion[i] = ((x[i] + y[i] * Math.sqrt(d)) / z[i]).to_i
[/code]
The error I'm getting is "Bignum out of Float range". I think that the problem is that x[i],y[i], and z[i] can be extremely huge integers but Math.sqrt(d) is a float - so it tries to convert them to floats in order carry out the operations but they're too big. I have no idea how to get around this problem.[/QUOTE]
Use Bigdecimal instead of Bignum.
I am a bit new to forms in c#, so I created a little neural net class and I wanted to try it out. Finally found out how to draw things in a image box using the paint method, only when I use that method to update my neural network it just shows as a red cross any help on that ?
I'm coding in java, and for some reason I'm getting errors when initializing my array.
[code]
int identification[] = 1;
identification = new int[1];
[/code]
Error info
[code]
H:\5-8\Chapter07\HFCHD.java:33: <identifier> expected
identification = new int[1];
^
1 error
Tool completed with exit code 1
[/code]
Just guessing but isn't it :
[code]
int[] Array;
Array = new int[1];
Array[0] = 1;
[/code]
You're assigning 1 to the array.
[QUOTE=nullsquared;21612724]You're assigning 1 to the array.[/QUOTE]
oh hurr i forgot to delete =1
thanks
Sorry, you need to Log In to post a reply to this thread.