h1.post-title { color:orange; font-family:verdana,Arial; font-weight:bold; padding-bottom:5px; text-shadow:#64665b 0px 1px 1px; font-size:32px; } -->

Pages

Font names in Combobox using C#.Net

Declaration Part:


Using System.Drawings.Text





Code for getting font name into ComboBox :

InstalledFontCollection inst = new InstalledFontCollection();
            foreach (FontFamily fnt in inst.Families)
            {
                comboBox1.Items.Add(fnt.Name);
            }







Tooltip for TextBox

Tooltip for TextBox -- Coding  
private void textBox1_TextChanged(object sender, EventArgs e)
{
  if (textBox1.Text != "")
  {
     string str = textBox1.Text;
     toolTip1.Show(str, textBox1, 1, 10);
  }
  else
 {
   toolTip1.Hide(textBox1);
 }
}

Delete files base on character

Good Afternoon!
Today , we will discuss about Delete Files based on Specified Character.  
 
private void deletefilescheckwithstartingword(string inputPath,char ch) 
 { 
string[] InputPath = System.IO.Directory.GetFiles(inputPath); 
foreach (string fileName in InputPath)
 {
 FileInfo fileInformation = new FileInfo(fileName);
 string file = fileInformation.Name; char[] letter = file.ToCharArray(); 
if (letter[0] == ch)
 {
 System.IO.File.Delete(fileName);
 }
 } 
 } 

Happy Coding! 

Auto Complete,AutoScale,AutoSize Mode

AutoComplete Mode:
AutoComplete Mode is only for ComboBox and Text Box.
AutoScale Mode:
Default AutoScale Mode  is "Font"It is only for Form.
AutoSize Mode:
 Grow Only: Manually,you can change size of the Control when Auto size is enable.
 Grow and Shrink:Manually,you can't change size of the Control when Auto size is enable.

Control Validation using C#.net

Step by step to Control Validation:
 
   Add a Form
    Go to Form Property window.
    Disable Auto Validate .
    Add a Text Box in the Form.
    Add a Button in the Form.
    Verify Causes Validation is true.


if (textBox1.Text.Length == 0)
 { 
e.Cancel = true;
 }
 else
 {
 e.Cancel = false; 
}
 if (this.ValidateChildren())
 { 
MessageBox.Show("Validation succeeded!");
 }
 else
 {
 MessageBox.Show("Validation failed.");
 }

Form.ShowDialog vs Form.Show


Form.ShowDialog vs Form.Show
Form.ShowDialog Form.Show
It is a Modal Dialog Box. It is a Modaless.
you can't transfer a Text into Main form to Child Form. you can transfer a Text into Main form to Child Form.
Main form will not focus and you can't call another form before closing this form. Main form will focus and you can call another form before closing this form.

Disable Controls in Tab Control

Today, we will discuss about How to Disable Controls in Tab Control using C#.net? private static void DisableControls(Control.ControlCollection ctls, bool disable) { foreach (Control ctl in ctls) { ctl.Enabled = disable; DisableControls(ctl.Controls, disable); } } public static void DisableTab(TabPage page, bool disable) { DisableControls(page.Controls, disable); } private void btnAction_Click(object sender, EventArgs e) { DisableTab(tabPage1, false); btnAction.Enabled = true; } Happy Coding!

Get Parent Directory Name

Here , I give  code for Get Parent Directory Name

Use Parent.FullName Code.

string root = @"C:\Lakshmi\Naraayanan";
DirectoryInfo di = new DirectoryInfo(root);
MessageBox.Show(di.Parent.FullName);


Happy Coding!

Use Multiple Cast Delegates in C# .net

First create a class file for using Method in Delegate.Class name is  :Mathamatic.cs
Function Names are Add,Sub,Mul,Div.
Functions are given below:
public static string Add(int i, int j)
       {
          return "Sum of  I and J  is " + " " + ":" + (i + j);
       }
public static string Sub(int i, int j)
        {
            return "Sub of  I and J  is " + " " + ":" + (i - j);
        }
public static string Mul(int i, int j)
{
            return "Mul of  I and J  is " + " " + ":" + (i * j);
}
public static string Divi(int i, int j)
{
       return "Divide of  I and J  is " + " " + ":" + (i / j);
}



In our Form , drag and drop a button control in the Form.
First Declare a Delegate in the form :(like this)


public delegate string matha (int i,int j);


Now paste this code in the button Click Event.


 matha matadd = new matha(mathamatics.Add);
 MessageBox.Show(matadd(10, 5).ToString());
 matha matSub = new matha(mathamatics.Sub);
 MessageBox.Show(matSub(10, 5).ToString());
 matha matDivi = new matha(mathamatics.Divi);
 MessageBox.Show(matDivi(10, 5).ToString());
 matha matMul = new matha(mathamatics.Mul);
 MessageBox.Show(matMul(10, 5).ToString());


Happy Coding!

Add Enum value into ComboBox

Here , I will give a Small Code for Add Enum Value into ComboBox using C#.net.

First We create Enum Method using Enum Keyword:

enum days
    {
        Monday=1,
        Friday,
       Sunday
   }

Add a enum value into ComboBox box.
Add this code in the Form loading or button click event or any where...

comboBox1.Items.Add(days.Friday);
comboBox1.Items.Add(days.Monday );
comboBox1.Items.Add(days.Sunday);