How can I place a border around a PictureBox?
One solution is to use a panel that has a picturebox placed on it with DockStyle.Fill. This will make the picturebox assume the size of the panel. In addition, set the DockPadding.All property to the width of the desired border. Then in the Panel’s OnPaint method, call the baseclass and then paint the desired borders. Here are both VB and C# projects that illustrate how you might go about this. The derived PicturePanel class has properties that allow you to set the bordersize and color as well as the image that is to be displayed. This sample retrieves the image from an embedded resource. It also uses double buffering to minimize flashing as you resize the control.
How do I autosize the columns in my DataGrid so they always fill the the grid’s client area
If you add a DataGridTableStyle to your Datagrid, then you can use the ColWidth property of the GridColumnStyles to set the width of each column. To dynamically set these widths as the grid is resized, you can handle the SizeChanged event of the the DataGrid. In your handler, you can compute the width of each column by dividing the client width minus the width of the row header column by the number of columns. Now there are a couple of technical points. You have to adjust for a possible vertical scrollbar. And, you have to adjust things for possible integer rounding in the calculations. To handle this last problem, the attached samples (both VB and C#) apply the single computed width to all but the last column. And this last column is just given all the space left. This means the last column may differ in width from the other columns by a couple of pixels.
How do I programmatically set an image as Form’s Icon ?
You could do so as shown in the code below : [C#] Form form1 = new Form(); Bitmap bmp = imageList1.Images[index] as Bitmap; form1.Icon = Icon.FromHandle(bmp.GetHicon()); [VB.NET] Dim form1 As Form = New Form() Dim bmp As Bitmap = imageList1.Images(index) as Bitmap form1.Icon = Icon.FromHandle(bmp.GetHicon()) Please refer to the sample attached here that illustrates this.
How can I add items to the System Menu of a form.
To do this, you can use use iterop to access the GetSystemMenu and AppendMenu Win32 APIs. You also need to override the form’s WndProc method to catch and act on the menu message. This idea was posted in the Microsoft newsgroups by Lion Shi. Here are some sample projects.
How can I control the cursor over my DataGrid
One way you can do this is to derive the DataGrid and override its WndProc method to handle the WM_SETCURSOR method yourself. In your override, you can do hit testing to decide when you want to set the cursor, or when you want to call the base class and let it set the cursor. Here are sample projects (VB and C#) showing the technique. Public Class MyDataGrid Inherits DataGrid Private Const WM_SETCURSOR As Integer = 32 Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message) If m.Msg <> WM_SETCURSOR Then MyBase.WndProc(m) Else ’see if you want the cursor – in col 1, rows 2, 3, 4 Dim pt As Point = Me.PointToClient(Control.MousePosition) Dim hti As DataGrid.HitTestInfo = Me.HitTest(pt.X, pt.Y) If hti.Column = 1 AndAlso hti.Row > 1 AndAlso hti.Row < 5 Then Cursor.Current = Cursors.Hand ’if not, call the baseclass Else MyBase.WndProc(m) End If End If End Sub ’WndProc Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs) If Cursor.Current.Equals(Cursors.Hand) Then MessageBox.Show(”My MouseDown”) Else MyBase.OnClick(e) End If End Sub ’OnMouseDown End Class ’MyDataGrid