Windows Application

How to Create chart from datatable using c# windows application



//Declare One DataTable Gloably
        DataTable dtChart = new DataTable();
        private void Form11_Load(object sender, EventArgs e)
        {
            //Note* Add one panel in form

            //Insert Static Data In Datatable
            dtChart.Clear();
            dtChart.Columns.Add("Mark");
            dtChart.Rows.Add("355");
            dtChart.Rows.Add("230");
            dtChart.Rows.Add("125");
            dtChart.Rows.Add("390");
            dtChart.Rows.Add("125");

            //Select Row in Collection
            DataRow[] rows = dtChart.Select();

            //Call Generate Chart Method
            GenerateChart(rows, "Mark");

        }

       // Generate Chart Method
        private void GenerateChart(DataRow[] drChart, string dataColumnName)
        {
            Chart objChart = new Chart();
            objChart.Name = "chart" + dataColumnName;
            objChart.Size = new System.Drawing.Size(85, 75);
            objChart.ChartAreas.Add(dataColumnName);
            objChart.ChartAreas[dataColumnName].AxisY.LabelStyle.Enabled = true;
            objChart.ChartAreas[dataColumnName].AxisX.LabelStyle.Enabled = true;
            objChart.ChartAreas[dataColumnName].AxisY.Enabled = AxisEnabled.Auto;
            objChart.ChartAreas[dataColumnName].AxisX.Enabled = AxisEnabled.Auto;
            objChart.Series.Add(dataColumnName);
            objChart.Series[dataColumnName].Color = System.Drawing.Color.GreenYellow;
            //Change SeriesChartType Like bar,line,pie etc
            objChart.Series[dataColumnName].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Bar;

            foreach (DataRow dr in drChart)
            {
                double Mark = Convert.ToDouble(dr[dataColumnName]);
                objChart.Series[dataColumnName].Points.AddY(Mark);
            }
            objChart.ChartAreas[0].AxisX.MajorGrid.Enabled = false;
            objChart.ChartAreas[0].AxisX.MinorGrid.Enabled = false;
            objChart.ChartAreas[0].AxisY.MajorGrid.Enabled = false;
            objChart.ChartAreas[0].AxisY.MinorGrid.Enabled = false;
            objChart.BringToFront();
            objChart.Dock = DockStyle.Top;
            panel1.Controls.Add(objChart);
        }


How to close login form  in C# windows application before login

//LoginForm.cs File
this.DialogResult = System.Windows.Forms.DialogResult.OK;
this.Dispose();

//Program.cs File
public static Home frmHome;

[STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Login frmLogin = new Login();
            frmLogin.ShowDialog();
            if (frmLogin.DialogResult == DialogResult.OK)
            {
                frmHome= new Home();
                Application.Run(frmHome);
            }
        }


how to write connection string in c# windows application

Write thi code in app.config in windows application

providerName="System.Data.SqlClient"
connectionString="Data Source=(LocalDB)\v11.0;AttachDbFileName=|DataDirectory|\DatabaseFileName.mdf;InitialCatalog=DatabaseName;
Integrated Security=True;
MultipleActiveResultSets=True" 


How to set random color in dynamic created panel in c# windows application

 

private void Form1_Load(object sender, EventArgs e)
        {
            Random randonGen = new Random();
            for (int i = 0; i <= 12; i++)
            {
                Color randomColor = Color.FromArgb(randonGen.Next(200), randonGen.Next(230), randonGen.Next(235));
                User_Control.ControlsPanel cntPan = new User_Control.ControlsPanel();
                cntPan.MonthName = "Test";
                cntPan.Dock = DockStyle.Top;
                cntPan.BackColor = randomColor;
                panel1.Controls.Add(cntPan);
            }
        } 


How to use string builder in windows application

using System;
using System.Text;

class Program
{
    static void Main()
    {
     StringBuilder builder = new StringBuilder();
     // Append to StringBuilder.
     for (int i = 0; i < 10; i++)
     {
        builder.Append(i).Append(" ");
     }
     Console.WriteLine(builder);
    }


How to Open Anothe Form from Another Form in MDIContainer Using C#
 
//Open Form in mdi form

// this code is special

// if you open one form in mdi peren then open another form from form in mdi write this code

// Eg.

//Create one project
//Create Default form property ismdicontainer=true
//then
//add one more form like Form2 this form is open from MDIForm

//then open second form open from Form2 add one more form like Form3

//then write this code in form2 button event then see the megic

Form3 frmShow = new Form3();
frmShow.MdiParent = this.ParentForm;
frmShow.Show();
this.Close(); 


 How to Close Form By Pressing Escape Key in windows application

// Form Keypreview Property = True
// Write Code in Keydown Event

 private void General_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Escape)
            {
                this.Close();
            }
        }


How to insert only characters in textbox using c# Windows application

*Insert maskedtextbox then write this code its key press event*

private void maskedTextBox1_KeyPress(object sender, KeyPressEventArgs e)
{
    char presskey = e.KeyChar;
    if (char.IsLetter(presskey) || char.IsSeparator(presskey) || char.IsPunctuation(presskey))
    {
        e.Handled = false;
    }
    else if(e.KeyChar=='\b')
    {
    }
    else
    {
        e.Handled = true;
    }
}


How to get first character capital string in windows application

using System.Globalization;

string a = CultureInfo.CurrentCulture.TextInfo.ToTitleCase("india");

Result : India 


How to show notification in taskbar using c# windows application


using System;
using System.Drawing;

DateTime Dates = Convert.ToDateTime("12/7/2012 6:09:11 PM");
TimeSpan diff = Dates - System.DateTime.Now;
notifyIcon1.Icon = SystemIcons.Exclamation;
notifyIcon1.BalloonTipTitle = "Days Remaning";
notifyIcon1.BalloonTipText = "Day : " + diff.Days.ToString();
notifyIcon1.BalloonTipIcon = ToolTipIcon.Error;
notifyIcon1.Visible = true;
notifyIcon1.ShowBalloonTip(30000); 


How to get all system Fonts Name in c# windows application

using System.Drawing.Text;

InstalledFontCollection inst = new InstalledFontCollection();

foreach (FontFamily fnt in inst.Families)
{
    comboBox1.Items.Add(fnt.Name);


How to Display Reverse String in C# Windows Application

label1.Text = "";
string inp = textBox1.Text;
char[] outp = inp.ToCharArray();
Array.Reverse(outp);
foreach (var item in outp)
{
    label1.Text += item.ToString();


How to Store & Retrieve Value Of Form using IsolatedStorage in C# Windows Application 






using System.Collections.Generic;
using System.ComponentModel;

using System.Text;
using System.Windows.Forms;
using System.IO;
using System.IO.IsolatedStorage;
using System.Diagnostics;

//Variable
string FullLine;
        const string ISOLATED_FILE_NAME = "Setting.txt";
        IsolatedStorageFile isoStore = IsolatedStorageFile.GetStore(IsolatedStorageScope.User | IsolatedStorageScope.Assembly, null, null);

 private void ISOStorageUse_Load(object sender, EventArgs e)
        {
            cbYesNo.Text = "No";
            ddlStandard.SelectedIndex = 0;
          
            #region Get Data
            IsolatedStorageFileStream iStream = new IsolatedStorageFileStream(ISOLATED_FILE_NAME, FileMode.OpenOrCreate, isoStore);
            StreamReader reader = new StreamReader(iStream);
            FullLine = reader.ReadToEnd();
            reader.Close();
            #endregion Get Data

            #region Apply Value
            string SplitPart = FullLine.Replace("\r\n", ",");
            string[] Parts = SplitPart.Split(',');

            if (SplitPart == "") return;
            dtpDate.Value = Convert.ToDateTime(Parts[0]);
            tbName.Text = Parts[1];
            ddlStandard.SelectedIndex = Convert.ToInt32(Parts[2]);
            cbYesNo.Checked = Convert.ToBoolean(Parts[3]);
            #endregion Apply Value
        }


// Form Closing Event

 private void ISOStorageUse_FormClosing(object sender, FormClosingEventArgs e)
        {
            // Write some text into the file in isolated storage.
            IsolatedStorageFileStream oStream = new IsolatedStorageFileStream(ISOLATED_FILE_NAME, FileMode.OpenOrCreate, isoStore);
            StreamWriter writer = new StreamWriter(oStream);
            writer.WriteLine(dtpDate.Value);
            writer.WriteLine(tbName.Text);
            writer.WriteLine(ddlStandard.SelectedIndex);
            writer.WriteLine(cbYesNo.Checked);
            writer.Close();
        }  


How to Menually Database Backup Restore in Windows Application [Access Database]

using System.Windows.Forms;
using System.Data;
using System.Data.OleDb;
using System.Collections.Generic;
using System.Text;
using System.IO;

private void btnBackup_Click(object sender, EventArgs e)
        {
            string dt = System.DateTime.Now.ToString("dd.MM.yyyy");
            string CurrentDatabasePath = Environment.CurrentDirectory + @"\dbSchool.mdb";
            FolderBrowserDialog fbd = new FolderBrowserDialog();
            if (fbd.ShowDialog() == DialogResult.OK)
            {
                string newPath = System.IO.Path.Combine(fbd.SelectedPath, dt);
                System.IO.Directory.CreateDirectory(newPath);
                File.Copy(CurrentDatabasePath, newPath + @"\dbSchool.mdb", true);
                MessageBox.Show("Back Up SuccessFull! ", "Khodiyar Engineers & Industries", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

        private void btnRestore_Click(object sender, EventArgs e)
        {
            string PathToRestoreDB = Environment.CurrentDirectory + @"\dbSchool.mdb";
            OpenFileDialog ofd = new OpenFileDialog();
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                string Filetorestore = ofd.FileName;
                File.Copy(Filetorestore, PathToRestoreDB, true);
                MessageBox.Show("Restore SuccessFull! ", "Khodiyar Engineers & Industries", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        } 

2 comments :

  1. How to Create .exe file form window Application???

    ReplyDelete
    Replies
    1. Very simple steps, yet you discarded them:
      => Compile the application in Release mode.
      => Open the solution folder.
      => Open the project folder.
      => Open the Bin folder.
      => Open the Release folder.
      => Copy the .exe file.
      Share it.

      Delete