|
this is the way
<br />
private void button1_Click(object sender, EventArgs e)<br />
{<br />
int i;<br />
for (i = 0; i < 10; i++)<br />
{<br />
if (i == 5)<br />
goto skip;<br />
}<br />
skip:<br />
MessageBox.Show("i = " + i);<br />
}<br />
<br />
but this is not so robust
try this
<br />
private void button2_Click(object sender, EventArgs e)<br />
{<br />
int i;<br />
i = skip();
MessageBox.Show("i = " + i);<br />
}<br />
<br />
private int skip()<br />
{<br />
for (int i = 0; i < 10; i++)<br />
{<br />
if (i == 5)<br />
return i;<br />
}<br />
return 0;<br />
}<br />
|
|
|
|
|
I am developing a windows application in which I am calling a dialog window in a thread. When I minimize the Dialog, it not only minimize but also closes. Why it is showing this kind of behaviour?
The code i used is:
On Form1:
private void button1_Click(object sender, System.EventArgs e)
{
Thread td = new Thread(new ThreadStart(initiateForm2));
td.Start();
}
private void initiateForm2()
{
Demo frm2 = new Demo();
this.Hide();
frm2.ShowDialog();
}
On Form2:
private void btnMinimize_Click(object sender, System.EventArgs e)
{
this.Hide();
}
The problem is that when I hide the second form, it also call the Closing event of the Dialog form. It closes the dialog window. Why it is so?
Thanks,
Sandeep S. Sekhon
|
|
|
|
|
I guess this behaviour is caused by the fact that you show the second form as modal dialog. Use the Form.Show method to display the second form. Furthermore you should no longer need to do this inside an extra thread, so the whole thing cuts down to:
private void button1_Click(object sender, System.EventArgs e)
{
Demo frm2 = new Demo();
this.Hide();
frm2.Show();
}
"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
|
|
|
|
|
hello
i want to make report in my WinApp
i want to dispaly just One record at each page
plzzzzzzzzzzzzzzzzzzzzzzzzz
i want help give me an example to do that ...
Palestine
|
|
|
|
|
What kinf of reports are you talking about?
--------------------------------------------------------
My portfolio & development blog
Q:What does the derived class in C# tell to it's parent?
A:All your base are belong to us!
|
|
|
|
|
I have a datagrid view that has a number of cells that are readonly.
The default behavior of tabbing in a datagridview is to go to the next cell. What I'm looking to do is make it so that it skips readonly=true cells and goes to the next cell.
Here's my problem. No element(that I can find) within the datagridview has a tabstop property, so I need to handle the keypress event.
The problem I have is, I can't seem to catch it. I've tried handling datagridview.keypress, and even handling the EditingControlShowing event to assign a handler to the textboxes that make up the dgv to handle the tab.
So here's my question, has anyone done this themselves, or has any idea how to skip cells that are readonly in a datagridview?
|
|
|
|
|
Hello
If you have .Nt 2.0 you can handle PreviewKeyDown event which can catch the tab key, or handle the CellEnter event and shift the focus to the nearest non-readonly cell.
Regards
|
|
|
|
|
Hi,
How can i create and write to an xml file with C# the date and time in seperate tags to an xml file like this:
<root>
<date>ddMMyyyy<date>
<time>HH:mm:ss<time>
<root>
Thanks in advance!
|
|
|
|
|
Hello
In System.Xml namespace there are two classes: XmlReader and XmlWriter .
Use them to make the xml file and write the data to it.
Regards
|
|
|
|
|
Use the ToString method of the DateTime class to create the string representation of the date and the time.
As you have used the exact format that the ToString method uses, it's easy:
daDate.ToString("ddMMyyyy")
and
daDate.ToString("HH:mm:ss")
---
b { font-weight: normal; }
|
|
|
|
|
Using daDate.ToString("HH:mm:ss") is a risky choice as ":" is a placeholder for the time separator. Hence for example Italian regional settings would give something like "21.17.48" instead of "21:17:48". Even in a fixed region users could simply break the format by changing their regional settings. Always provide a IFormatProvider, typically CultureInfo.InvarientCulture. If you create your own CultureInfo instance to do the formatting, remember specifying "false" to disallow custom overrides.
I assume this is a fixed XML format that MUST be followed? If it is I guess you do not have a choice, but if it is in ANY way possible to influence the format do so, as it is basically as wrong as it can be.
When storing dates as strings there are two formats you can use: "yyyy-MM-dd" or wrong. "ddMMyyyy" clearly belongs in the "wrong" category as it is ambigious and it doesn't even sort correctly. When storing date and time, preferably write them into a single entry with the ISO format.
If you use the XmlSerializer, just serialize/deserialize a DateTime object and it will use the correct ISO format.
|
|
|
|
|
lmoelleb wrote: Using daDate.ToString("HH:mm:ss") is a risky choice as ":" is a placeholder for the time separator.
Yes, you are right. I didn't think of that.
The character should be quoted to be interpreted as a literal:
"HH':'mm':'ss"
As the format now contains no culture variant components, it's not affected by any cultural differences.
Using a format provider doesn't affect the output in this case, it's only encouraged for programming style. If no format provider is specified, the CultureInfo.CurrentCulture is used, as there exists no formatting without a format provider.
---
b { font-weight: normal; }
|
|
|
|
|
I assume that you already know how to write an XML output.
So to segregate the Dat and time, you can use the DateTime class to get the date and time seperate portions from the DateTime.Now
Just take out the time and date component from the supported methods
Excelsior
Arjun Bahree
"By The Might of Mjolnir"
I Came! I Coded! I Conquered!
|
|
|
|
|
Im not sure if this is the right place for this post, if not I apologize in advance this is my first time on the forum.
My question is - I am trying to write an Image Viewer program that reads the file paths from the file system and stores them in a list. Then it loads the first 25 images into an Image list(the 25 can be set to whatever I want.). That all works fine. The problem is when you get to the end of the 25 and its time to add more images. It works but is EXTREMELY slow. I cant seem to figure this out and have been playing with it for a while now. Any insight would be appriciated. Heres my code for adding to the buffer -
public void vScrollBar1_Scroll(object sender, ScrollEventArgs e) {
Thread addThread;
if(CurrentIndex <= BufferPadding / 2 + 1) {
CurrentIndex = vScrollBar1.Value;
PictureBox.Image = BufferedImageList[CurrentIndex];
} else {
if(CurrentIndex >= BufferPadding / 2 + 1 && CurrentIndex < ImagePathList.Count - 1) {
CurrentIndex = vScrollBar1.Value;
PictureBox.Image = BufferedImageList[BufferPadding / 2 + 1];
addThread = new Thread(new ThreadStart(AddToBuffer));
addThread.Start();
}
}
}
public void AddToBuffer() {
BufferedImageList.Add(DICOMImage.FromPath(ImagePathList[CurrentIndex]));
BufferedImageList[0].Dispose();
BufferedImageList.RemoveAt(0);
}
Thanks in advance
Brad
|
|
|
|
|
Hi there,
I have been trying to start some processes from my Windows service which is a multithreaded application and uses threadpool. I am able to start upto 24 processes (using ProcessInfo) but when the service try to start 25th an Application execption is logged in the eventlog:
Event Type: Error
Event Source: .NET Runtime
Event Category: None
Event ID: 0
Date: 9/8/2006
Time: 11:05:38 AM
User: N/A
Description:
The description for Event ID ( 0 ) in Source ( .NET Runtime ) cannot be found. The local computer may not have the necessary registry information or message DLL files to display messages from a remote computer. The following information is part of the event: .NET Runtime version 1.1.4322.573- .NET Framework Initialization Error: C:\WINNT\Microsoft.NET\Framework\v1.1.4322\mscorwks.dll could not be loaded.
I have tried setting maximum num of threads and IOCompletion threads using SetMaxThreads method exposed by ICorThreadPool interface, but no help.
Task manager shows threads count 20 and IO Write- 5 for the windows service.
Could it be appdomain or threadpool? Any helping comment much appreaciated.
Thanks,
|
|
|
|
|
Is it possible to create a system.data.datatable or dataset from an excel worksheet that is obtained using interop.excel in C#?
The code is as following. As you can see, I can read/modify certain cell, but is it possible to convert the table to a System.data.datatable? Or at least print out the select range in the excelworksheet?
protected void OpenExcelSpreadSheet(string input)
{
Excel.Application excelApp = new Excel.ApplicationClass();
excelApp.Visible = false;
Excel.Workbook newWorkbook =
excelApp.Workbooks.Add(XlWBATemplate.xlWBATWorksheet);
// The following code opens an existing workbook
object Missing = System.Reflection.Missing.Value;
string workbookPath= "myFile.xls";
Excel.Workbook excelWorkbook =
excelApp.Workbooks.Open(workbookPath,Missing,Missing,Missing,
Missing,Missing,Missing,Missing,Missing,Missing,Missing,Missing,Missing,Missing,Missing);
// The following gets the Worksheets collection
Excel.Sheets excelSheets = excelWorkbook.Worksheets;
// The following gets Sheet1 for editing
string currentSheet = "Sheet1";
Excel.Worksheet excelWorksheet = (Excel.Worksheet)excelSheets.get_Item(currentSheet);
// The following gets cell A1 for editing
Excel.Range excelCell = (Excel.Range)excelWorksheet.get_Range("A1", "A1");
excelCell.Value2 = input;
Excel.Range excelTable = (Excel.Range)excelWorksheet.get_Range("A1", "A27");
int noOfRow = excelTable.Rows.Count;
int noOfColumn = excelTable.Columns.Count;
Response.Write("Table has " + noOfRow + " rows and " + noOfColumn + " columns.
");
}
|
|
|
|
|
I want the functionality of converting digits into text. Any one give me code example or an article about that.
Example:
209
Two Hundred and Nine
thanks
"and Nader where are u i need u'r help"
-- modified at 14:42 Friday 8th September, 2006
Syed Shahid Hussain
|
|
|
|
|
Search this messageboard for 'eleventh' and'twelveth', there is a nice switch statement to deal with that, the rest will be easy.
|
|
|
|
|
Please give me some more detail or link to that article. Thanks
Syed Shahid Hussain
|
|
|
|
|
tell me more friend. I am waiting.
Please
leppie wrote: Search this messageboard for 'eleventh' and'twelveth'
What do you mean by that
Thanks
Syed Shahid Hussain
|
|
|
|
|
Hello friend
Syed Shahid Hussain wrote: I am waiting.
No need. I'm working on it, and I'll post the code when I'm finished. Already half the way.
Regards
|
|
|
|
|
Hello friend.
Here is your code. I hope you like it;).
It consists of 3 methods. You call the ToLiteral() method and supply it with the string you want to parse. It will subsequently call the other two methods to retreive the literals and the segments names. Forgive me for the poor comment -never been good in commenting-. I included a button click even handler to show you how to test for output and how to use the ToLiteral() method.
private void TestButton_Click(object sender, EventArgs e)
{
MessageBox.Show("4\n" + ToLiterals("4"));
MessageBox.Show("57\n" + ToLiterals("57"));
MessageBox.Show("209\n" + ToLiterals("209"));
MessageBox.Show("8734\n" + ToLiterals("8734"));
MessageBox.Show("24567\n" + ToLiterals("24567"));
MessageBox.Show("973654\n" + ToLiterals("973654"));
MessageBox.Show("2315736\n" + ToLiterals("2315736"));
MessageBox.Show("27065154\n" + ToLiterals("27065154"));
MessageBox.Show("827464876\n" + ToLiterals("827464876"));
MessageBox.Show("1675376283\n" + ToLiterals("1675376283"));
}
private string ToLiterals(string Input)
{
String Output = "";
while (Input.Length > 0)
{
if (Input[0] == '0')
{
Input = Input.Remove(0, 1);
Output += "And ";
continue;
}
if (Input.Length % 3 != 2)
{
Output += ConvertChar(Input[0].ToString());
if (Input.Length % 3 == 0 && Input.Length > 2)
Output += "Hundred ";
else
Output += GetSegment(Input.Length / 3);
Input = Input.Remove(0, 1);
continue;
}
else
{
if (Input[0] == '1')
{
Output += ConvertChar(Input.Substring(0, 2));
}
else
{
Output += ConvertChar(Input[0] + "0");
Output += ConvertChar(Input[1].ToString());
}
Output += GetSegment(Input.Length / 3);
Input = Input.Remove(0, 2);
}
}
return Output;
}
private string GetSegment(int seg)
{
switch (seg)
{
case 1: { return "Thousand "; }
case 2: { return "Million "; }
case 3: { return "Billion "; }
case 4: { return "Trillion "; }
default: { return ""; }
}
}
private string ConvertChar(string ToConvert)
{
switch (ToConvert)
{
case "1": { return "One "; }
case "2": { return "Two "; }
case "3": { return "Three "; }
case "4": { return "Four "; }
case "5": { return "Five "; }
case "6": { return "Six "; }
case "7": { return "Seven "; }
case "8": { return "Eight "; }
case "9": { return "Nine "; }
case "10": { return "Ten "; }
case "11": { return "Eleven "; }
case "12": { return "Twelve "; }
case "13": { return "Thirteen "; }
case "14": { return "Fourteen "; }
case "15": { return "Fifteen "; }
case "16": { return "Sixteen "; }
case "17": { return "Seventeen "; }
case "18": { return "Eighteen "; }
case "19": { return "Nineteen "; }
case "20": { return "Twenty "; }
case "30": { return "Thirty "; }
case "40": { return "Fourty "; }
case "50": { return "Fifty "; }
case "60": { return "Sixty "; }
case "70": { return "Seventy "; }
case "80": { return "Eighty "; }
case "90": { return "Ninety "; }
default: { return ""; }
}
}
PS.
It took me about 35mins to write and test the code. It may need some adjustments, but it should give you a good start.
Regards
|
|
|
|
|
Hi
So so thanks. I am so happy that you has given me the code and spend your time on me. I'll use it and send u feedback. Thank you very much.
(I cant imagine that some people are kind enough that they spend their precious time for others. I really appreciate you. I dont have words to thank U. Its my heart sound. By heart thanks alot. And dont mind if u dont like my talks. I am a simple boy and dont let any thing close in my heart, I say it at the spot.)
God Bless You.
Keep messaging,
Your friend
Syed Shahid Hussain
|
|
|
|
|
Hello
I'm always happy to help you .
See you soon on the forum.
Regards
|
|
|
|
|
Thanks friend,
Your code is so logical and it took my two hrs. for understanding it. How your made the logic in just 35 min. You are a true programmer. The code meet all my requirements and I'll use it in my Data Base program "as it is" without any changing. So thanks and so nice of you.
God Bless You
"If u read this plz send me your e-mail address."
Bye
Syed Shahid Hussain
|
|
|
|