How do I set several lines into a multiline textbox
There are a several of ways to do this. Here are a few: 1) Insert a carriage return-linefeed, ‘\r\n’, between your lines. textBox1.Text = ‘This is line 1.\r\nThis is line 2’; // or textBox1.Text = stringvar1 + ‘\r\n’ + stringvar2; 2) Use the Environment.NewLine property. This property is normally set to ‘\r\n’. textBox1.Text = ‘This is line 1.’ + Environment.NewLine + ‘This is line 2’; 3) Use the Lines property of the TextBox. Make sure you populate your array before you set the property. string[] arr = new string[2]; arr[0] = ‘this is line1’; arr[1] = ‘this is line 2’; textBox3.Lines = arr;
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()); }