الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

مكتبة الأكواد

رائج
بدأه أبوفهد في 1 نوفمبر 2002 · 48 رد · 65,567 مشاهدة · في Microsoft Visual C#.NET
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

بسم الله الرحمن الرحيم ،، والصلاة والسلام على أشرف الأنبياء والمرسلين وبعد :

مكتبة الأكواد هي المكان الذي سوف يتجه إليه كل من يبحث عن كود معين ، نحاول هنا أن نقوم بجمع أكبر عدد ممكن من الأكواد بمساعدة الأخوان طبعا :) وكل أملي من الجميع من كان لديه كود معين (طبعا لانقصد البرامج الكاملة) ويحب أن ينشره في المنتدى أن يكون مكان النشر في مكتبة الأكواد .. نريد أن يتكون لدينا بعد فترة مكتبة كبيرة من الأكواد تكون مرجعا لجميع المبرمجين يقصدها القاصي والداني ..

أخوكم: أبوفهد

تم تعديل هذه المشاركة بواسطة bashmohandes في 6 سبتمبر 2005 في 05:44

#2
System.Net.IPHostEntry ass = System.Net.Dns.GetHostByName("www.arabteam2000.com");
System.Net.IPAddress []ip = ass.AddressList;
MessageBox.Show(ip[0].ToString());

إنشاء مجلد

System.IO.Directory.CreateDirectory ("c:\arabteam2000");

حذف مجلد

System.IO.Directory.Delete("c:\arabteam2000");

نقل مجلد

System.IO.Directory.Move ("c:\arabteam2000", "c:\arabteam2000");

pictureBox1.Image = System.Drawing.Image.FromFile(System.Environment.CurrentDirectory + @"csharp.jpg");

تستطيع تنفيذ الكود بشرط ان يوجد عندك صوره في نفس مسار البرنامج

ويكون اسم الصوره csharp.jpg

طبعا تستطيع التعديل في الكود وتحديد مسار مختلف وصورة مختلفة

MessageBox.Show(System.Environment.UserName);

System.Diagnostics.Process s = new System.Diagnostics.Process();
s.StartInfo.FileName ="C:\\Program Files\\MacromediaFlash 5\\Flash.exe";
s.Start();

MessageBox.Show (System.Environment.CurrentDirectory );

جميع الأعضاء الموجودة في هذه الفئة هي أعضاء ساكنة Static ..

using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.Text;

public class InternetConnectionState

{

	[DllImport("wininet.dll", CharSet = CharSet.Auto)]
  private static extern int InternetGetConnectedStateEx(

 	 ref int lpdwFlags,

 	 [MarshalAs(UnmanagedType.LPTStr)]
 	 StringBuilder lpszConnectionName,
 	 int dwNameLen,
 	 int dwReserved);
	static StringBuilder connectionName = new StringBuilder(255);// Buffer initializing
	public static bool IsConnected()
	{
  int retVal = 0;
  retVal = InternetGetConnectedStateEx(ref retVal, connectionName, connectionName.Capacity, 0);
  if(retVal == 1)
 	 return true;
  else
 	 return false;
	}
	public static string ConnectionName
	{
  get
  {
 	 return connectionName.ToString();
  }
	}
}

تم تعديل هذه المشاركة بواسطة bashmohandes في 6 سبتمبر 2005 في 05:02

#3

السلام عليكم ...

هذا كود لطبع التاريخ و الوقت بطرق عده ...

using System;
  
class myApp
{
	public static void Main()
    {
  DateTime CurrTime = DateTime.Now;
 	 
  Console.WriteLine ( "d: {0:d}" , CurrTime );
  Console.WriteLine ( "D: {0:D}" , CurrTime );
  Console.WriteLine ( "f: {0:f}" , CurrTime );
  Console.WriteLine ( "F: {0:F}" , CurrTime );
  Console.WriteLine ( "g: {0:g}" , CurrTime );
  Console.WriteLine ( "G: {0:G}" , CurrTime );
  Console.WriteLine ( "m: {0:m}" , CurrTime );
  Console.WriteLine ( "M: {0:M}" , CurrTime );
  Console.WriteLine ( "r: {0:r}" , CurrTime );
  Console.WriteLine ( "R: {0:R}" , CurrTime );
  Console.WriteLine ( "s: {0:s}" , CurrTime );
  //Console.WriteLine ("S: {0:S}" , CurrTime );  // error!!!
  Console.WriteLine ( "t: {0:t}" , CurrTime );
  Console.WriteLine ( "T: {0:T}" , CurrTime );
  Console.WriteLine ( "u: {0:u}" , CurrTime );
  Console.WriteLine ( "U: {0:U}" , CurrTime );
  Console.WriteLine ( "y: {0:y}" , CurrTime );
  Console.WriteLine ( "Y: {0:Y}" , CurrTime );
   	 
    }
}

وشكراً(f)

تم تعديل هذه المشاركة بواسطة bashmohandes في 6 سبتمبر 2005 في 05:10

If you think yourself that you are nobody, you should go somewhere to find yourself

#4

دالة الصوت

اولا اتمنى من الاستاذ ابو فهد اتحاف هذه الزاوية بمشاركاته المميزة وجميع الاعضاء

اولا نضيف هذا الأمر اعلى الشاشة البرمجية(فوق الكلاس)

using System.Runtime.InteropServices;

ثم نعرف دالة كالأتي

[DllImport("winmm.dll")]

	private static extern int PlaySoundA(string a,int b , int c);

ثم نستدعي الدالة في زر أمر كالتالي

PlaySoundA(@"file name here",0,0);
#5

مثال على التأكد من تاريخ معين باستخدام الحد الأقصى للتاريخ في تقويم

calendar

if(System.DateTime.Now.Date.CompareTo(calendar.MaxDate)>=0)
 	 {
    if(MessageBox.Show(this.ProductName+" version "+this.ProductVersion+" is expired and must be updated!nDo you want to check for updates now?",this.ProductName+" :: Version Expired",MessageBoxButtons.YesNo)==System.Windows.Forms.DialogResult.Yes)
   	 System.Diagnostics.Process.Start("http://myWebsite/myProduct.html");
    
    Application.Exit();
}

Here you can load a text file into a rich text box:

richTextBox1.LoadFile(@"icitc.icit",RichTextBoxStreamType.PlainText);

To close the application after clicking an object called "exit":

private void exit_Click(object sender, System.EventArgs e)

  {

 	 if(MessageBox.Show("Are you sure you want to exit ICit Calendar?",this.ProductName+" :: Exit",MessageBoxButtons.YesNo)==System.Windows.Forms.DialogResult.Yes)

    Application.Exit();

  }

لمعرفة تاريخ اليوم ووضعه في كائن :

private void today_Select(object sender, System.EventArgs e)

  {

 	 myDate.Text=System.DateTime.Now.Date.ToLongDateString();

  }

إظهار رسالة:

MessageBox.Show("my text","label");

لعمل check box مرتبط بشفافية النافذة:

private void transparent_Click(object sender, System.EventArgs e)

  {

 	 if(transparent.Checked)

    Opacity=1;

 	 else

    Opacity=0.5;

 	 transparent.Checked=!transparent.Checked;

  }

حفظ "Save Hashtable" في ملف xml , ويليها كود "Load ".

using System;

using System.Collections;

using System.IO;

using System.Runtime.Serialization;

using System.Runtime.Serialization.Formatters.Binary;//by Add References



namespace Example

{

	/// <summary>

	/// Summary description for Class1.

	/// </summary>

	class Class1

	{   static Hashtable Hasht;

  /// <summary>

  /// The main entry point for the application.

  /// </summary>

  [STAThread]

  static void Main(string[] args)

  {

 	 string filename="ExxmlFile.xml";

 	 Hasht=new Hashtable(5);

 	 Hasht.Add("111","Hussein");

 	 Hasht.Add("222","ArabTeam ");

 	 Hasht.Add("333","Yaser");

 	 Hasht.Add("444","Mohamad");

 	 try

 	 {

    Save(filename);

    Console.WriteLine("Saved");

               	 

 	 }

 	 catch(Exception l){Console.WriteLine(l.Message);}

  

  }

  

  

  static void Save(string filename)

  {

 	 IFormatter formatter=new BinaryFormatter();

 	 Stream stream=new FileStream(filename,FileMode.Create,FileAccess.Write,FileShare.None);

 	 formatter.Serialize(stream,Hasht);

 	 stream.Close();

  }

	}

}

//////////////////////////////Load Function/////////////////////////////////

static void Load(string filename)

  {

 	 IFormatter formatter=new BinaryFormatter();

 	 Stream stream=new FileStream(filename,FileMode.Open,FileAccess.Read,FileShare.Read);

 	 Students=(HashTable)formatter.Deserialize(stream);

 	 stream.Close();

  }

تم تعديل هذه المشاركة بواسطة bashmohandes في 6 سبتمبر 2005 في 05:11

#6

كان بحث التخرج بتاعي عباره عن برنامج إحصائي

ولقد احتجت فيه لتصميم بعض الوظائف (functions) التي تتعامل مع المصفوفات

public class Matrices
{
public static decimal[,] minuplate( decimal[,] a, decimal[,] B)// ضرب المصفوفات
  {	decimal[,] j=new decimal[1,1];
 	 decimal decimal1=0;
 	 int s,S,c,C,K,M,i=0;
 	 K=a.GetLength(1);
 	 S=a.GetLength(0);
 	 C=b.GetLength(1);
 	 M=b.GetLength(0);
 	 if((K!=1 || S!=1) && (C!=1 || M!=1) )
 	 {
   	 j=new decimal[S,C];
    for(s=0;s<S;s++)
   	 for(c=0;c<C;c++)
   	 {	for(i=0;i<K;i++)
      {decimal1+=a[s,i]*b[i,c];}
      j[s,c]=decimal1;decimal1=0;
   	 }
 	 }
 	 else if (K==1&&S==1)
 	 {
   	 j=new decimal[M,C];
    for(int I=0;I<M;I++)
    {
      for(int J=0;J<C;J++)
      j[I,J]=a[0,0]*b[I,J];
    }
 	 }
 	 else if (C==1&&M==1)
 	 {
   	 j=new decimal[S,K];
    for(int I=0;I<S;I++)
    {
   	 for(int J=0;J<K;J++)
      j[I,J]=b[0,0]*a[I,J];
    }
 	 }
  
 	 return j;
  }
  public static decimal[,] minuplate( decimal[,] a, decimal B)
  {
    int K=a.GetLength(1),S=a.Length/a.GetLength(1);
 	 decimal[,] j=new decimal[S,K];
 	 for(int i=0;i<S;i++)
 	 {
   	 for(int ii=0;ii<K;ii++)
   	 {j[i,ii]=a[i,ii]*b;	}
 	 }
 	 return j;
  }
  public static decimal[,] minuplate( decimal[,] a , decimal[,] b , decimal[,] c)
  {
    decimal[,] ab=minuplate(a,B);
 	 decimal[,] abc=minuplate(ab,c);
 	 return abc;
  }

  public static decimal[,] minuplate( decimal[,] a , decimal[,] b , decimal[,] c, decimal[,] d)
  {	decimal[,] ab=minuplate(a,B);
 	 decimal[,] abc=minuplate(ab,c);
 	 decimal[,] abcd=minuplate(abc,d);
 	 return abcd;
  }

  public static decimal sumOfMatrix(decimal[,] x)// مجموع عناصر مصفوفه
  {
 	 decimal sum=0;
 	 foreach(decimal a in x)
 	 {
    sum+=a;
 	 }
  return sum;
  }

  
  public static decimal[,] SquarOfMatrix(decimal[,] x)// تربيع مصفوفه
  {	decimal[,] xSquare=new decimal[x.GetLength(0),x.GetLength(1)];
 	 for(int i=0;i<x.GetLength(0);i++)
 	 {
   	 for(int j=0;j<x.GetLength(1);j++)
                    {xSquare[i,j]=x[i,j]*x[i,j];

   	 }
 	 }
 	 
 	 return xSquare;
  }
  public static decimal[,] Subtraction(decimal[,] a1,decimal[,] a2)//طرح المصفوفات
  {decimal[,] answer=new decimal[a1.GetLength(0),a1.GetLength(1)];
 	 for(int i=0;i<a1.GetLength(0);i++)
 	 {	for(int j=0;j<a1.GetLength(1);j++)
    {answer[i,j]=a1[i,j]-a2[i,j];	}
 	 }
  return answer;
  }

  public static decimal[,] Addition(decimal[,] a1,decimal[,] a2)//جمع المصفوفات
  {	decimal[,] answer=new decimal[a1.GetLength(0),a1.GetLength(1)];
 	 for(int i=0;i<a1.GetLength(0);i++)
 	 {for(int j=0;j<a1.GetLength(1);j++)
    {answer[i,j]=a1[i,j]+a2[i,j];	}
 	 }
 	 return answer;
  }

}

haq2600@gawab.com

تم تعديل هذه المشاركة بواسطة bashmohandes في 6 سبتمبر 2005 في 05:14

#7

كود يقوم باذالة احرف من string

using System;

namespace Consol
{

	class remove
	{
  static void Main() // Entry point
  {
 	 // Write your code here
 	 string s="AB CD";
 	 Console.WriteLine("Enter number of character you want to remove:");
 	 int nNumber=int.
 	 char []c= new char[n];
 	 s=remove(s,c);
 	 Console.WriteLine(s);

  }
public static string remove(string s,char[] c)
{
string output="";
string [] strings=s.Split©;
foreach(string substring in strings)
{
output=String.Concat(output,substring);
}
return output;
}
	}
}

تم تعديل هذه المشاركة بواسطة bashmohandes في 6 سبتمبر 2005 في 05:15

#8
**how to make OLEDataBase connection and how to get data from database**

// Set Access connection and select strings.
  // The path to BugTypes.MDB must be changed if you build the sample
  // from the command line:
#if USINGPROJECTSYSTEM
  string strAccessConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=..\\..\\BugTypes.MDB";
#else
  string strAccessConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=??.MDB"; //(??)is the path of your database file in access format
#endif
  string strAccessSelect = "SELECT * FROM Categories"; //sql query command

  // Create the dataset and add the Categories table to it:
  DataSet myDataSet = new DataSet();
  OleDbConnection myAccessConn = null;
  try
  {
 	 myAccessConn = new OleDbConnection(strAccessConn);
  }
  catch(Exception ex)
  {
 	 Console.WriteLine("Error: Failed to create a database connection. \n{0}", ex.Message);
 	 return;
  }

  try
  {
  
 	 OleDbCommand myAccessCommand = new OleDbCommand(strAccessSelect,myAccessConn);
 	 OleDbDataAdapter myDataAdapter = new OleDbDataAdapter(myAccessCommand);

 	 myAccessConn.Open();
 	 myDataAdapter.Fill(myDataSet,"Categories");

  }
  catch (Exception ex)
  {
 	 Console.WriteLine("Error: Failed to retrieve the required data from the DataBase.\n{0}", ex.Message);
 	 return;
  }
  finally
  {
 	 myAccessConn.Close();
  }

هدا الكود عبارة عن فكرة مبسطة تريك كيفية الاتصال ب الأكسيس داتابيس ,وكيفية ادخال ما يسمي بال "SQL query command" للحصول علي ما تريد من الداتا بيس, وشكرا.

منارة التقنية

http://itechflare.com

 

برنامج إستخراج سندات القبض المجاني

للمزيد

#9

يقوم هذا الكود باعطاء برنامجك Style XP

و تتم كتابته فى main()

Application.EnableVisualStyles();

الكود السابق يعطي ال XP Style فقط اذا كان البرنامج يعمل على XP يعني لو اخذت نفس البرنامج و شغلته على ME سيكون شكله عادي مثل اي برنامج على ME

Sr. Software Development Engineer
Hulu, LLC
My Blogs

#10

خطوات اساسية للتعامل مع ال DB و انا اخصص هنا SQL server 2000

SqlConnection objcon;
SqlDataAdapter objda;
DataSet ds;
string sql;
  objcon=new SqlConnection("data source(local);initialcatalog=maka;integratedsecurity=true"); 	 
sql="SELECT name FROM kind";
 	 objda=new SqlDataAdapter(sql,objcon);
 	 ds=new DataSet();
 	 objda.Fill(ds,"kind");

تم تعديل هذه المشاركة بواسطة bashmohandes في 6 سبتمبر 2005 في 05:20

#11

بالنسبة للكود الخاص لتنزيل ملف الى المكان الذي يختاره ال User

أولا يجب اضافة Namespace

using System.Net

لنفرض الان ان لديك اثنين TextBox الاول اسمه downloadURL حيث نضع فيه رابط للملف المراد تنزيله و الاخر savePath و يكون فيه مكان تخزين الملف على الجهاز بفرض وجود Button اسمه btnDownload لبدأ عملية التحميل نكتب الكود التلى في الحدث Click الخاص به

private void btnDownload_Click(object sender, System.EventArgs e)

{

   WebClient wc = new WebClient();

   wc.DownloadFile(downloadURL.Text, savePath.Text);

}

و فوق كل ذي علم عليم

#12

تم مراجعة مكتبة الأكواد و ازالة جميع المشاركات الزائدة و الأكواد التالفة و تنسيق الأكواد أرجو الحفاظ على تنظيم المكتبة و إلا سأضطر لغلقها

Sr. Software Development Engineer
Hulu, LLC
My Blogs

#13

السلام عليكم

اجراء عمليه على نوع من controls

نفرض ان لديك فورم معينه وتريد ان تقوم باجراء عملية ما على نوع معين من الكنترولز الموجوده بالفورم

using System;
using System.Windows.Forms;

public class process : System.Windows.Forms.Form {

    //كود تم توليده تلقائياً من فيجوال ستوديو ومحذوف

    private void processbtn_Click(object sender, System.EventArgs e) {
        ProcessControls(this);
    }

    private void ProcessControls(Control ctrl) {
    
        //يقوم بتحديد نوع الكنترول ..نود ان نقوم بالعمليه فقط على الtextbox
        if (ctrl.GetType() == typeof(TextBox)) {
            ctrl.Text = "";
        }
        
        //نقوم بتكملة العمليه عن طريق ال recursion
        //وهى تقنية تستخدم فى بعض الmethods
         
        foreach (Control ctrlChild in ctrl.Controls) {
            ProcessControls(ctrlChild);
        }
    }
}

يمكن عمل السابق باكثر من طريقه اخرى وابسط من ذلك

عمل فورم لا يمكن تحريكها

form1.FormBorderStyle=FormBorderStyle.None
#14

مجموعة من الكود , رائعة لبرمجة Windows Applications

و اخرى Consol Application

تم حذف كود الConsole لعدم وجود شرح مع الكود

و شكراً

WA Code.zip

تم تعديل هذه المشاركة بواسطة bashmohandes في 7 سبتمبر 2005 في 23:32

#15

يقوم هذا الكود البسيط بجلب ال IP-Address الخاص بالهوست ... بعد ادخال اسم الهوست

using System;
using System.Net;

class GTest
{
	public static void Main()
	{
  string strHost;
  Console.Write("Input host : "); 
 // ادخال اسم الهوست
  strHost = Console.ReadLine();
//جلب جميع ال اي بيس الخاصة بهذا الهوست ووضعها في مصفوفة
  IPHostEntry IPHost = Dns.Resolve(strHost);
  Console.WriteLine(IPHost.HostName); 
  IPAddress [] address = IPHost.AddressList; 
  Console.WriteLine("List IP {0} :",IPHost.HostName); 
  for(int i = 0;i< address.Length; i++)
 //عرض جميع محتويات المصفوفة و التي تحتوي على كل الأي بيس
  Console.WriteLine(address);
	}
}

تم تعديل هذه المشاركة بواسطة fmo_82 في 9 سبتمبر 2005 في 16:35

#16

بستخدام الخاصية Environment.TickCount نستطيع معرفة الوقت المنقضي للتشغيل بأجزاء الثواني , بإمكانك الإستفادة من هذه الخاصية فيما بعد لعمل برنامج يقوم بعمل تقارير اوقات التشغيل للجهاز والوقت المنقضي للتشغيل ,

تقوم الميثود التالية بحساب الوقت المنقضي للتشغيل و ارجاع قيمة String تحتوي على الساعات و الدقائق ...

public string time()
{
int mm =  ((Environment.TickCount / 1000) / 60);
int hrc = mm/60;
int min = mm%60;
return  hrc.ToString () + ":" + min.ToString ();
}
#17

ودة عبارة عن كود يتم إنشاء Button and picturebox at runtime

ثم يتم إختيار أى من الصور عن طريق DialogBox وتحميلها فى الpictureBox وعند عمل Rsize للForm يتم عمل Resize

للPicturebox and Button عن طريق إستخدامanchor

windowsApplicationBook.rar

Muhammad Allam

Computer Science

@Resource(MappedURL="My Blog" )

#18

كود لحساب نهاية الشهر :

نجد عدد أيام الشهر عن طريق استخدام الدالة DateTime.DaysInMonth

وبذلك نكون قد حصلنا على رقم آخر يوم بالشهر

ثم نقارنها برقم اليوم الموجودين في نحن

private void IsEndOfMonth(int day)
{
            if (day == DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month))
            {
               MessageBox.Show("it is the last day in this Month");
            }
            else
            {
               MessageBox.Show("it is Not the last day in this Month");
            }
}

مثال :

int Today = DateTime.Now.Day;
IsEndOfMonth(Today);
#19

هذا الكود يوضح كيفية التحكم في خاصية Transparency للـ Form

using System;
using System.Drawing;
using System.Windows.Forms;

namespace transparency
{
	public class frmMain : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Button btnTrans;
		static int i = 0;

		public frmMain()
		{
			InitializeComponent();

		}

		private void InitializeComponent()
		{
			this.btnTrans = new System.Windows.Forms.Button();
			this.SuspendLayout();
			// 
			// btnTrans
			// 
			this.btnTrans.Location = new System.Drawing.Point(168, 96);
			this.btnTrans.Name = "btnTrans";
			this.btnTrans.TabIndex = 0;
			this.btnTrans.Text = "Click me";
			this.btnTrans.Click += new System.EventHandler(this.btnTrans_Click);
			// 
			// frmMain
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(250, 200);
			this.Controls.Add(this.btnTrans);
			this.Name = "frmMain";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "Transparency";
			this.Paint += new System.Windows.Forms.PaintEventHandler(this.frmMain_Paint);
			this.ResumeLayout(false);
		}

		[STAThread]
		static void Main() 
		{
			Application.Run(new frmMain());
		}

		private void btnTrans_Click(object sender, System.EventArgs e)
		{
			btnTrans.Text = "Next Color";
			i++;
			if (i == 1)
				this.Opacity = 0.75;
			else if (i ==2 )
				this.TransparencyKey = System.Drawing.Color.Red;
			else if (i ==3 )
				this.TransparencyKey = System.Drawing.Color.Green;
			else if (i ==4 )
				this.TransparencyKey = System.Drawing.Color.Blue;
			else if (i ==5 )
				this.TransparencyKey = System.Drawing.Color.Black;
			else if (i ==6 )
				this.TransparencyKey = System.Drawing.Color.Empty;
			else if (i ==7 )
				this.Opacity = 1;

			if (i >= 7)
				i = 0;
		}

		private void frmMain_Paint(object sender, System.Windows.Forms.PaintEventArgs e) {
			e.Graphics.FillRectangle(Brushes.Red, 0,0,100,50);
			e.Graphics.FillRectangle(Brushes.Green, 0,50,100,50);
			e.Graphics.FillRectangle(Brushes.Blue, 0,100,100,50);
			e.Graphics.FillRectangle(Brushes.Black, 0,150,100,50);
		}
	}
}

مواضيع متنوعة

#20

السلام عليكم

ده ان شاء الله كود عشان اخلي TextBox يتكتب فيها ارقام بس

للتطبيق خد الكود كوبي و بيست في ال KeyPress event

bool Num=false;
for(int x=48;x<=57;x++)
{
if(e.KeyChar==(char)x)
Num=true;
}
if(e.KeyChar==(char)8)
e.Handled=false;
else if(!Num)
e.Handled=true;
1
#21

السلام عليكم و رحمة الله وبركاته

كذلك يمكن استخدام الكود الآتي و يضع في الحدث KeyPress الخاص بال TextBox

لكتابة أرقام صحيحة فقط

if(Char.IsNumber(e.KeyChar) || e.KeyChar==(char)8)
			{
				e.Handled=false;
			}
			else e.Handled=true;

للسماح بكتابة علامة عشرية

if(Char.IsNumber(e.KeyChar) || e.KeyChar==(char)8 || (e.KeyChar=='.' & ((TextBox)sender).Text.IndexOf('.')<0))
			{
				e.Handled=false;
			}
			else e.Handled=true;

و فوق كل ذي علم عليم

#22

السلام عليكم

ماتقوموا به شيء ممتاز وياحبذا لو قمتم باضافة الاكواد داخل مكتبة الاكواد في الصفحة الرئيسية للموقع ويمكن للجميع الاضافة وسوف تظهر مباشرة بعد عملية الموافقة عليها من قبل المشرف

http://www.arabteam2000.com

جديد مدونتي الشخصية http://www.badwi.com

ادعو لنا بظاهر الغيب

MyBooksExchange.jpg

#23

أريد ان أقدّم هذا الكود ل

Binary Search Tree

Class Node

**********

using System;

namespace BinaryNode
{
	class Node
	{
		public object item;
		public Node left;
		public Node right;

		public Node(object it)
		{
			item = it;
			left = null;
			right = null;
		}

		public Node(object it, Node lf, Node rt)
		{
			item = it;
			left = lf;
			right = rt;
		}
	}
}

Class CSharpBinaryTree

********************

using System;
using BinaryNode;


namespace BinarySearchTree
{
	public class CSharpBinaryTree
	{
		private Node root;
		private readonly object ITEM_NOT_FOUND;

		public CSharpBinaryTree(object itemNotFound)
		{
			root = null;
			ITEM_NOT_FOUND = itemNotFound;
		}

		~CSharpBinaryTree()
		{
			makeEmpty();
		}

		private bool isEmpty()
		{
			return root == null;
		}

		private object elementAt(Node temp)
		{
			return (temp == null) ? ITEM_NOT_FOUND : temp.item;
		}

		public void makeEmpty()
		{
			makeEmpty(ref root);
		}

		private void makeEmpty(ref Node temp)
		{
			if (temp != null)
			{
				makeEmpty(ref temp.left);
				makeEmpty(ref temp.right);
				temp = null;
			}
		}

		public object findMin()
		{
			return elementAt(findMin(ref root));
		}

		private Node findMin(ref Node temp)
		{
			if (temp == null)
			{
				return null;
			}
			else if (temp.left == null)
			{
				return temp;
			}
			else
			{
				return findMin(ref temp.left);
			}
		}

		public object findMax()
		{
			return elementAt(findMax(ref root));
		}

		private Node findMax(ref Node temp)
		{
			if (temp == null)
			{
				return null;
			}
			else if (temp.right == null)
			{
				return temp;
			}
			else
			{
				return findMax(ref temp.right);
			}
		}

		public object find(ref object obj)
		{
			return elementAt(find(ref obj, ref root));
		}

		private Node find(ref object obj, ref Node temp)
		{
			if (temp == null)
			{
				return null;
			}
			else if (obj.ToString().CompareTo(temp.item.ToString()) < 0)
			{
				return find(ref obj, ref temp.left);
			}
			else if (obj.ToString().CompareTo(temp.item.ToString()) > 0)
			{
				return find(ref obj, ref temp.right);
			}
			else
			{
				return temp;
			}
		}

		public void insert(object obj)
		{
			insert(ref obj, ref root);
		}

		private void insert(ref object obj, ref Node temp)
		{
			if (temp == null)
			{
				temp = new Node(obj);
			}
			else if (obj.ToString().CompareTo(temp.item.ToString()) < 0)
			{
				insert(ref obj, ref temp.left);
			}
			else if (obj.ToString().CompareTo(temp.item.ToString()) > 0)
			{
				insert(ref obj, ref temp.right);
			}
			else
			{
			;
			}
		}

		public void remove(object obj)
		{
			remove(ref obj, ref root);
		}

		private void remove(ref object obj, ref Node temp)
		{
			if (temp == null)
			{
				Console.WriteLine("The Tree You Are Deleting From Is Empty");
			}
			else if (obj.ToString().CompareTo(temp.item.ToString()) < 0)
			{
				remove(ref obj, ref temp.left);
			}
			else if (obj.ToString().CompareTo(temp.item.ToString()) > 0)
			{
				remove(ref obj, ref temp.right);
			}
			else if (temp.left != null && temp.right != null)
			{
				temp.item = findMin(ref temp.right).item;
				remove(ref temp.item, ref temp.right);
			}
			else
			{
				temp = (temp.left != null) ? temp.left : temp.right;
			}
		}

		public void printTreeInOrder()
		{
			if (isEmpty())
			{
				Console.WriteLine("The Tree Is Empty");
			}
			else
			{
				printTreeInOrder(root);
			}
		}

		private void printTreeInOrder(Node temp)
		{
			if (temp == root)
			{
				Console.Write("The Tree Elements Are:\n\t");
			}
			if (temp != null)
			{
				printTreeInOrder(temp.left);
				Console.Write(" " + temp.item.ToString());
				printTreeInOrder(temp.right);
			}
			if (temp == findMax(ref root))
			{
				Console.WriteLine("\n");
			}
		}

		public static void Main(string[] FinalHeaven)
		{
			CSharpBinaryTree csbt = new CSharpBinaryTree(-1);

			csbt.insert(50);
			csbt.insert(60);
			csbt.insert(40);
			csbt.insert(45);
			csbt.insert(55);
			csbt.printTreeInOrder();

			Console.WriteLine("Deleting 50");
			csbt.remove(50);
			csbt.printTreeInOrder();

			Console.WriteLine("Deleting 60");
			csbt.remove(60);
			csbt.printTreeInOrder();

			Console.WriteLine("Deleting 40");
			csbt.remove(40);
			csbt.printTreeInOrder();

			Console.WriteLine("Deleting 45");
			csbt.remove(45);
			csbt.printTreeInOrder();

			Console.WriteLine("Deleting 55");
			csbt.remove(55);
			csbt.printTreeInOrder();

			Console.ReadKey();
		}
	}
}

[

و كن فتى في ذرى العلياء همّته

يسمو بغاياته حتى على زحل

موقع خاص بي

My Website

قمت بتصميم لعبة بسيطة بإستخدام اللغة الجميلة الجافا

Plane Fighter Game

برنامج جميل بلغة الجافا يساعد على تنظيم المشاكل

The TS Organizer

#25

هذا الكود لتغيير في خصائص الصورة

System.Drawing.Bitmap B1 = new Bitmap(this.pictureBox1.Image);
			this.pictureBox1.Image = B1;
			System.Drawing.Bitmap TempB = new Bitmap(this.pictureBox1.Image);
			int I, J;
			int DX, DY;
			int R, G, B;
			Random RR = new Random();
			for (I = 3; I < TempB.Height - 3; I++)
			{
				for (J = 3; J <= TempB.Width - 3; J++)
				{
					DX = RR.Next(4)  - 2;
					DY =  RR.Next(4)  - 2;
					R = TempB.GetPixel (J + DX,I + DY).R;
					G = TempB.GetPixel(J + DX, I + DY).G;
					B = TempB.GetPixel(J + DX, I + DY).B;
					B1.SetPixel(J, I, Color.FromArgb(R, G, B));
				}
				this.pictureBox1.Refresh();
			}

هذا الكود لعرض التاريخ الهجري

 

using System.Globalization;




DateTimeFormatInfo DTFormat = new CultureInfo("ar-sa", false).DateTimeFormat;
DTFormat.Calendar = new HijriCalendar();
DTFormat.ShortDatePattern = "dd/mm/yyyy";

string myDate = DateTime.Today.Date.ToString("f",DTFormat);

نقل محتويات ListBox إلى أخرى

 



private void button1_Click(object sender, System.EventArgs e)
{
 while(this.listBox1.SelectedIndices.Count>0) 
 {
  this.listBox2.Items.Add (this.listBox1.SelectedItems[0]);	 
  this.listBox1.Items.Remove (this.listBox1.SelectedItems[0]);	 
 }
}

(h)

التعامل مع XML

 

private void button1_Click(object sender, EventArgs e)
		{
			//using System.Xml; 
			XmlDocument W = new XmlDocument();
			if (!System.IO.File.Exists(@"F:\aa.xml"))
			{
				//في حال عدم وجود الملف أنشئ الملف
				XmlDeclaration Doc = W.CreateXmlDeclaration("1.0", "", "yes");
				W.PrependChild(Doc);
				XmlElement Emps = W.CreateElement("TBPhone");
				W.AppendChild(Emps);
			}
			else
				W.Load(@"F:\aa.xml"); // إذا كان الملف موجود فحمله

		  XmlElement NodeP = W.DocumentElement;
		  XmlElement Note_Phones = W.CreateElement("Note_Phones");
		  Note_Phones.SetAttribute("PhoneNo", this.txtPhoneNo.Text);
		  NodeP.AppendChild(Note_Phones);
		  XmlElement FName = W.CreateElement("FName");
		  FName.InnerText = this.txtFName.Text;
		  Note_Phones.AppendChild(FName);
		  XmlElement LName = W.CreateElement("LName");
		  LName.InnerText = this.txtLName.Text;
		  Note_Phones.AppendChild(LName);
		  W.Save(@"F:\aa.xml");


		}

يا أيها الناس قولو لا إله إلا الله تفلحوا وتملكوا بها العرب وتذل لكم العجم وإذا آمنتم كنتم ملوكا في الجنة

مواضيع مشابهة