Posts Tagged ‘C#’

How to auto scroll to the bottom of a multiline TextBox in C# ?

At least in .NET 2.0, the TextBox control doesn’t have a property to let the TextBox automatically scroll to the bottom when it is set to multiline. You have to write code like this: textBox1.Text += “Test string \n”;textBox1.Update();textBox1.SelectionStart = textBox1.Text.Length;textBox1.ScrollToCaret(); OR, you can use the following code: textBox1.AppendText(“This is a test string \n”);textBox1.SelectionStart = [...]

Comments (1)

BitConverter (.NET): int to array, array to int

The following sample copied from Microsoft:以下例子来自于微软 // Example of BitConverter class methods.using System; class BitConverterDemo{ public static void Main( ) { const string formatter = “{0,25}{1,30}”; double aDoubl = 0.1111111111111111111; float aSingl = 0.1111111111111111111F; long aLong = 1111111111111111111; int anInt = 1111111111; short aShort = 11111; char aChar = ‘*’; bool aBool = true; Console.WriteLine( [...]

Leave a Comment

.NET Marshal.Copy的一个应用(A sample of Marshal.Copy)

Marshal.Copy在对有C++代码和C#代码混合的项目中很有用,它能在非托管指针和托管数组间起到相互转换作用。 Namespace: System.Runtime.InteropServices Assembly: mscorlib (in mscorlib.dll) Copies data from a managed array to an unmanaged memory pointer, or from an unmanaged memory pointer to a managed array. 把数据从一个托管的数组拷贝到一个非托管的内存指针, 或从一个非托管的内存指针拷贝到一个托管的数组。 Marchal.Copy有很多形态,其四个参数有很多类型变化: Copy(array<Byte>[]()[], Int32, IntPtr, Int32) Copy(array<Char>[]()[], Int32, IntPtr, Int32) Copy(array<Double>[]()[], Int32, IntPtr, Int32) Copy(array<Int16>[]()[], Int32, IntPtr, Int32) Copy(array<Int32>[]()[], Int32, IntPtr, Int32) Copy(array<Int64>[]()[], Int32, IntPtr, Int32) [...]

Leave a Comment

C# 中的委托和事件

C# 中的委托和事件 PDF版浏览: http://www.cnblogs.com/Files/JimmyZhang/Delegates-and-Events-in-CSharp.pdf 更新记录: 2007年 9月28日:事件的由来 引言 委 托 和 事件在 .Net Framework中的应用非常广泛,然而,较好地理解委托和事件对很多接触C#时间不长的人来说并不容易。它们就像是一道槛儿,过了这个槛的人,觉得真 是太容易了,而没有过去的人每次见到委托和事件就觉得心里别(biè)得慌,混身不自在。本文中,我将通过两个范例由浅入深地讲述什么是委托、为什么要使 用委托、事件的由来、委托和事件对Observer设计模式的意义、.Net Framework中的委托和事件,对它们的中间代码也做了讨论。

Leave a Comment

Call Javascript function from codebehind C#

How to call a javascript function from ASPX.cs code behind file? Set the Body tag in your page/master page to runat=”server” and an id=”MainBody”. Put the script tag in your page like you normally would with any HTML file <script src=”popup.js”  type=”text/javascript”></script> Then in the code behind attach the onload attribute to the body tag [...]

Leave a Comment