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
How can I trigger a button click event
Use the button’s public method PerformClick. button1.PerformClick();
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 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'); }
What are the steps to compiling and using multiple language resources
Localization Sample illustrates how to load different language resources depending upon a parameter passed in when you run the program from a command line. The sample can display English, French, Spanish and German words using the same exe. For example, typing Test de on the command line will count to three in German. Typing Test fr will count to three in French. The argument passed in is used to determine the culture setting for the resources. In each folder is a batch file that handles compiling the single exe and multiple resources. The tools RESGEN and AL are used in these batch files to generate the resources and resource DLL’s. Notice the naming conventions used by the subfolders containing the foreign resource DLLs.