1. مهمان گرامی، جهت ارسال پست، دانلود و سایر امکانات ویژه کاربران عضو، ثبت نام کنید.
    بستن اطلاعیه

كدهاي به درد بخور سي شارپ

شروع موضوع توسط minaaa ‏24/10/11 در انجمن C #C++

  1. کاربر پیشرفته

    تاریخ عضویت:
    ‏9/12/10
    ارسال ها:
    19,795
    تشکر شده:
    6,456
    امتیاز دستاورد:
    113
    پاسخ : كدهاي به درد بخور سي شارپ

    برای به دست آوردن اندازه تصویر مجازی
    كد:
    HTML:
    MessageBox.Show("VirtualScreen: " +  SystemInformation.VirtualScreen);[/HTML[/LEFT]
     
  2. کاربر پیشرفته

    تاریخ عضویت:
    ‏9/12/10
    ارسال ها:
    19,795
    تشکر شده:
    6,456
    امتیاز دستاورد:
    113
    پاسخ : كدهاي به درد بخور سي شارپ

    تابعی برای رمز نگاری یکطرفه به وسیله الگوریتم md5 الگوریتم یکطرفه یعنی اینکه مقداری که به دست می آید قابل برگشت نیست......!
    اما مقداری که از یک رشته تولید می شود همیشه یکسان است.و می توان با مقایسه رشته رمز نگاری شده قبل و جدید اعتبار آن را تعیین کرد
    كد:
    HTML:
    byte[] computemd5(string  st1)
    **
    MD5CryptoServiceProvider md51 = new  MD5CryptoServiceProvider();
    UTF8Encoding encode = new  UTF8Encoding();
    byte[] stbytes = encode.GetBytes(st1);
    byte[] result =  md51.ComputeHash(stbytes);
    return result;
    }
     
  3. کاربر پیشرفته

    تاریخ عضویت:
    ‏9/12/10
    ارسال ها:
    19,795
    تشکر شده:
    6,456
    امتیاز دستاورد:
    113
    پاسخ : كدهاي به درد بخور سي شارپ

    اجرای فقط یک کپی از برنامه

    این دستور چک می کند اگر هیچ برنامه ای از نوع برنامه فراخوانی شده در حال اجرا نباشد ، برنامه اجرا می شود.

    HTML:
    using System;
    using  System.Collections.Generic;
    using System.Windows.Forms;
    using  System.Diagnostics;
    
    namespace SingleInstanceTest
    **
    static class  Program
    **
    [System.Runtime.InteropServices.DllImport("user32.d  ll")]
    [return: System.Runtime.InteropServices.MarshalAs(System.Ru  ntime.InteropServices.UnmanagedType.Bool)]
    static extern bool  SetForegroundWindow(IntPtr hWnd);
    
    public static bool  HasPriorInstance()
    **
    Process currentProcess =  Process.GetCurrentProcess();
    string fileName =  currentProcess.StartInfo.FileName;
    foreach (Process process in  Process.GetProcessesByName(currentProcess.ProcessN ame))
    **
    if (process.Id  == currentProcess.Id) ** continue; }
    if (process.StartInfo.FileName !=  fileName) ** continue;  }
    SetForegroundWindow(process.MainWindowHandle);
    return  true;
    }
    return false;
    }
    
    [STAThread]
    static void  Main()
    **
    if  (!HasPriorInstance())
    **
    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(fals  e);
    Application.Run(new Form1());
    }
    }
    }
    }
     
  4. کاربر پیشرفته

    تاریخ عضویت:
    ‏9/12/10
    ارسال ها:
    19,795
    تشکر شده:
    6,456
    امتیاز دستاورد:
    113
    پاسخ : كدهاي به درد بخور سي شارپ

    كدهاي به درد بخور سي شارپ
    کدی برای تست زمان اجرای برنامه قطعه کدی برای تست اجرای زمان برنامه

    HTML:
     //**************************************
    // 
    // Name: [ A Simple] code execution  time
    // tests
    // Description:Paste this into your C# c
    // ode to test  how 
    long a portion of your code  takes to execute. 
    The number of  milliseconds is appended to C:\TimeTest.txt
    // By: lonetron
    //
    //This  code is copyrighted and has // limited warranties.Please see http://
    //  title="vBulletin" style="border-width: 0px 0px 1px;  font-variant: normal; border-bottom: 1px dotted rgb(0, 0, 0); cursor:  help;">vb</acronym>/scripts/Sh
    //  owCode.asp?txtCodeId=1620&lngWId=10 //for details.  //**************************************
    // 
    
    using System;
    using  System.Drawing;
    using System.Collections;
    using  System.ComponentModel;
    using System.Windows.Forms;
    using  System.Data;
    namespace InCodeTimeTest{
    public class CInCodeTimeTest :  System.Windows.Forms.Form{
    #region ConstructAndDispose
    private  System.ComponentModel.Container components = null;
    public  CInCodeTimeTest()**
    InitializeComponent();
    }
    protected override void  Dispose( bool disposing )
    **
    if( disposing )**
    if (components != null)  **
    components.Dispose();
    }
    }
    base.Dispose( disposing  );
    }
    #endregion
    #region Windows Form Designer generated code
    ///  <summary>
    /// Required method for Designer support - do not  modify
    /// the contents of this method with the code editor.
    ///  </summary>
    private void InitializeComponent()
    **
    // 
    // CInCodeTimeTest
    // 
    this.AutoScaleBaseSize = new  System.Drawing.Size(5, 13);
    this.ClientSize = new System.Drawing.Size(292,  273);
    this.Name = "CInCodeTimeTest";
    this.Text = "In Code Time  Test";
    this.Load += new  System.EventHandler(this.CInCodeTimeTest_Load);
    }
    #endregion
    #region  Main
    [STAThread]
    static void Main() 
    **
    Application.Run(new  CInCodeTimeTest());
    }
    #endregion Main
    private void  CInCodeTimeTest_Load(object sender, System.EventArgs  e)
    **
    /*
    --------------------------------
    Simple code execution time  tests
    --------------------------------
    Paste this into your C# code to  test how 
    long a portion of your  code takes to execute. 
    The number  of milliseconds is appended to  C:\TimeTest.txt
    __________________________________________________  _______________________
    |This simple solution was brought to you by the P2B  Consortium. |
    |“Create your very own artificial intelligence chat-bot  now!”|
    |http://www.p2bconsortium.com/ |
    | |
    |Create, deploy and test  artificial intelligence chat-bot |
    |now with Rapid Bot Trainer:|
    | |
    |Create, deploy and test artificial intelligence  chat-bot |
    |now with ANY IRC CLIENT and no  downloads:|
    |http://www.p2bconsortium.com/stork.html |
    | |
    |Create,  test and deploy an artificial intelligence chat-bot|
    |to ANY ONLINE CHATROOM  with the TANU public API web  methods:|
    |http://www.p2bconsortium.com/Simple%20State%20Server%20Tutorial.htm|
    |http://www.p2bconsortium.com/sss/sss.asmx|
    |_________________________________________________  ________________________|
    */
    //Start Copying Here
    System.DateTime tm =  System.DateTime.Now;
    //Stop Copying Here, Paste this before the code that you  need to time test.
    System.Threading.Thread.Sleep(1000);
    //Start Copying  Here
    System.DateTime tma = System.DateTime.Now;
    System.IO.StreamWriter sw  = System.IO.File.AppendText("C:\\TimeTest.txt");
    sw.WriteLine((((((tma.Hour *  (24 * 60 * 1000)) + (tma.Minute * (60 * 1000))) + (tma.Second * 1000)) +  tma.Millisecond) - ((((tm.Hour * (24 * 60 * 1000)) + (tm.Minute * (60 * 1000)))  + (tm.Second * 1000)) + tm.Millisecond)));
    sw.Flush();
    //Stop Copying  Here
    }
    }
    }
     
  5. کاربر پیشرفته

    تاریخ عضویت:
    ‏9/12/10
    ارسال ها:
    19,795
    تشکر شده:
    6,456
    امتیاز دستاورد:
    113
    پاسخ : كدهاي به درد بخور سي شارپ

    قرار دادن فرم در وسط صفحه در سی شارپ قرار دادن فرم در وسط صفحه در سی شارپ

    HTML:
     //**************************************
    // 
    // Name: AForm CenterScreen
    //  Description:This code provides an use
    // ful method to put a form in the  center o
    // f screen. I have found that Microsoft on
    // ly provides  property "StartPosition" so 
    // that  when the form is loaded, it is in t
    // he center of screen. What if I move it  a
    // nd then want it returns to the center?
    // By: nguyen si  hoang
    //
    // Inputs:Windows Form
    //
    // Assumes:C#  Fundamentals
    //
    // Side Effects:not at all
    //
    //This code is  copyrighted and has // limited warranties.Please see http://
    // title="vBulletin" style="border-width: 0px 0px 1px; font-variant:  normal; border-bottom: 1px dotted rgb(0, 0, 0); cursor:  help;">vb</acronym>/scripts/Sh
    //  owCode.asp?txtCodeId=4567&lngWId=10 //for details.  //**************************************
    // 
    
    /*-------------------------------------------------------------
    Copyright  © 2006,BlogicSystems. All Rights Reserved.
    Owner: Nguyen Si Hoang
    Purpose:  Put a form in the center of screen
    Date: March 09  2006
    ---------------------------------------------------------------*/
    private  void CenterScreen(Form frm)
    **
    // Get the Width and Height of the  form
    int frm_width = frm.Width;
    int frm_height = frm.Height;
    
    //Get  the Width and Height (resolution) 
    // of the  screen
    System.Windows.Forms.Screen src =  System.Windows.Forms.Screen.PrimaryScreen;
    int src_height =  src.Bounds.Height;
    int src_width = src.Bounds.Width;
    
    //put the form in  the center
    frm.Left = (src_width - frm_width) / 2;
    frm.Top = (src_height -  frm_height) / 2;
    }
     
  6. کاربر پیشرفته

    تاریخ عضویت:
    ‏9/12/10
    ارسال ها:
    19,795
    تشکر شده:
    6,456
    امتیاز دستاورد:
    113
    پاسخ : كدهاي به درد بخور سي شارپ

    ارسال ایمیل بوسیله ی vb</acronym>.net سورس ارسال ایمیل بوسیله ی vb</acronym>.net , #C

    HTML:
      //**************************************
    // 
    // Name: Sending email using DNS  server
    // Description:Sometimes sending mails u
    // sing an SMTP server is  not feasible for 
    // a project’s  requirement. We may wa
    // nt to utilize the MX record of the recip
    //  ient’s domain name. The following 
    // technical tip shows how to send mails  us
    // ing mail servers of recipient’s do
    // main. We will be using  Aspose.Network fo
    // r doing this.
    // By: aspose_seo
    //
    //  Assumes:We used Aspose.Network for Se
    // nding email using DNS  server.
    //
    //This code is copyrighted and has // limited warranties.Please  see http://
    //  title="vBulletin"  style="border-width: 0px 0px 1px; font-variant: normal; border-bottom: 1px  dotted rgb(0, 0, 0); cursor: help;">vb</acronym>/scripts/Sh
    //  owCode.asp?txtCodeId=7114&lngWId=10 //for details.  //**************************************
    // 
    
    [C#]
    MailMessage msg = new  MailMessage();
    msg.From = "sender@mail.com";
    msg.To =  "use1@mail.com;user2@mail.com";
    msg.Subject = "dns sending";
    msg.Body =  "it is a test.";
    DnsMailClient client = new  DnsMailClient();
    client.Send(msg);
    [VB</acronym>.NET]
    Dim msg As MailMessage = New  MailMessage()
    msg.From = "sender@mail.com"
    msg.To =  "use1@mail.com;user2@mail.com"
    msg.Subject = "dns sending"
    msg.Body = "it  is a test.
    Dim client As DnsMailClient = New  DnsMailClient()
    client.Send(msg)
     
  7. کاربر پیشرفته

    تاریخ عضویت:
    ‏9/12/10
    ارسال ها:
    19,795
    تشکر شده:
    6,456
    امتیاز دستاورد:
    113
    پاسخ : كدهاي به درد بخور سي شارپ

    کانورت انواع فرمت ها به PDF در vb</acronym>.net convert an Excel XLS file to PDF

    دانلود سورس کانورت انواع فرمت ها به PDF در vb</acronym>.net

    HTML:
      //**************************************
    // 
    // Name: aspose_seo
    //  Description:This technical tip shows 
    // how to convert an Excel XLS file to  PDF 
    // even if it contains any  images or charts
    // within it.
    // By: aspose_seo
    //
    // Assumes:This  technical tip shows how 
    // to  convert an Excel XLS file to PDF even
    // if it contains any images or charts  with
    // in it. You will be using Aspose.Cells an
    // d Aspose.Pdf libraries  for XLS2PDF conve
    // rsion. Please also make sure to save you
    // r  Aspose.Pdf XML file on disk, not in a 
    // stream because Aspose.Pdf XML file is  be
    // ing used as a medium to preserve those i
    // mage  files.
    //
    //This code is copyrighted and has // limited warranties.Please  see http://
    //  title="vBulletin"  style="border-width: 0px 0px 1px; font-variant: normal; border-bottom: 1px  dotted rgb(0, 0, 0); cursor: help;">vb</acronym>/scripts/Sh
    //  owCode.asp?txtCodeId=7113&lngWId=10 //for details.  //**************************************
    // 
    
    [C#] 
    // Saving an XLS file in Aspose.Pdf  xml 
    // format
    Workbook wb = new  Workbook();
    wb.Open("C:\\book1.xls);
    wb.Save("C:\\xls2pdf.xml",  FileFormatType.AsposePdf);
    // Converting XLS file to PDF through As
    //  pose.Pdf using Aspose.Pdf xml file as a 
    // medium
    Aspose.Pdf.Pdf pdf = new  Aspose.Pdf.Pdf();
    pdf.BindXML("c:\\xls2pdf.xml",  null);
    pdf.Save("C:\\xls2pdf.pdf");
    [VB</acronym>]
    ' Saving an XLS file in Aspose.Pdf xml  format
    Dim wb as Workbook = new  Workbook()
    wb.Open("C:\book1.xls)
    wb.Save("C:\xls2pdf.xml",  FileFormatType.AsposePdf)
    ' Converting XLS file to PDF through Aspose.Pdf  using Aspose.Pdf xml file as a medium
    Dim pdf as Aspose.Pdf.Pdf = new  Aspose.Pdf.Pdf()
    pdf.BindXML("c:\\xls2pdf.xml",  null)
    pdf.Save("C:\xls2pdf.pdf")
     
  8. کاربر پیشرفته

    تاریخ عضویت:
    ‏9/12/10
    ارسال ها:
    19,795
    تشکر شده:
    6,456
    امتیاز دستاورد:
    113
    پاسخ : كدهاي به درد بخور سي شارپ

    یافتن کنترل به صورت بازگشتی با استفاده از این تابعشما می توانید کنترل مورد نظر در فرم را به صورت بازگشتی پیدا کنید
    كد:
    HTML:
    public Control FindControlRecursive(Control container,  string name)
    **
    if (container.ID == name)
    return container;
    foreach  (Control ctrl in container.Controls)
    **
    Control foundCtrl =  FindControlRecursive(ctrl, name);
    if (foundCtrl != null)
    return  foundCtrl;
    }
    return null;
    }