نمایش نتایج 1 تا 40 از 534

نام تاپیک: 1001 نکته در سی شارپ

Hybrid View

پست قبلی پست قبلی   پست بعدی پست بعدی
  1. #1

    ضبط (ركورد) صدا از طريق ميكروفون

    How to record voice from microphone?


    using Microsoft.VisualBasic.Devices;
    using Microsoft.VisualBasic;
    using System.Runtime.InteropServices;

    تابع API زير را به كلاس برنامه بيافزاييد :
    [DllImport("winmm.dll", EntryPoint = "mciSendStringA", 
    CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]

    private static extern int mciSendString(string lpstrCommand,
    string lpstrReturnString, int uReturnLength, int hwndCallback);

    3 دكمه با نامهاي زير بسازيد :
    • Record
    • SaveStop
    • Read
    در زمان كليك شدن دكمه Record بنويسيد :
    // record from microphone
    mciSendString("open new Type waveaudio Alias recsound", "", 0, 0);
    mciSendString("record recsound", "", 0, 0);

    و هنگام كليك شدن دكمه SaveStop
    // stop and save
    mciSendString("save recsound c:\\record.wav", "", 0, 0);
    mciSendString("close recsound ", "", 0, 0);
    Computer c = new Computer();
    c.Audio.Stop();

    و براي دكمه Read نيز :
    Computer computer = new Computer();
    computer.Audio.Play("c:\\record.wav", AudioPlayMode.Background);

    منبع :
    http://www.dotnetspider.com/resource...icrophone.aspx

  2. #2

    بدست آوردن ليست برنامه هاي نصب شده بر روي سيستم

    Get a list of installed software in C#‎

    private string Getinstalledsoftware()
    {
    string Software = null;

    string SoftwareKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninst all";
    using (RegistryKey rk = Registry.LocalMachine.OpenSubKey(SoftwareKey))
    {
    foreach (string skName in rk.GetSubKeyNames())
    {
    using (RegistryKey sk = rk.OpenSubKey(skName))
    {
    try
    {
    if (!(sk.GetValue("DisplayName") == null))
    {
    if (sk.GetValue("InstallLocation") == null)
    Software += sk.GetValue("DisplayName") + " - Install path not known\n"; //Nope, not here.
    else
    Software += sk.GetValue("DisplayName") + " - " + sk.GetValue("InstallLocation") + "\n"; //Yes, here it is...
    }
    }
    catch (Exception ex)
    {
    //No, that exception is not getting away... :P
    }
    }
    }
    }
    return Software;
    }
    منبع : http://www.dreamincode.net/code/snippet1995.htm

  3. #3

    تست ارتباط با اينترنت از طريق پينگ كردن

    Check for internet connection in C#‎

    public bool isConnectionAvailable()
    {
    //build a list of sites to ping, you can use your own
    string[] sitesList = { "www.google.com", "www.microsoft.com" , "www.psychocoder.net" };
    Ping ping = new Ping();
    PingReply reply;
    bool _success = false;
    int notReturned = 0;
    try
    {
    for (int i = 0; i <= sitesList.Length; i++)
    {
    reply = ping.Send(sitesList[i], 10);
    if (reply.Status != IPStatus.Success)
    {
    notReturned += 1;
    }
    if (notReturned == sitesList.Length)
    {
    _success = false;
    throw new Exception(@"There doest seem to be a network/internet connection.\r\n
    Please contact your system administrator");
    }
    else
    {
    _success = true;
    }
    }
    }

    catch
    {
    _success = false;
    }
    return _success;
    }


    منبع : http://www.dreamincode.net/code/snippet1568.htm

  4. #4

    بدست آوردن سطر جاري در ديتاگريدويو

    Get current DataRow from a DataGridView instance.

    public DataRow GetCurrentRow(DataGridView dgv)
    {
    DataRowView drv = null;
    try
    {
    if (dgv.CurrentRow == null) { return null; }
    if (dgv.CurrentRow.DataBoundItem == null) { return null; }
    drv = (DataRowView)dgv.CurrentRow.DataBoundItem;
    }
    catch
    {
    return null;
    }
    return drv.Row;
    }

    منبع : http://www.dreamincode.net/code/snippet1435.htm

  5. #5

    بدست آوردن ميزان زمان روشن بودن كامپيوتر

    representation of the amount of time the computer has been on since the OS started.

    public string getUptime()
    {
    String strResult = String.Empty;
    strResult += Convert.ToString(Environment.TickCount / 86400000) + " days, ";
    strResult += Convert.ToString(Environment.TickCount / 3600000 % 24) + " hours, ";
    strResult += Convert.ToString(Environment.TickCount / 120000 % 60) + " minutes, ";
    strResult += Convert.ToString(Environment.TickCount / 1000 % 60) + " seconds.";
    return strResult;
    }


    منبع : http://www.dreamincode.net/code/snippet1555.htm

برچسب های این تاپیک

قوانین ایجاد تاپیک در تالار

  • شما نمی توانید تاپیک جدید ایجاد کنید
  • شما نمی توانید به تاپیک ها پاسخ دهید
  • شما نمی توانید ضمیمه ارسال کنید
  • شما نمی توانید پاسخ هایتان را ویرایش کنید
  •