How can I programmatically maximize or minimize a form
Use the form’s WindowState property. //minimize this.WindowState = System.Windows.Forms.FormWindowState.Minimized; ….. //maximize this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
How can I tell if the current row has changed and whether I am on the AddNew row or not
The DataGrid’s CurrentCellChanged event is hit even if you just change cells in the current row. If you want an event that is only hit when you change rows, then you have to look at the binding manager. This object has both a CurrentChanged event and a PositionChanged event which are hit when you change rows. To decide whether you are on the AddNew row or not, you can again use the binding manager and compare the number of rows it returns with the number of rows in your data table. Below is some code snippets showing how you might get at this information. private System.Windows.Forms.DataGrid dataGrid1; private BindingManagerBase bindingManager; private void Form1_Load(object sender, System.EventArgs e) { // Creating connection and command sting string conStr = @’Provider=Microsoft.JET.OLEDB.4.0;data source=C:\northwind.mdb’; string sqlStr = ‘SELECT * FROM Employees’; // Create connection object OleDbConnection conn = new OleDbConnection(conStr); // Create data adapter object OleDbDataAdapter da = new OleDbDataAdapter(sqlStr,conn); // Create a dataset object and fill with data using data adapter’s Fill method DataSet ds = new DataSet(); da.Fill(ds, ‘Employees’); dataGrid1.DataSource = ds.Tables[‘Employees’]; bindingManager = this.BindingContext[dataGrid1.DataSource]; bindingManager.PositionChanged += new System.EventHandler(RowChanged); } private void RowChanged(object sender, System.EventArgs e) { Console.WriteLine(‘RowChanged ‘ + bindingManager.Position.ToString() ); bool lastRow = bindingManager.Count > ((DataTable)dataGrid1.DataSource).Rows.Count; if(lastRow) Console.WriteLine(‘lastRow’); }
How can a translate an OLE_COLOR into a GDI+ Color object
Use the ColorTranslator class. It has methods to translate to / from OLE colors, HTML colors, and Win32 colors.
How can I trigger a button click event
Use the button’s public method PerformClick. button1.PerformClick();
How do I programmatically load, modify and save a bitmap
You can download a working project. Below are VB code snippets showing how you might do these tasks. ’load a bitmap from an embedded resource Dim Bmp As Bitmap ’ from an embedded resource Dim curName As String = ”BitmapVB.sync.bmp” Dim strm As System.IO.Stream = Me.GetType().Assembly.GetManifestResourceStream(curName) Bmp = New Bitmap(strm) PictureBox1.Image = Bmp ….. ….. ’load a bitmap from a file Dim Bmp As Bitmap = Image.FromFile(”c:\sync.bmp”) PictureBox1.Image = Bmp ….. ….. ’modify a bitmap Dim Bmp As Bitmap = PictureBox1.Image.Clone Dim g As Graphics = Graphics.FromImage(Bmp) Dim brush1 As SolidBrush = New SolidBrush(Color.Red) g.DrawString(TextBox1.Text, TextBox1.Font, brush1, 10, 10) PictureBox2.Image = Bmp g.Dispose() …. …. ’save a bitmap as a file Dim dlg As SaveFileDialog = New SaveFileDialog() dlg.Title = ”Save BMP file” dlg.InitialDirectory = ”c:\” dlg.Filter = ”bmp files (*.bmp)|*.bmp|All files (*.*)|*.*” If dlg.ShowDialog = DialogResult.OK Then PictureBox2.Image.Save(dlg.FileName End If