Showing posts with label winforms tutorial. Show all posts
Showing posts with label winforms tutorial. Show all posts

Saturday, December 23, 2017

How to display Notification in Notification Area of Taskbar in Windows Application

How to display Notification in Notification Area of Taskbar in Windows Application

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 read & write file in isolation storage in c#

How to read & write file in isolation storage in c#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.IO.IsolatedStorage;
using System.Diagnostics;

namespace Program
{
        //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();
       } 
}

Thursday, March 19, 2015

How to dynamic upload image in aspx file upload control using c# windows application

i have solution for how to dynamic upload image in any browsers file upload dialog using c# windows application for more help send mail in my gmail id i give u solution for your desktop application

thank you...

Thursday, June 20, 2013

Get Byte Size in MB Using C# Windows Application


CREATE FUNCTION

static double ConvertBytesToMegabytes(long bytes)
{
            return (bytes / 1024f) / 1024f;
}

Write This Code In Page Load Event

// Now convert to a string in megabytes.
string s = ConvertBytesToMegabytes(6955008).ToString("0.00");

// Convert bytes to megabytes.
MessageBox.Show(s + " MB");

Thursday, June 13, 2013

How to get Size in KB, MB, GB, TB, PB, EB, Bytes In C# Windows Application


Create Static Function

static String BytesToString(long byteCount)
        {
            string[] suf = { "B", "KB", "MB", "GB", "TB", "PB", "EB" }; //Longs run out around EB
            if (byteCount == 0)
                return "0" + suf[0];
            long bytes = byteCount;
            int place = Convert.ToInt32(Math.Floor(Math.Log(bytes, 1024)));
            double num = Math.Round(bytes / Math.Pow(1024, place), 2);
            return (Math.Sign(byteCount) * num).ToString() + suf[place];
        }

Write in Any Place Like This

private void Test_Load(object sender, EventArgs e)
        {
            MessageBox.Show(BytesToString(2000000).ToString());
        }

Tuesday, June 11, 2013

How to get Max & Min Number From Array List in C# Windows Application

-- Add this Name Space
using System.Collections;

ArrayList Numbers = new ArrayList();

-- Add Value in Array List
Random Randomizer = new Random();
Int32 P1 = Randomizer.Next(25, 100);
Int32 P2 = Randomizer.Next(25, 100);
Int32 P3 = Randomizer.Next(25, 100);
Int32 P4 = Randomizer.Next(25, 100);
Numbers.Add(P1);
Numbers.Add(P2);
Numbers.Add(P3);
Numbers.Add(P4);

-- Get Max Number
Int32 MaxNumber = Numbers.Cast<Int32>().Max();

-- Get Min Number
Int32 MaxNumber = Numbers.Cast<Int32>().Min();

Monday, June 10, 2013

Create Maths Quiz in C# Windows Application


Random randomizer = new Random();
int addend1;
int addend2;
int timeLeft;
int minuend;
int subtrahend;
int multiplicand;
int multiplier;
int dividend;
int divisor;

private void timer1_Tick(object sender, EventArgs e)
        {
            if (CheckTheAnswer())
            {
                timer1.Stop();
                MessageBox.Show("You got all the answers right!",
                                "Congratulations");
                startButton.Enabled = true;
            }
            else if (timeLeft > 0)
            {
                timeLeft--;
                timeLeftLabel.Text = timeLeft + " seconds";
            }
            else
            {
                timer1.Stop();
                timeLeftLabel.Text = "Time's up!";
                MessageBox.Show("You didn't finish in time.", "Sorry");
                sum.Value = addend1 + addend2;
                difference.Value = minuend - subtrahend;
                product.Value = multiplicand * multiplier;
                quotient.Value = dividend / divisor;
                startButton.Enabled = true;

            }
        }

public void StartTheQuiz()
        {
            // Fill in the addition problem.
            addend1 = randomizer.Next(51);
            addend2 = randomizer.Next(51);
            plusLeftLabel.Text = addend1.ToString();
            plusRightLabel.Text = addend2.ToString();
            sum.Value = 0;

            // Fill in the subtraction problem.
            minuend = randomizer.Next(1, 101);
            subtrahend = randomizer.Next(1, minuend);
            minusLeftLabel.Text = minuend.ToString();
            minusRightLabel.Text = subtrahend.ToString();
            difference.Value = 0;

            // Fill in the multiplication problem.
            multiplicand = randomizer.Next(2, 11);
            multiplier = randomizer.Next(2, 11);
            multLeftLabel.Text = multiplicand.ToString();
            multRightLabel.Text = multiplier.ToString();
            product.Value = 0;

            // Fill in the division problem.
            divisor = randomizer.Next(2, 11);
            int temporaryQuotient = randomizer.Next(2, 11);
            dividend = divisor * temporaryQuotient;
            divLeftLabel.Text = dividend.ToString();
            divRightLabel.Text = divisor.ToString();
            quotient.Value = 0;

            // Start the timer.
            timeLeft = 60;
            timeLeftLabel.Text = "60 seconds";
            timer1.Start();
        }

private bool CheckTheAnswer()
        {
            if ((addend1 + addend2 == sum.Value)
                && (minuend - subtrahend == difference.Value)
                && (multiplicand * multiplier == product.Value)
                && (dividend / divisor == quotient.Value))
                return true;
            else
                return false;
        }

        private void startButton_Click(object sender, EventArgs e)
        {
            StartTheQuiz();
            startButton.Enabled = false;
        }

How to Display Reverse Number Or String in C# Windows Application


private void btReverse_Click(object sender, EventArgs e)
        {
            label1.Text = "";
            string inp = textBox1.Text;
            char[] outp = inp.ToCharArray();
            Array.Reverse(outp);
            foreach (var item in outp)
            {
                label1.Text += item.ToString();
            }
        }

How to create Count Down Timer in C# Windows Application


public int hours = 00;   // Hours.
public int minutes = 10; // Minutes.
public int seconds = 00; // Seconds.

private void timer1_Tick(object sender, EventArgs e)
        {
            if (seconds < 1)
            {
                seconds = 59;
                if (minutes == 0)
                {
                    minutes = 59;
                    if (hours != 0) hours -= 1;
                }
                else
                {
                    minutes -= 1;
                }
            }
            else seconds -= 1;
            lblHr.Text = hours.ToString();
            lblMin.Text = minutes.ToString();
            lblSec.Text = seconds.ToString();
        }

private void CountDownTimer1_Load(object sender, EventArgs e)
        {
            timer1.Enabled = true;
        }

Saturday, June 8, 2013

Close Windows Form Using Escape Key

Note : Keypreviw = True in Form Property

Then Write This Code in  KeyDown Event

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

How to Select COM Port All Details Using C#

Add Two References

- using System.Management;
- using System.IO.Ports;

:: Write this code in page load event ::

ManagementObjectCollection ManObjReturn;
ManagementObjectSearcher ManObjSearch;
ManObjSearch = new ManagementObjectSearcher("Select * from Win32_SerialPort");
ManObjReturn = ManObjSearch.Get();

foreach (ManagementObject ManObj in ManObjReturn)
{
                //int s = ManObj.Properties.Count;
                //foreach (PropertyData d in ManObj.Properties)
                //{
                //    MessageBox.Show(d.Name);
                //}
                MessageBox.Show(
                    "Device ID : " + ManObj["DeviceID"] + "\n"
                    + "PNP Device ID : " + ManObj["PNPDeviceID"] + "\n"
                    + "Name : " + ManObj["Name"] + "\n"
                    + "Caption : " + ManObj["Caption"] + "\n"
                    + "Description : " + ManObj["Description"] + "\n"
                    + "Provider Type : " + ManObj["ProviderType"] + "\n"
                + "Status : " + ManObj["Status"]);
}

Tuesday, May 21, 2013

Import Excel Data To Gridview Using C#

Create Form
















public string strFileName;

private void excelBrowsebtn_Click(object sender, EventArgs e)
        {
            strFileName = txtFileName.Text;
            OpenFileDialog fdlg = new OpenFileDialog();
            fdlg.Title = "Select file";
            fdlg.InitialDirectory = @"c:\";
            fdlg.FileName = txtFileName.Text;
            fdlg.Filter = "Excel Sheet(*.xlsx)|*.xls|All Files(*.*)|*.*";
            fdlg.FilterIndex = 1;
            fdlg.RestoreDirectory = true;
            if (fdlg.ShowDialog() == DialogResult.OK)
            {
                txtFileName.Text = fdlg.FileName;
            }


string connectionString = String.Format(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};

Extended Properties=""Excel 8.0;HDR=YES;IMEX=1;""", txtFileName.Text);
string query = String.Format("select * from [{0}$]", "Sheet1");
OleDbDataAdapter dataAdapter = new OleDbDataAdapter(query, connectionString);
DataSet dataSet = new DataSet();
dataAdapter.Fill(dataSet);
dataGridView1.DataSource = dataSet.Tables[0];
        }


private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
        {
            if (e.Control is System.Windows.Forms.TextBox)
            {
                ((System.Windows.Forms.TextBox)e.Control).CharacterCasing = CharacterCasing.Upper;
            }
        }