RE: هل يمكن اضافة اكثر من tag فى ال button - Anas Mahmoud - 04-08-20
للاسف فعلا البوتون ماتقدرتش تضيف فيه غير في ال Tag
ممكن ده يبقى حل مناسب
نعمل class نحط فيه الخصائص اللي عاوزينها للبوتون
وبعدين نعمل منه نسخة لكل بوتون ونحطها في التاج
وبعدين ناخد البيانات دي من التاج لما نحتاجها
كود :
Class Product
Public Property ID As Integer
Public Property [Name] As String
Public Property Price As Double
Public Property TaxPrice As Double
Public Property Discount As Double
Public Property Descripton As String
End Class
لما نضيف زر جديد نعمل نسخة من الكلاس :
كود :
Dim ProductInfo As New Product
ProductInfo.ID = CInt(TxtID.Text)
ProductInfo.Name = TxtName.Text
ProductInfo.Price = CDbl(TxtPrice.Text)
ProductInfo.TaxPrice = CDbl(TxtTaxPrice.Text)
ProductInfo.Discount = CDbl(TxtDiscount.Text)
ProductInfo.Descripton = TxtDescription.Text
وبعدين نحط النسخة دي في التاج وكمان نحط الاسم والتكست :
كود :
ProductButton.Tag = ProductInfo
ProductButton.Name = ProductInfo.ID
ProductButton.Text = ProductInfo.Name
وفي حدث الضغط على الزر نأخد النسخة دي ونضيف اللي فيها للداتا جريد :
كود :
Private Sub ProductButton_Click(sender As Object, e As EventArgs)
Dim ProductButton As Button = sender
Dim ProductInfo As Product = ProductButton.Tag
DataGridView1.Rows.Add(ProductInfo.ID, ProductInfo.Name, ProductInfo.Price, ProductInfo.TaxPrice, ProductInfo.Discount, ProductInfo.Descripton)
End Sub
ماتنساش تضيف الحدث عند انشاء الزر :
كود :
AddHandler ProductButton.Click, AddressOf ProductButton_Click
شوف المثال ده انشاء ازرار وتخزين فيها البيانات المطلوبة وعند الضغط عليها تضيف اللي فيها للجريد
[attachment=25377]
RE: هل يمكن اضافة اكثر من tag فى ال button - mostafa nada - 06-08-20
(04-08-20, 11:17 AM)Anas Mahmoud كتب : للاسف فعلا البوتون ماتقدرتش تضيف فيه غير في ال Tag
ممكن ده يبقى حل مناسب
نعمل class نحط فيه الخصائص اللي عاوزينها للبوتون
وبعدين نعمل منه نسخة لكل بوتون ونحطها في التاج
وبعدين ناخد البيانات دي من التاج لما نحتاجها
كود :
Class Product
Public Property ID As Integer
Public Property [Name] As String
Public Property Price As Double
Public Property TaxPrice As Double
Public Property Discount As Double
Public Property Descripton As String
End Class
لما نضيف زر جديد نعمل نسخة من الكلاس :
كود :
Dim ProductInfo As New Product
ProductInfo.ID = CInt(TxtID.Text)
ProductInfo.Name = TxtName.Text
ProductInfo.Price = CDbl(TxtPrice.Text)
ProductInfo.TaxPrice = CDbl(TxtTaxPrice.Text)
ProductInfo.Discount = CDbl(TxtDiscount.Text)
ProductInfo.Descripton = TxtDescription.Text
وبعدين نحط النسخة دي في التاج وكمان نحط الاسم والتكست :
كود :
ProductButton.Tag = ProductInfo
ProductButton.Name = ProductInfo.ID
ProductButton.Text = ProductInfo.Name
وفي حدث الضغط على الزر نأخد النسخة دي ونضيف اللي فيها للداتا جريد :
كود :
Private Sub ProductButton_Click(sender As Object, e As EventArgs)
Dim ProductButton As Button = sender
Dim ProductInfo As Product = ProductButton.Tag
DataGridView1.Rows.Add(ProductInfo.ID, ProductInfo.Name, ProductInfo.Price, ProductInfo.TaxPrice, ProductInfo.Discount, ProductInfo.Descripton)
End Sub
ماتنساش تضيف الحدث عند انشاء الزر :
كود :
AddHandler ProductButton.Click, AddressOf ProductButton_Click
شوف المثال ده انشاء ازرار وتخزين فيها البيانات المطلوبة وعند الضغط عليها تضيف اللي فيها للجريد
اخى الكريم .. جزاك الله خير على اهتمامك وتعبك والله انا مش عارف اشكرك ازاى ولكن جزاك الله خيراً وربنا يزيدك بفضله
|