|
|
private void txtBody_TextChanged(object sender, eventArgs e)<br />
{<br />
if(tbWordwrap.Pushed)<br />
{<br />
int maxLength = 65;<br />
string[] tempArray = new string(txtBody.Lines.length);<br />
tempArray = txtBody.Lines;<br />
<br />
int Prevsel = txtBody.SelectionStart;<br />
string Op = "";<br />
<br />
bool change= false;<br />
<br />
for(int counter = 0; counter < tempArray.Length; counter++)<br />
{<br />
if (tempArray[counter].length > maxLength )<br />
{<br />
string[] Words = tempArray[counter].split(' ');<br />
int currentLineLength = 0;<br />
string currentLine = "";<br />
foreach(string currentWord in Words)<br />
{<br />
if(currentWord.length > 0)<br />
{<br />
if(currentWord.length >= maxLength)<br />
{<br />
Op += curreentWord.Insert(maxLength, "\r\n");<br />
break;<br />
}<br />
if (currentLineLength + currentWord.Length + 1 < maxLength) <br />
{ <br />
<br />
currentLine += " " + currentWord;<br />
currentLineLength += (currentWord.Length + 1); <br />
} <br />
else<br />
{<br />
<br />
Op +=currentLine.insert(currentLineLength,"\r\n);<br />
currentLine = currentWord;<br />
currentLineLength = currentWord.Length ; <br />
} <br />
<br />
}<br />
}<br />
if(currentLine != "")<br />
Op += currentLine;<br />
<br />
<br />
Prevsel++;<br />
change= true;<br />
}<br />
else<br />
{<br />
Op += tempArray[counter] + "\r\n";<br />
}<br />
}<br />
<br />
if(change)<br />
{<br />
txtBody.Text = Op;<br />
txtbody.SelectionStart = Prevsel;<br />
}<br />
}<br />
}<br />
<br />
<br />
Above code is for text editor in which a user can fix no. of characters in single line. If user fix to 65 char then in single line 65 character will appear.
Its working but having some problem,if user types a line
like: "This is trial message."
Now suppose the above character count are equal to 65, the code now supress the spaces in above line,
i.e it modify the line
like: "This is trial message."
It omits the spaces. How can i modify this code that it would also count the spaces, maxLength is variable for the no. of char in a line.
|
|
|
|
|
humdumof wrote: string[] Words = tempArray[counter].split(' ');
This removes the spaces. So, add one for every word you add, obviously.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hello,
I am developing C# form application.
I want to pass some user editable command line data to application before execution. So that i can read it before main() gets execute.
How can i pass these data and read it from my application.
Thanks.
Gajesh
|
|
|
|
|
static void Main(string[] args)
{}
where args is a string aray that has the command line arguments in it split by spaces.
Heres one of the articles you'll find right here on codeproject if you search ...
http://www.codeproject.com/csharp/Command_Line.asp[^]
|
|
|
|
|
thanks originSH,
But how end user will pass data from application exe?
I thought of editing the application properties(RClick on application icon -> propertry) but i couldn't find command line editor in any of the tab.
Thanks.
|
|
|
|
|
gajesh wrote: But how end user will pass data from application exe?
*from* the app ? You can pass data TO the app, on the command line.
gajesh wrote: I thought of editing the application properties(RClick on application icon -> propertry) but i couldn't find command line editor in any of the tab.
you can only edit the command line of a shortcut, not the app itself
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
gajesh wrote: But how end user will pass data from application exe?
Either by launching program from cmd or by modifying target which is on the shortcut tab of properties window
|
|
|
|
|
gajesh wrote: So that i can read it before main() gets execute.
Nothing happens before main gets executed. Your command line args are available from the Application object, however.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
I think you are talking about console application in c#
if u look at your main method
static void Main(string[] args)
{
//
// TODO: Add code to start application here
//
/// Added next line to print input on console
Console.WriteLine(args[0]);
}
it accepts array of string, this is area where u can pass values
e.g myapplication.exe parameter
Atul kumar
|
|
|
|
|
How Can i read and write to excel sheet
|
|
|
|
|
Take this as a starting point: http://www.bbv.ch/pdf_files/system_event/2005_XMLto%20Excel.pdf
Look for other posts here on CodeProject (there are quite a few).
To sum it up. you can use:
- XSLT (optional with an Excel XML Template file)
- csv files (easiest)
- Interop (search for Excel Interop assemblies)
- use third-party library
Happy programming
Urs
-^-^-^-^-^-
no risk no funk
|
|
|
|
|
Hi!
I've written a program in C# which is running stable for hours. Then, at some moment, I get the Windows Error Message "The program xy has encounterd a problem an has to close". What I did was writeing some information at different time stamps to a file. What is interesting: the file is filled with information AFTER the Error Message and the whole program still keeps running, only the output (multimedia things) is not shown anymore. So in my opinion I have a performance problem.
My question: Does anybody know how to get to the reason for such a Windows error. Can I catch such a Windows error or somehow suppress it?
Is there a possibility to free resources of Windows Form manual?
Kind regards
|
|
|
|
|
Seems like one of your threads exits unexpectedly whereas others continue to run.
First of all check your code, make sure all exceptions get caught and displayed or
logged (not Exception.Message but Exception.ToString()). Add a try-catch construct to
your Main method.
If this does not help, add logging to all your code so you can see which parts keep running,
and which dont; compare parts of the log that you consider normal with the final part, when
the anomaly has occurred.
|
|
|
|
|
IS it not possible to run this application under the debugger and wait for the debugger to catch this?
|
|
|
|
|
Thank you for your answers.
Of course it is possible to work with the debugger or with try/catch but in fact it does not help me because the error is not shown by the debugger. It is a Windows Error Message and that's the great problem.
|
|
|
|
|
Hi guys,
I need to develop a SQL syntax checker in C#, how do I go about doing that, I think there are two approaches, one is with RegEx and other is, I can create some customised SQL Dictionary which can be cross-checked whenever I enter some SQL statement in a text box.
Please help. I need some more ideas for this concept ?
|
|
|
|
|
SQL is simple enough that regex may work. However, not all combinations of SQL statements are valid SQL, so you probably need a more complex parser for it to really work.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
In the good old days we used lex, or flex for this purpose, eventually combined with yacc or bison. Now I don't know. You may google for keywords like parser generator or lexical analysis. No idea how these cooperate with C#
|
|
|
|
|
|
You may want to consider using Antlr[^]. It has grammars for various languages.
|
|
|
|
|
You will need a proper parser for that. Regex with suffice as a tokenizer, but not for grammar parsing. I suggest you go with something like: GPPG[^].
|
|
|
|
|
DataTable mytable = new DataTable();
This is the code. :->
Please elobrate what exactly you are looking for?
|
|
|
|
|
Hi,
If you are looking to create a new data table schema in VC# then below is the code:
DataTable dt = new DataTable("tblName");
dt.Columns.Add("Id", typeof(int));
dt.Columns.Add("Name", typeof(string));
dt.Columns.Add("Age", typeof(int));
dt.AcceptChanges();
If u need any thing specific, let me know.
|
|
|
|
|
He just told you how to do it in C#.
|
|
|
|