Showing posts with label C#. Show all posts
Showing posts with label C#. Show all posts

Saturday, 14 April 2012

C#: Multilingual application

This is all about developing an application which supports multiple languages.
So that, you need two or more resource files as you need. These files hold the translations corresponding to languages.
As shown bellow figure, you can add resource files to your application. (C#.NET 2005).

Wednesday, 11 April 2012

C# :Count the total number of lines in RichTextBox

All you have to use is RichTextBox.GetLineFromCharIndex method.

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.
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  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
sbyteSystem.Sbyte -128 to 127Signed 8-bit number
byteSystem.byte 0 to 255Unsigned 8-bit
number
shortSystem.Int16 -32.768 to 32.767Signed 16-bit number
ushortSystem.UInt16 0 to 65.535Unsigned
16-bit number
intSystem.Int32 -2.147.483.648 to
2.147.483.647
Signed 32-bit
number
uintSystem.UInt32 0 to 4,294,967,295Unsigned
32-bit number
longSystem.Int64 –9,223,372,036,854,775,808
to
9,223,372,036,854,775,807
Signed 64-bit
number
ulongSystem.UInt64 0 to
18,446,744,073,709,551,615
Unsigned
64-bit number
charSystem.Char U0000 to UffffA single 16-bit
Unicode character
floatSystem.Single 1.5x10-45 to 3.4x103832-bit floating
point number
doubleSystem.Double 5.0x10-324 to 1.7x1030864-bit floating
point number
boolSystem.Boolean true or falseRepresents
truth or falsity
decimalSystem.Decimal 100 to 1028A 96-bit signed
number
stringSystem.String Limited by system memoryRepresents a
set of Unicode
characters
objectSystem.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[^]
    
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[^]