How can I make the datagrid have no currentcell
There appears to be no method to turn off a currentcell. When a cell is being edited, it is the TextBox embedded in the columnstyle that has the focus, and is displaying the highlighted text. You will notice in this situation, if you click the grid’s title bar above the column headers, this TextEdit control loses focus, and the datagrid appears to have no current cell. We can simulate this click from code, and use it to expose a method in our datagrid to SetNoCurrentCell. Below is some code to illustrate this idea. public class MyDataGrid : DataGrid { public const int WM_LBUTTONDOWN = 513; // 0x0201 public const int WM_LBUTTONUP = 514; // 0x0202 [System.Runtime.InteropServices.DllImport(‘user32.dll’)] static extern bool SendMessage(IntPtr hWnd, Int32 msg, Int32 wParam, Int32 lParam); public void SetNoCurrentCell() { //click on top left corner of the grid SendMessage( this.Handle, WM_LBUTTONDOWN, 0, 0); SendMessage( this.Handle, WM_LBUTTONUP, 0, 0); } } Here is some VB code. Public Class MyDataGrid Inherits DataGrid Public WM_LBUTTONDOWN As Integer = 513 Public WM_LBUTTONUP As Integer = 514 Shared _ Function SendMessage(hWnd As IntPtr, msg As Int32, wParam As Int32, lParam As Int32) As Boolean Public Sub SetNoCurrentCell() ’click on top left corner of the grid SendMessage(Me.Handle, WM_LBUTTONDOWN, 0, 0) SendMessage(Me.Handle, WM_LBUTTONUP, 0, 0) End Sub ’SetNoCurrentCell End Class ’MyDataGrid
How do I display the PrintPreview maximized and control its zooming
You can use the WindowState property of the PrintPreviewDialog class to bring the PrintPreview maximized. To handle zooming, the PrintPreviewDialog has a property, PrintPreviewControl. PrintPreviewControl owns a Zoom property that allows you to set the zoom factor of the PrintPreview.
How can I load an embedded rich text file into a richtextbox
You use the LoadFile method of the RichTextBox, passing it a streamreader based on the resource. So include your RTF file as an embedded resource in your project, say RTFText.rtf. Then load your richtextbox with code such as Stream stream = this.GetType().Assembly.GetManifestResourceStream(‘MyNameSpace.RTFText.rtf’); if (stream != null) { StreamReader sr = new StreamReader(stream); richTextBox1.LoadFile(stream, RichTextBoxStreamType.RichText); sr.Close(); } Here is a VB snippet. Depending on your default namespace settings, you may not need explicit reference to the namespace in the GetManifestResourceStream argument. Dim stream As Stream = Me.GetType().Assembly.GetManifestResourceStream(‘MyNameSpace.RTFText.rtf’) If Not (stream Is Nothing) Then Dim sr As New StreamReader(stream) richTextBox1.LoadFile(stream, RichTextBoxStreamType.RichText) sr.Close() End If
How do I check the state of the virtual keys, Caps lock for example?
If the Control.ModifierKeys doesn’t address your issue, then use Platform Invoke and call GetKeyState directly. Declare this class first: [ ComVisibleAttribute(false), SuppressUnmanagedCodeSecurityAttribute() ] internal class NativeMethods { [DllImport(‘user32.dll’, CharSet=CharSet.Auto, ExactSpelling=true, CallingConvention=CallingConvention.Winapi)] public static extern short GetKeyState(int keyCode); public static int HIWORD(int n) { return ((n >> 16) & 0xffff/*=~0x0000*/); } public static int LOWORD(int n) { return (n & 0xffff/*=~0x0000*/); } } Then when you want to check if Caps is down or ON, call: short state = NativeMethods.GetKeyState(0x14 /*VK_CAPTIAL*/); bool capsKeyDown = NativeMethods.HIWORD(state); bool capsKeyON = NativeMethods.LOWORD(state);
How can I have a form with no title bar, but yet keep the resizing borders
Set your form’s Text and ControlBox properties. myForm.Text = ”; myForm.ControlBox = false;