Increase/Decrease Textbox Font Size Programatically (VB.NET)

[vbnet]
Private Sub frm_Main_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
‘ Ctrl + + = increase the SQL size
If e.Control And e.KeyCode = Keys.Add Then
Using f As Font = TextBox1.Font
TextBox1.Font = New Font(f.FontFamily, f.Size + 1, f.Style)
End Using
Exit Sub
End If

‘ Ctrl + – = decrease the SQL size
If e.Control And e.KeyCode = Keys.Subtract Then
Using f As Font = TextBox1.Font
TextBox1.Font = New Font(f.FontFamily, f.Size – 1, f.Style)
End Using
Exit Sub
End If
End Sub
[/vbnet]

Capture when Ctrl+Enter keys are pressed at the same time (VB.NET)

Make sure your Form’s KeyPreview property is set to True.

[vbnet]
Private Sub frm_Main_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
If e.Control And e.KeyCode = Keys.Enter Then
‘ Do something
End If
End Sub
[/vbnet]

You can also capture when the Alt+Enter keys are pressed at the same time with the following:

[vbnet]
Private Sub frm_Main_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
If e.Alt And e.KeyCode = Keys.Enter Then
‘ Do something
End If
End Sub
[/vbnet]

Populate a DataGridView with SqlDataReader

In order to display the data in a SqlDataReader object in a DataGridView control, you first need to load the data into a DataTable object. The code below is in C# and the Connection String is for a SQL Server database connection.

[csharp]
using System.Data.SqlClient;

SqlConnection con = new SqlConnection();
SqlCommand cmd = new SqlCommand();
SqlDataReader dr;

// set the connection string
con.ConnectionString = “Data Source=SqlServerName;Initial Catalog=DbName;Integrated Security=True”
con.Open();

string SQL = “SELECT * FROM tbl_Users”;

// create the SQL command
cmd = new SqlCommand(SQL, con);

// execute the SQL
dr = cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);

DataTable table = new DataTable();
table.Load(dr);

reader.Close();
reader.Dispose();
con.Close();
con.Dispose();
cmd.Dispose();
cmd = null;

// Display the data in the DataGridView control…
DataGridView1.DataSource = table;
[/csharp]