How do I bind a mdb file to a datagrid

You can use the classes in the System.Data.OleDb namespace to read a MDB file into a datagrid. You instantiate a OleDbConnection object using a connection string to your MDB file. You then instantiate a OleDbDataAdapter that uses this connection object and a SQL query. Next you create a DataSet object, use the OleDbDataAdapter to fill this dataset, and finally attached this dataset to your datagrid. Here is the code that does this. private void Form1_Load(object sender, System.EventArgs e) { // Set the connection and sql strings // assumes your mdb file is in your root string connString = @’Provider=Microsoft.JET.OLEDB.4.0;data source=C:\northwind.mdb’; string sqlString = ‘SELECT * FROM customers’; // Connection object OleDbConnection connection = new OleDbConnection(connString); // Create data adapter object OleDbDataAdapter dataAdapter = new OleDbDataAdapter(sqlString, connection); // Create a dataset object and fill with data using data adapter’s Fill method DataSet dataSet = new DataSet(); dataAdapter.Fill(dataSet, ‘customers’); // Attach dataset’s DefaultView to the datagrid control dataGrid1.DataSource = dataSet.Tables[‘customers’].DefaultView; }

How can I draw a single line of text with different fonts using DrawString

The key is that you have to calculate the ascent height of the font. The font ascent as reported by FontFamily.GetCellAscent is in what is called ’Design Units’. The Cell Spacing design unit value of fonts is proportional to the actual height of the font on the device. We use this relationship to calculate cell ascent in device units. The rendering code has to just ensure that the x, y position passed to DrawString takes care of the ascent. private void HandlePaint(object sender, PaintEventArgs args) { // clear the background Graphics g = args.Graphics; g.Clear(Color.AliceBlue); // create a pen Pen pen = new Pen(Color.Red, 1f); // the string to be drawn string s = ‘Side by side’; // the first font Font f1 = new Font(‘Arial’, 10f); float strWidth1 = g.MeasureString(s, f1).Width; float fontHeight1 = f1.GetHeight(g); float fontAscentHeight1 = (fontHeight1/f1.FontFamily.GetLineSpacing(f1.Style))*f1.FontFamily.GetCellAscent(f1.Style); // the second font Font f2 = new Font(‘Times New Roman’, 48); float fontHeight2 = f2.GetHeight(g); float fontAscentHeight2 = (fontHeight2/f2.FontFamily.GetLineSpacing(f2.Style))*f2.FontFamily.GetCellAscent(f2.Style); // draw the base line Point ptStart = new Point(0, this.ClientSize.Height/2); Point ptEnd = new Point(this.ClientSize.Width, this.ClientSize.Height/2); g.DrawLine(Pens.Black, ptStart, ptEnd); // draw string with first font g.DrawString(s, f1, Brushes.Red, new PointF(0, ptStart.Y – fontAscentHeight1)); // draw string with second font g.DrawString(s, f2, Brushes.Red, new PointF(strWidth1, ptStart.Y – fontAscentHeight2)); }

Can I write CGI applications using .NET

You sure can. Here is a simple CGI program that prints out the current time and also all the environment variables that are available to it. using System; public class cgi { public static void Main(string[] args) { Console.WriteLine(‘Content-Type:text/html\n\n’); if(args.GetLength(0) == 0) Console.WriteLine(‘The time now is {0}’, System.DateTime.Now.ToString()); else Console.WriteLine(‘Hi {0}, the time now is {1}’, args[0], System.DateTime.Now.ToString()); foreach(string s in Environment.GetEnvironmentVariables().Keys) Console.WriteLine(‘ {0} : {1} ‘,s, Environment.GetEnvironmentVariables()[s]); } }

How to make properties in your custom data type appear in a particular order in the property browser

// Your custom data type public class MySize { … public int Width{get{…}set{…}} public int Height{get{…}set{…}} } For example, in the above class (MySize) if you want to your properties ‘Width’ and ‘Height’ to appear in that order, you should provide this override: public override bool GetPropertiesSupported(ITypeDescriptorContext context) { return true; } public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes) { System.ComponentModel.PropertyDescriptorCollection propertyDescriptorCollection; string[] propNames; propertyDescriptorCollection = TypeDescriptor.GetProperties(typeof(System.Drawing.Size),attributes); propNames = (string[])new System.String[2]; propNames[0] = @’Width’; propNames[1] = @’Height’; return propertyDescriptorCollection0.Sort(propNames); } // end of method GetProperties