How can I make a ReadOnly TextBox ignore the mousedowns so that you cannot scroll the text or set the cursor

You can do this by deriving the TextBox, overriding the WndProc method and ignoring these mousedowns. [C#] public class MyTextBox : TextBox { protected override void WndProc(ref System.Windows.Forms.Message m) { // WM_NCLBUTTONDOWN WM_LBUTTONDOWN if(this.ReadOnly && (m.Msg == 0xa1 || m.Msg == 0x201)) { return; //ignore it } base.WndProc(ref m); } } [VB.NET] Public Class MyTextBox Inherits TextBox Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message) ’ WM_NCLBUTTONDOWN WM_LBUTTONDOWN If Me.ReadOnly AndAlso(m.Msg = &HA1 OrElse m.Msg = &H201) Then Return ’ignore it End If MyBase.WndProc(m) End Sub ’WndProc End Class ’MyTextBox

In an MDI application, the MDI child’s MaximumSize and MinimumSize properties don’t seem to take effect. How can I restrict the size of my MDI child?

It appears that this behavior is a bug that will be corrected in a future .NET release. You can control the size of your child form by adding a Layout event handler for it. Here is a code snippet that imposes the minimum size that you set in its properties. You can also handle it by overriding the form’s WndProc method as explained in this Microsoft KB article. [C#] private void Document_Layout(object sender, System.Windows.Forms.LayoutEventArgs e) { if(this.Bounds.Width < this.MinimumSize.Width) this.Size = new Size(this.MinimumSize.Width, this.Size.Height); if(this.Bounds.Height < this.MinimumSize.Height) this.Size = new Size(this.Size.Width, this.MinimumSize.Height); } [VB.NET] Private Sub Document_Layout(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LayoutEventArgs) Handles MyBase.Layout If (Me.Bounds.Width < Me.MinimumSize.Width) Then Me.Size = New Size(Me.MinimumSize.Width, Me.Size.Height) End If If (Me.Bounds.Height < Me.MinimumSize.Height) Then Me.Size = New Size(Me.Size.Width, Me.MinimumSize.Height) End If End Sub

How can I use events to restrict key input to grid cells

If you make sure your DataGrid is using a DataGridTableStyle, then you can access the TextBox through the GridColumnStyles collection and hook the event there. Here is some code…. [C#] //in formload this.dataGrid2.DataSource = this.dataSet11.Customers; // set the data source //make sure grid has a tablestyle DataGridTableStyle ts = new DataGridTableStyle(); ts.MappingName = this.dataSet11.Customers.TableName; this.dataGrid2.TableStyles.Add(ts); //now we can wire up wire up events for columns 1 and 4 …. DataGridTextBoxColumn tbc = (DataGridTextBoxColumn)ts.GridColumnStyles[0]; tbc.TextBox.KeyPress += new KeyPressEventHandler(CellKeyPress); tbc = (DataGridTextBoxColumn)ts.GridColumnStyles[3]; tbc.TextBox.KeyPress += new KeyPressEventHandler(CellKeyPress);….. //the handler private void CellKeyPress(object sender, KeyPressEventArgs e) { //don’t allow 1’s if(e.KeyChar == ’1’) e.Handled = true; } [VB.NET] ’in formload Me.dataGrid2.DataSource = Me.dataSet11.Customers ’ set the data source ’make sure grid has a tablestyle Dim ts As New DataGridTableStyle() ts.MappingName = Me.dataSet11.Customers.TableName Me.dataGrid2.TableStyles.Add(ts) ’now we can wire up wire up events for columns 1 and 4 …. Dim tbc as DataGridTextBoxColumn = CType(ts.GridColumnStyles(0), DataGridTextBoxColumn) AddHandler tbc.TextBox.KeyPress, AddressOf CellKeyPress tbc = CType(ts.GridColumnStyles(3), DataGridTextBoxColumn) AddHandler tbc.TextBox.KeyPress, AddressOf CellKeyPress ….. ’the handler Private Sub CellKeyPress(sender As Object, e As KeyPressEventArgs) ’don’t allow 1’s If e.KeyChar = ‘1’c Then e.Handled = True End If End Sub ’CellKeyPress

How can I programmatically manipulate Anchor styles

You can do this using the bitwise operators &, | and ^ ( And, Or and Xor (or &, Or, ^) in VB.Net). Here is code that will toggle label1 being anchored on the left. [C#] private void button1_Click(object sender, System.EventArgs e) { if ((label1.Anchor & AnchorStyles.Left) == 0) { //add it label1.Anchor = label1.Anchor | AnchorStyles.Left; } else if ((label1.Anchor & AnchorStyles.Left) != 0) { //remove label1.Anchor = label1.Anchor ^ AnchorStyles.Left; } } [VB.NET] Private Sub button1_Click(sender As Object, e As System.EventArgs) If(label1.Anchor And AnchorStyles.Left) = 0 Then ’add it label1.Anchor = label1.Anchor Or AnchorStyles.Left ElseIf(label1.Anchor And AnchorStyles.Left) <> 0 Then ’remove label1.Anchor = label1.Anchor Xor AnchorStyles.Left End If End Sub ’button1_Click