|
Application.Exit will nit work inside the constructor, because Application.Run wasn't executed yet. If you look at the static Main method of your application it looks similar to this:
static void Main()
{
Applivation.Run(new MainForm());
}
So what happens, is that an instance of the MainForm class is created (calling your constructor) and afterwards passed to the Application.Run method. That's why Application.Exit does not work inside the constructor.
It would probably be the best to assign the instance of MainForm to a variable and only call Application.Run, if your MainForm could be properly initialized:
static void Main()
{
MainForm form = new MainForm();
if (something)
{
Applivation.Run(form);
}
else
{
Show some kind of error message
}
}
"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." - Rick Cook www.troschuetz.de
|
|
|
|
|
Thanks very much - I've learn't heaps tonight.
Glen Harvy
|
|
|
|
|
My pleasure
"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." - Rick Cook www.troschuetz.de
|
|
|
|
|
i want to make my event in win form
using c#.i have created it but
the problem is that the event is not firing.
so i need your help.
i created these events by taking help of
vb.net program.
ashu
|
|
|
|
|
What event? and give us some code
|
|
|
|
|
What do you mean by not Firing... It's not meant to fire auto... You are required to do it explicitly.
|
|
|
|
|
You need to explain what you mean by 'not firing', and you need to explain how your code is working between VB and C#, probably by posting some code.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
Hi! I am new to C# programming and have run into a roadblock. I don't know how to get it to count the number of months needed to pay off the loan. Here is what I have so far:
//declare variables
double loanAmount;
double interestRate;
double monthlyPayment;
double balance;
double monthlyPrincipalPayment;
int monthCounter;
double totalInterestPaid;
//initialize variables
loanAmount = 0;
interestRate = 0;
monthlyPayment = 0;
balance = 0;
monthlyPrincipalPayment = 0;
monthCounter = 0;
totalInterestPaid = 0;
//input statements
Console.WriteLine("Enter loan amount: ", loanAmount);
loanAmount = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Enter monthly interest rate in decimal format: ", interestRate);
interestRate = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Enter monthly payment: ", monthlyPayment);
monthlyPayment = Convert.ToDouble(Console.ReadLine());
//calculate monthly principal payment
monthlyPrincipalPayment = balance - (interestRate * loanAmount);
//calculate the total interest paid
totalInterestPaid = totalInterestPaid + (loanAmount * interestRate);
//calculate the total number of months to pay off interest
//while loop
while (balance > 0)
{
//count the number of months
monthCounter++;
//calculate balance each month
balance = balance - monthlyPayment;
}
//display the total interest paid
Console.WriteLine("You paid $ " + totalInterestPaid + " in interest");
//display the total number of months it took to pay loan
Console.WriteLine("It took " + monthCounter + " months to pay off your loan.");
|
|
|
|
|
Hi,
Your logic is flawed? You cannot calculate the interest on the whole of the loan unless you know how long they want the loan for. Therefor your program, as it is written, will go into an infinite logical loop as the balance will never be paid.
You will need to decide when you are going to calculate and charge interest. It seems the following is what you are suggesting:
Initial Loan $10,000 (for example)
Interest rate is fixed.
Interest is charged on daily outstanding balance and is included in the fixed repayment offered.
Repayments will be fixed each month (be careful here as you will create another infinite loop if the payment is insufficient to cover principal and interest).
psuedocode is:
While (BalanceOutstanding > 0)
{
count++; // whatever your counter is
BalanceOutstanding = (BalanceOutstanding * Rate / 12) - Payment; // psuedocode
}
You would be better of not using a While statement to calculate the months - use maths (used to be called algebra when I went to school ). Google for the appropriate formulae.
Cheers,
Glen Harvy
|
|
|
|
|
The problem is I am supposed to use the while loop to decrease the loan amount until it gets to 0. Thanks for your help.
Fatimah
|
|
|
|
|
I'm making a program that has a simple link-checker in it, and it makes Google and ASP.net sitemaps as well. I want it to be able to crawl a site on the web. Right now it works against local copies of a web site, and does very nicely finding broken links and making sitemaps. You can find a beta here:
http://www.smoothjazzy.com/jazzy_sitemap.html[^]
Anyway, I'm having a problem when I make requests for HTTP locations. If the file is local, I just check for it on the hard drive, but if it's an absolute URL, then I do this:
<br />
WebClient browser = new WebClient();<br />
UTF8Encoding enc = new UTF8Encoding();<br />
try {<br />
string fileContents = enc.GetString(browser.DownloadData(test_url));<br />
c_url.found = true;<br />
} catch (Exception exc) {<br />
current_report_builder.Append("***** Broken Link<br />
....etc....<br />
When I do this it executes server-side codes just fine of course, but sometimes there are javascripts on pages, such as my site above, which generate links. I want to be able to scan those links as well. Right now they show up as broken links because they are generated by javascript document.write commands.
Does anyone know how I can ammend this code to run client-side javascripts so I can see the "final rendering" of the page? I thought of possibly doing it with an invisible browser control, but I'd rather not...
I have searched Google and these forums and a few dark corners I know about, but nobody seems to know anything about this... If you can find it somewhere, please tell me what search terms you used, cuz I'm getting shlock
|
|
|
|
|
Hi,
I am considering various obfuscators and protection systems and am considering .Net Reactor in view of it's performance and price.
If anyone has any recommendations/comments, I would appreciate the feedback.
Thanks.
Glen Harvy
|
|
|
|
|
Hi,
I am just trying to adapt the Extended Common Dialog Box
http://msdn2.microsoft.com/en-us/library/ms996463.aspx
to my needs. Now I have got two problems left:
1. I want this dialog ("GetOpenFileName" from ComDlg32.dll) to appear modal with my Windows-Forms application. It is dangerous that the user can open as many of these dialogs as he wants because the "Open File"-Button of the calling Form is always enabled... I am not very experiences in using Win32-dlls and I have no idea how to approach this problem.
2. If you are a bit familiar with the above msdn-example perhaps you can help me also with this: I changed the dialog to a multi-file-select dialog (adding the AllowMultiSelect-flag). As expected the dialog can only return a few files (as string like e.g.: 'C:\Programs\"test1.txt" "test2.txt"') as const int _MAX_PATH is by default set to only 270. So I changed it to 32768 bytes which is the maximum allowed value as I have learned. But when I now select more files in this dialog it returns nothing!???
Thanks in advance for any idea,
Alex
|
|
|
|
|
AlexZieg71 wrote: So I changed it to 32768 bytes which is the maximum allowed value as I have learned
That looks like the maximum allowed value for a signed short ( at a guess). MAX_PATH is set to the right value for a maximum path.
There are solutions on the web to extending an open file dialog in C#, I'd suggest finding one of those.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
Hi Christian,
I only found the solution that I am just working with and the "OpenFileDialogEx" on the CodeProject-pages. The problem with OpenFileDialogEx is that it only works for .NET 2.0 but I work with .NET 1.1.
Do you know another solution? Your answer makes me think that my 2 described problems are barely to solve.
Best Regards
Alex
|
|
|
|
|
OK, I found out the solution for my Problem #1 myself:
In the GetOpenFileName-Struct you can also define the owner of the form as an IntPtr. Assign the Handle of the "Owner-Form" to it and it´s done:
_ofn.hwndOwner = owner.Handle;
|
|
|
|
|
How to find a word in textbox?
thx
nemanja
|
|
|
|
|
textbox1.Text gives you the text, the string class contains methods for finding text within strings.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
Can you write me some example plz!
thx
nemanja
|
|
|
|
|
When people ask trivial questions, that google could answer in seconds, I tend to provide some keywords, because it's really important for someone who wants to be a developer, to be able to do some research for themselves. Given what I told you, intellisense should be all you need to solve the problem.
The methods that search for the index of a substring, return -1 if they don't find it.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
if you want to implement some search functionality, defintely there must be some buch of text that will occupy the controll. right.. then go for richtextbox instead of textbox. That is having inbuilt function for "find"
This is my suggestion.. otherwise you hav to implement the logic to do so.
|
|
|
|
|
I want to fill my combo box with alphabet
nemanja
|
|
|
|
|
And ?
------------------------------ "The Soapbox has been so ..."
|
|
|
|
|
Automaticly!!
Not Manual!
nemanja
|
|
|
|
|
Create a custom control. Then you only have to create it once.
|
|
|
|