|
EliottA wrote: I never ran into a problem like that before
That's probably because it's not that usual to divide two literal values. Usually one of the operands is a double variable, then the compiler will cast the other operand to double also.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Being a bit anal about this, I'd do this:
double tf = double.Parse(textBox1.Text);
double tc = 5d / 9d * (tf - 32d);
label1.Text = tc.ToString();
Regards,
Rob Philpott.
|
|
|
|
|
Oh, that's fascinating! Placing a 'd' after a whole number will really make it a double?
|
|
|
|
|
Yep, although I never really have ever used it. I'd rather put 5.0 or something of the sort.
|
|
|
|
|
will 5.0 def making it a double as opposed to float?
Im not trying to correct, seroius question
My opinion is... If someone has already posted an answer, dont post the SAME answer
|
|
|
|
|
From my recollection yes it will, the default is always double unless explicitly indicated otherwise.
|
|
|
|
|
My opinion is... If someone has already posted an answer, dont post the SAME answer
|
|
|
|
|
Hi All,
I have an application which calls a number of different child form for different processes.
These forms are mainly displayed with the ShowDialog() method as they require the user to enter data before doing anything else.
Now the problem is sometimes (not very often) when the child 'dialog' form is finished with, either by setting DialogResult to 'OK' or to 'Cancel' and then calling this.Hide(), the parent form will not be visible. The form is still present in the taskbar, so a quick minimise then maximise will show it once again, but clearly this is not acceptable.
If anyone has experienced this problem or can offer an explaination, I would be greatful.
But please remember its not a common occurances, and if you offer a simple solution such as try setting the parent form to visible everytime as safety measure, I cannot test so easily and would much prefer an explaination if possible.
Of course saying that, if someone can say they have had experience with the problem and have solved with no more issues without knowing a reason behind, I would be happy with that as a solution - atleast for now
Thanks
My opinion is... If someone has already posted an answer, dont post the SAME answer
|
|
|
|
|
You're calling this.Hide() to hide the dialog - not the parent form - if I understood correctly.
You should use ChildForm.Hide() since the this keyword
points back to the parent form.
Kristian Sixhoej
"You can't undo the past... but you can certainly not repeat it." - Bruce Willis
|
|
|
|
|
this.Hide() is inside the child form itself.
Basically there are 2 buttons (Confirm and Cancel) within the child form
Confirm has event code such as:
this.DialogResult = DialogResult.OK;
if(CheckValid())
this.Hide();
Cancel has event code such as:
this.DialogResult = DialogResult.Cancel;
this.Hide();
My opinion is... If someone has already posted an answer, dont post the SAME answer
|
|
|
|
|
I think my best option is to repost this exact problem in a bout an hour, surely no one will remember it by then hahaha.... (Note to self; stop typing everything you think)
My opinion is... If someone has already posted an answer, dont post the SAME answer
|
|
|
|
|
Answer seems to be that using this.Close() instead of this.Hide() seems to solve the issue.
i didnt use .Close() as i assumed that it would dispose of any properties i need to use but this does not appear to be the case
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
so i am writing a simple app to get the hang of .net and winforms... if i write some common functions as part of my "program" class how can i call them from a form? in mfc if was easy to get a ref to the app object and call from there but so far im not fining the equivalent here
any help appreciated
"mostly watching the human race is like watching dogs watch tv ... they see the pictures move but the meaning escapes them"
|
|
|
|
|
If i understand your question properly you can just use static functions, no?
My opinion is... If someone has already posted an answer, dont post the SAME answer
|
|
|
|
|
I wasn't sure about his question either, is he trying to execute code from an event on a form or..?
|
|
|
|
|
Not sure, from the question thou I gather its just calling a method within the Program class, which itself is a static class.
Personally if I have alot of common functions such as conversion algorithms or something, i just have a static 'Function' and call them whenever and whereever needed
My opinion is... If someone has already posted an answer, dont post the SAME answer
|
|
|
|
|
thats kinda what i'm doing and was wondering if thats "ok in .net" so to speak
"mostly watching the human race is like watching dogs watch tv ... they see the pictures move but the meaning escapes them"
|
|
|
|
|
Yeah, I dont see why you shouldnt do it.
But as i said, prob best in another static class and leave the main Program class to do just what it needs, of course if you ever need login or splash screens, then you might be adding to the Program class
My opinion is... If someone has already posted an answer, dont post the SAME answer
|
|
|
|
|
sweet! thnx a lot
"mostly watching the human race is like watching dogs watch tv ... they see the pictures move but the meaning escapes them"
|
|
|
|
|
Dont do any coding in the "Program" class for now.
The "Program" class has the Main method which in turn runs an instance of your Form.
Application.Run(new Form1());
The above line takes the control to the constuctor of Form1
public Form1()
{
InitializeComponent();
}
So if you write any method you can run them here for a start
public Form1()
{
InitializeComponent();
MyMethod()
}
|
|
|
|
|
Hi,
all methods are part of one class or other; there are no global methods.
A public static method is called by ClassName.MethodName(parms) .
A public non-static method is called by MyClassInstance.MethodName(parms) .
You normally pass MyClassInstance to whomever is interested, and/or you define an interface (which promises availability of some methods, but does not specify a particular class implementing them),
or, best of all, you pass a delegate (that is how you keep dependencies low).
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
modified on Friday, June 10, 2011 11:39 AM
|
|
|
|
|
got it thnx ... i was still in web world (where i've been for too long it seems) where most member functions are public by default ... these were private by default so making them public worked
"mostly watching the human race is like watching dogs watch tv ... they see the pictures move but the meaning escapes them"
|
|
|
|
|
so a question about general approaches...
in a desktop app (winforms say) is it better to open and close database connections with each form as it loads / unloads OR is it better to open a connection when the app starts and leave it open for the duration?
this is a low volume scenario with no more than 50 users expected simultaneously fyi
thnx
"mostly watching the human race is like watching dogs watch tv ... they see the pictures move but the meaning escapes them"
|
|
|
|
|
You could do either. I think the general approach is to create a connection each time because of something called Connection Pooling which is a cache of connections.
Either way, you want to seperate your DB calls from you GUI code - this is a good abstraction. Wrap up the DB access stuff in a Data Access Layer.
Regards,
Rob Philpott.
|
|
|
|
|
ok cool thnx ... when you say separate the db calls do you mean the open / close connection stuff or even further and use a whole class for the data calls for each form?
my approach would be to use stored procs / views and call them from the code ... is that not good?
thnx again
"mostly watching the human race is like watching dogs watch tv ... they see the pictures move but the meaning escapes them"
|
|
|
|