How to create an alert dialog in Android

To create an alert dialog in Android you can use the following snippet.

Sample Java

new AlertDialog.Builder(this)
    .setTitle("Delete items")
    .setMessage("Are you sure you want to delete this items?")
    .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) { 
            // YES
        }
     })
    .setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) { 
            // NO
        }
     })
    .setIcon(android.R.drawable.ic_dialog_alert)
     .show();

Please rate this snippet

How to choose a font using FontDialog in C# and VB.NET

To choose a font using FontDialog in C# and VB.NET you can use the following snippet.

Sample C#

using (var dialog = new FontDialog())
{
	if (dialog.ShowDialog() != DialogResult.Cancel)
	{
		textBox1.Font = dialog.Font;
	}
}

Sample VB.NET

Using dialog = New FontDialog()
	If dialog.ShowDialog() <> DialogResult.Cancel Then
		textBox1.Font = dialog.Font
	End If
End Using

Please rate this snippet

How to choose a color using ColorDialog in C# and VB.NET

To choose a color using ColorDialog in C# and VB.NET you can use the following snippet.

Sample C#

using (var colorDialog = new ColorDialog())
{
	if (colorDialog.ShowDialog() != DialogResult.Cancel)
	{
		var colorChosen = colorDialog.Color;
		textBox1.ForeColor = colorChosen;
		textBox1.BackColor = colorChosen;
	}
}

Sample VB.NET

Using colorDialog = New ColorDialog()
	If colorDialog.ShowDialog() <> DialogResult.Cancel Then
		Dim colorChosen = colorDialog.Color
		textBox1.ForeColor = colorChosen
		textBox1.BackColor = colorChosen
	End If
End Using

Please rate this snippet