تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
[VB.NET] طلب مساعدة في ادخال التاريخ ؟
#1
Heart 
السلام عليكم ورحمة الله

لدي 3 Textbox
و Datatimepacker
كود ادخال التاريخ مثلا
Textbox1.text اليوم
Textbox2.text الشهر
textbox3.text السنه 
المطلوب
عند اضافة القيم في التكست بوكس يتم ادراجها في 
Datatimepacker

وشكرا لكم بالتوفيق 
الرد }}}
تم الشكر بواسطة:
#2
وعليكم السلام ورحمة الله وبركاته :

كود :
   Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
       TextBox1.Text = Format(DateTime.Now.Day, "00")
       TextBox2.Text = Format(DateTime.Now.Month, "00")
       TextBox3.Text = Format(DateTime.Now.Year, "0000")
       TextBox1.MaxLength = 2
       TextBox2.MaxLength = 2
       TextBox3.MaxLength = 4
   End Sub

   Private Sub TextBox1_GotFocus(sender As Object, e As EventArgs) Handles TextBox1.GotFocus
       TextBox1.SelectionStart = 0
       TextBox1.SelectionLength = TextBox1.Text.Length
   End Sub

   Private Sub TextBox1_Leave(sender As Object, e As EventArgs) Handles TextBox1.Leave
       DateTimePicker1.Value = DateTimePicker1.Value.AddDays(Val(TextBox1.Text) - DateTimePicker1.Value.Day)
   End Sub

   Private Sub TextBox2_GotFocus(sender As Object, e As EventArgs) Handles TextBox2.GotFocus
       TextBox2.SelectionStart = 0
       TextBox2.SelectionLength = TextBox2.Text.Length
   End Sub
   Private Sub TextBox2_Leave(sender As Object, e As EventArgs) Handles TextBox2.Leave
       DateTimePicker1.Value = DateTimePicker1.Value.AddMonths(Val(TextBox2.Text) - DateTimePicker1.Value.Month)
   End Sub

   Private Sub TextBox3_GotFocus(sender As Object, e As EventArgs) Handles TextBox3.GotFocus
       TextBox3.SelectionStart = 0
       TextBox3.SelectionLength = TextBox3.Text.Length
   End Sub
   Private Sub TextBox3_Leave(sender As Object, e As EventArgs) Handles TextBox3.Leave
       DateTimePicker1.Value = DateTimePicker1.Value.AddYears(Val(TextBox3.Text) - DateTimePicker1.Value.Year)
   End Sub

- لاحظ أن كود التغيير يأتي بعد مغادرة مربع النص  (ليس مهما في حال اليوم والشهر،، ولكن في حال السنة سيتسبب بخطأ بمربع السنة  لأن الـ DateTimePicker1 لن تقبل التواريخ قبل 01/01/1753  ولا حتى التواريخ المستقبلية البعيدة بعد 31/12/9998،، لذلك كتبت الكود في حدث المغادرة ليتجنب ما أمكن من اخطاء)..

لا بد وأنّ هناك كود أفضل من هذا ..
ولكن هذا ما أسعفتني به التجربة الان ..
قال صلى الله عليه وسلم: 
«كلمتان خفيفتان على اللسان 
ثقيلتان في الميزان،حبيبتان إلى الرحمن: 
سبحان الله وبحمده، سبحان الله العظيم».
الرد }}}
#3
taha okla شكرا لك اخي الغالي

جاري التجربه

نجحت معي كل الشكر والتقدير اخي TAHA OKLA
الرد }}}
تم الشكر بواسطة: ابراهيم ايبو
#4
(11-04-22, 01:06 PM)Taha Okla كتب : وعليكم السلام ورحمة الله وبركاته :

كود :
   Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
       TextBox1.Text = Format(DateTime.Now.Day, "00")
       TextBox2.Text = Format(DateTime.Now.Month, "00")
       TextBox3.Text = Format(DateTime.Now.Year, "0000")
       TextBox1.MaxLength = 2
       TextBox2.MaxLength = 2
       TextBox3.MaxLength = 4
   End Sub

   Private Sub TextBox1_GotFocus(sender As Object, e As EventArgs) Handles TextBox1.GotFocus
       TextBox1.SelectionStart = 0
       TextBox1.SelectionLength = TextBox1.Text.Length
   End Sub

   Private Sub TextBox1_Leave(sender As Object, e As EventArgs) Handles TextBox1.Leave
       DateTimePicker1.Value = DateTimePicker1.Value.AddDays(Val(TextBox1.Text) - DateTimePicker1.Value.Day)
   End Sub

   Private Sub TextBox2_GotFocus(sender As Object, e As EventArgs) Handles TextBox2.GotFocus
       TextBox2.SelectionStart = 0
       TextBox2.SelectionLength = TextBox2.Text.Length
   End Sub
   Private Sub TextBox2_Leave(sender As Object, e As EventArgs) Handles TextBox2.Leave
       DateTimePicker1.Value = DateTimePicker1.Value.AddMonths(Val(TextBox2.Text) - DateTimePicker1.Value.Month)
   End Sub

   Private Sub TextBox3_GotFocus(sender As Object, e As EventArgs) Handles TextBox3.GotFocus
       TextBox3.SelectionStart = 0
       TextBox3.SelectionLength = TextBox3.Text.Length
   End Sub
   Private Sub TextBox3_Leave(sender As Object, e As EventArgs) Handles TextBox3.Leave
       DateTimePicker1.Value = DateTimePicker1.Value.AddYears(Val(TextBox3.Text) - DateTimePicker1.Value.Year)
   End Sub

- لاحظ أن كود التغيير يأتي بعد مغادرة مربع النص  (ليس مهما في حال اليوم والشهر،، ولكن في حال السنة سيتسبب بخطأ بمربع السنة  لأن الـ DateTimePicker1 لن تقبل التواريخ قبل 01/01/1753  ولا حتى التواريخ المستقبلية البعيدة بعد 31/12/9998،، لذلك كتبت الكود في حدث المغادرة ليتجنب ما أمكن من اخطاء)..

لا بد وأنّ هناك كود أفضل من هذا ..
ولكن هذا ما أسعفتني به التجربة الان ..

الكود افادني بتحويل التاريخ من الميلادي إلى الهجري

كتبت تاريخ بالميلادي فظهر لي بالهجري " للمعلومية تاريخ جهازي بالهجري

الف شكر لك على الكود
اللهم ارحم من أسس هذا المنتدى (اباليث) و أجعل كل علم نافع تعلمناه في هذا المنتدى أجر له و صدقة تنفعه في قبره
الرد }}}
تم الشكر بواسطة: ابراهيم ايبو , Taha Okla , muaamar



التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم