Showing posts with label C#. Show all posts
Showing posts with label C#. Show all posts
Saturday, 14 April 2012
Wednesday, 11 April 2012
C# :Count the total number of lines in RichTextBox
All you have to use is RichTextBox.GetLineFromCharIndex method.
You will find more detailed explanation here:
GetLineFromCharIndex[^]
Here is complete example of counting total number of lines in RTB
int lineNumber = richTextBox1.GetLineFromCharIndex(richTextBox1.TextLength) + 1; MessageBox.Show(lineNumber.ToString());This 2 lines of code will give you number of lines in RichTextBox
You will find more detailed explanation here:
GetLineFromCharIndex[^]
Here is complete example of counting total number of lines in RTB
Saturday, 7 April 2012
C#: Read from excel file
I used .NET 2.0 framework. Reading from excel file is depends on excel's version, not entirely but it will affect your source code little bit.
Here is little tip about reading excel file.
This function accepts 2 arguments which are describe excel file's name, and it's version.
If you are using excel 2007 then send true as a second argument, or else send false when you call this function.
Here is little tip about reading excel file.
string mFileName; // file name which you will read from. System.Data.OleDb.OleDbConnection connection; string mSheetName; // excel file consists of many sheets / pages. System.Data.OleDb.OleDbDataAdapter dtAdapter;Reading from excel file is as same as reading from database, so that you will need connection string which helps you to connect your program to excel sheets, as well as dataAdapter which will retrieve data from excel sheet.
This function accepts 2 arguments which are describe excel file's name, and it's version.
If you are using excel 2007 then send true as a second argument, or else send false when you call this function.
C#: Read from command Prompt
I've been trying to read from Command prompt using c#. My application supposed to read lines from cmd whatever it shows. My Purpose was developing code editor and using external compiler.
You need to use
You need to use
System.Diagnostics.Process(System.Diagnostics.ProcessStartInfo).
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo("file.exe", "command");
startInfo.RedirectStandardError = true;
startInfo.RedirectStandardOutput = true;
startInfo.StandardOutputEncoding = //change if you need, you might need it
startInfo.StandardErrorEncoding = //change if you need, you might need it
//...Using this example,
file.exe could be any executable file and command, it should be related to exe file. In this example, file.exe is "cmd.exe" and "command" is "RUNCOB"Wednesday, 7 December 2011
C#: System data types
C# Shorthand | System Type | Range | Meaning in life |
| sbyte | System.Sbyte | -128 to 127 | Signed 8-bit number |
| byte | System.byte | 0 to 255 | Unsigned 8-bit number |
| short | System.Int16 | -32.768 to 32.767 | Signed 16-bit number |
| ushort | System.UInt16 | 0 to 65.535 | Unsigned 16-bit number |
| int | System.Int32 | -2.147.483.648 to 2.147.483.647 | Signed 32-bit number |
| uint | System.UInt32 | 0 to 4,294,967,295 | Unsigned 32-bit number |
| long | System.Int64 | –9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 | Signed 64-bit number |
| ulong | System.UInt64 | 0 to 18,446,744,073,709,551,615 | Unsigned 64-bit number |
| char | System.Char | U0000 to Uffff | A single 16-bit Unicode character |
| float | System.Single | 1.5x10-45 to 3.4x1038 | 32-bit floating point number |
| double | System.Double | 5.0x10-324 to 1.7x10308 | 64-bit floating point number |
| bool | System.Boolean | true or false | Represents truth or falsity |
| decimal | System.Decimal | 100 to 1028 | A 96-bit signed number |
| string | System.String | Limited by system memory | Represents a set of Unicode characters |
| object | System.Object | Any type can be stored in an object variable | The base class of all types in the .NET universe |
Tuesday, 19 April 2011
C# : Detecting cursor position in RichTextBox
When i was working on RichTextBox the main thing that i had to handle was counting lines and detecting cursor position. Now lets see how to get these things done. Let me tell you about how to detect cursor position.
You need to use:
RichTextBox.SelectionStart and RichTextBox.GetLineFromCharIndex()
But make sure you use instance method of RichTextBox class as show
here :GetLineFromCharIndex[^] and GetLineFromCharIndex[^]
You will find detailed explanation here:
DllImportAttribute[^]
You need to use:
RichTextBox.SelectionStart and RichTextBox.GetLineFromCharIndex()
But make sure you use instance method of RichTextBox class as show
here :GetLineFromCharIndex[^] and GetLineFromCharIndex[^]
private static int EM_LINEINDEX = 0xbb;
int index, line, col;
[DllImport("user32.dll")]
extern static int SendMessage(IntPtr hwnd, int message, int wparam, int lparam); [DllImport("user32.dll")]This line of code shouldn't be written in any method or functions.You will find detailed explanation here:
DllImportAttribute[^]
Subscribe to:
Posts (Atom)
