How do I create a dll/exe off a previously diassembled .il file?
You can create a dll/exe from the il file using the ilasm.exe utility. This utility is usually installed in the C:\WINNT\Microsoft.NET\Framework\v1.0.3705 (or the appropriate version no.) directory. If you want to run this utility via command line it would help if you add the above path to your Environment Path variable. Here is an example command line: // The .res resource file is optional ilasm TextProcessing.il /dll /output:TextProcessing.dll /resource:TextProcessing.res
What are the implications of using the Timer class in System.Timers as opposed to the Timer class in System.Windows.Forms
Be careful when using the Timer from System.Timers from within a Windows.Form application. Most methods in Windows Forms are not thread safe and can produce indeterminate results when called from another thread. In this case, System.Timers.Timer is much higher resolution and less affected by how busy your application is (since it doesn’t use the message pump) but it’s Tick event is fired from another thread. In order to be sure this works correctly, you’ll have to write the proper Control.Invoke code to marshal over to the thread the control was created on (the main thread) before you call methods on the control. So, in cases where you don’t need super-high-resolution and regular events to be fired, you’re much better off using System.Windows.Forms.Timer. It’s message pump is based (WM_TIMER) and will fire on the UI thread. (from [email protected] on microsoft.public.dotnet.framework.windowsforms)
How do I add support for custom scrolling to my own user control?
Windows Forms features a ScrollableControl. This will work in most cases where you know the exact dimensions of your control and scroll by pixel. See the MSDN Documentation for ScrollableControl for discussion how to use this control. Sometimes you may need more customized scrolling, for example if you implemented a text editor and you want to scroll lines and not pixels. For more customized scrolling you have to use PInvoke to access the Win32 ScrollWindow method. The following code shows how to enable access to the Win32 ScrollWindow method from your code. [StructLayout(LayoutKind.Sequential)] public struct RECT { public int left; public int top; public int right; public int bottom; public RECT(Rectangle rect) { this.bottom = rect.Bottom; this.left = rect.Left; this.right = rect.Right; this.top = rect.Top; } public RECT(int left, int top, int right, int bottom) { this.bottom = bottom; this.left = left; this.right = right; this.top = top; } } [DllImport(‘user32’)] public static extern bool ScrollWindow(IntPtr hWnd, int nXAmount, int nYAmount, ref RECT rectScrollRegion, ref RECT rectClip); void MyScrollFunc(int yAmount) { RECT r = new RECT(ClientRectangle); ScrollWindow(Handle, 0, yAmount, ref r, ref r); }
How do I control the position of the context menu when it is invoked via the keyboard?
Normally, the context menu will be shown at the center of the control when the keyboard is used to invoke the context menu of a control (Shift+F10, for example). You can customize the location as follows. Override WndProc in the grid and check if the Message.Msg is WM_CONTEXTMENU (0x007b) If so, check if the Message.LParam is -1, which means this was due to a keyboard message as opposed to the user right-clicking the mouse. Now, call the associated ContextMenu’s Show method explicitly at the selected row position. Make sure NOT to call the base class after showing the menu explicitly. protected override void WndProc(ref Message m) { if(m.Msg == 0x007B /*WM_CONTEXTMENU*/) { // LParam == -1 means that this is due to a keyboard message if((int)m.LParam == -1) { this.contextMenu.Show(); return; } } } [VB.Net] Protected Overrides Sub WndProc(ByRef m As Message) If m.Msg = 0x007B Then ’WM_CONTEXTMENU ’ LParam == -1 means that this is due to a keyboard message If (CType(m.LParam,Integer)) = -1 Then Me.contextMenu.Show() Return End If End If End Sub
In C++, the code ‘MyClass ht;’ creates an object ht on the stack frame. But in C#, this same code compiles, but gives a runtime error. Why
MyClass ht; does not create any object. Instead, it creates a variable (a reference) of type MyClass, and sets its value to null. No object is created. To create an object, you need to explicitly call the class constructor with a new. MyClass ht = new MyClass(); You can also use ht to refer to an instance of MyClass that has been created (with a new) at some other point in your code. MyClass myClass = new MyClass(); …… MyClass ht; …… ht = myClass; // both ht and myClass are references to the same object…