How do I use code to insert or delete tabpages in a TabControl

To delete a tabpage, you use the tabControl1.Controls.Remove method. To add a new page as the last tab, use the tabControl1.Controls.Add method. Here is some sample code. //remove the selected tab tabControl1.Controls.Remove(tabControl1.SelectedTab); //add a new tabpage as the last tab tabControl1.Controls.Add(new TabPage('new Page')); There does not appear to be support in the framework for inserting a tab at a particular position. A work around might be to save the current tabpage controls, clear the Controls collection, and then add the saved controls back to the Controls collection inserting a new tab. Here is some code that does this. private void InsertTab(int tabNumber, ref TabControl tabControl) { int limit = tabControl.Controls.Count; if(tabNumber < 0 || tabNumber > limit) { tabControl.Controls.Add(new TabPage('new Page')); return; } int target = tabControl.SelectedIndex; //save the existing pages & clear the controls Control [] c = new Control[limit]; tabControl.Controls.CopyTo(c, 0); tabControl.Controls.Clear(); //add the earlier pages for (int i = 0; i < target; ++i) tabControl.Controls.Add(c[i]); //insert the page tabControl.Controls.Add(new TabPage('new Page')); //add the later pages for (int i = target; i < limit; ++i) tabControl.Controls.Add(c[i]); //select the new page tabControl.SelectedIndex = target; }

How can I display HTML in a Form

You can add a web browser to a form in a straight forward manner. 1) Right-click your toolbox and select Customize Toolbox. Then add the Com Component ’Microsoft Web Browser’. 2) Drag the just added Explorer tool and drop it on your form to position it where you want it. 3) Set the initial display page using code such as: public Form1() { // // Required for Windows Form Designer support // InitializeComponent(); object a = 0; object b = 0; object c = 0; object d = 0; axWebBrowser1.Navigate('www.syncfusion.com', ref a, ref b, ref c, ref d); // // TODO: Add any constructor code after InitializeComponent call // }

When I click on a row header, the row is selected and no cell is active. How can I do this programmatically

This code adds a method to a derived grid that simulates a mouseclick on the rowheader of the row passed into the method. 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 ClickRowHeader(int row) { //get a point to click Rectangle rect = this.GetCellBounds(row, 0); Int32 lparam = MakeLong(rect.Left - 4, rect.Top + 4); //click it SendMessage( this.Handle, WM_LBUTTONDOWN, 0, lparam); SendMessage( this.Handle, WM_LBUTTONUP, 0, lparam); } static int MakeLong(int LoWord, int HiWord) { return (HiWord << 16) | (LoWord & 0xffff); } } ..... ..... //usage - myDataGrid is of type MyDataGrid. private void button2_Click(object sender, System.EventArgs e) { myDataGrid.ClickRowHeader(2); }

How can I translate a point to a cell in the datagrid

If the point, say pt, is in screen coordinates, you can use code such as Point p1 = dataGrid1.PointToClient(pt); MessageBox.Show(dataGrid1.HitTest(p1).ToString()); If you are using context menus for catching right-clicks in the grid, you have to do a little work to remember where the original right-click point was as the point passed in through the menu event arguments may not reflect this original click. One solution is to remember the click in the grid MouseDown event, and then use the code above to retrieve the grid cell from within the menu handler. Point rightMouseDownPoint; private void dataGrid1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { if (e.Button == MouseButtons.Right) rightMouseDownPoint = Cursor.Position; } private void menuItem4_Click(object sender, System.EventArgs e) { Point pt = dataGrid1.PointToClient(rightMouseDownPoint); MessageBox.Show(dataGrid1.HitTest(pt).ToString()); }

How can I work around my menu shortcuts from showing up incorrectly when I use Ctrl+Number?

When you assign Ctrl1, Ctrl2 etc as shortcuts for menuitems they show up as Ctrl+D1, Ctrl+D2. This can be worked around by creating and adding the menuitem through code as demonstrated below: [C#] //Create the menuitem MenuItem mymenuItem = new MenuItem(); //ShortCut mymenuItem.Shortcut = System.Windows.Forms.Shortcut.Ctrl1; //Add Event Handler for the menuitem mymenuItem.Click +=new EventHandler(this.mymenuItem_Click); //ShortCut Text to be displayed mymenuItem.Text = 'My MenuItem' +'\t'+ 'Ctrl+1'; //hide shortcut mymenuItem.ShowShortcut = false; //Add it to the bottom of the first menu this.mainMenu1.MenuItems[0].MenuItems.Add(mymenuItem); [VB.NET] ’Create the menuitem Dim mymenuItem As MenuItem = New MenuItem() ’ShortCut mymenuItem.Shortcut = System.Windows.Forms.Shortcut.Ctrl1 ’Add Event Handler for the menuitem mymenuItem.Click +=New EventHandler(Me.mymenuItem_Click) ’ShortCut Text to be displayed mymenuItem.Text = 'My MenuItem' +'\t'+ 'Ctrl+1' ’hide shortcut mymenuItem.ShowShortcut = False ’Add it to the bottom of the first menu Me.mainMenu1.MenuItems(0).MenuItems.Add(mymenuItem)