تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
[مثال] لتغيير الوان العناصر داخل ComboBox الكمبو بوكس
#1
السلام عليكم ورحمة الله وبركاتة 
اضع بين ايديكم مثال لتغيير الوان العناصر داخل ComboBox الكمبو بوكس 
كل عنصر بلون معين تختارة انت
لعل ينتفع بة احد
المثال في المرفقات


الملفات المرفقة
.rar   WindowsApplication1.rar (الحجم : 72.46 ك ب / التحميلات : 41)
عن أبي هريرة - رضي الله عنه - قال: قال رسول الله - صلى الله عليه وسلم -: ((كلمتان خفيفتان على اللسان، ثقيلتان في الميزان، حبيبتان إلى الرحمن: سبحان الله وبحمده، سبحان الله العظيم))؛ متفق عليه.
الرد }}}
#2
جزاك الله خيرا
الرد }}}
تم الشكر بواسطة: abo ragab
#3
جزاكم الله خيراً .

-------------------
مع تعديل بسيط على الكود لجعل اللون تبادلي مع الحفاظ على التأثيرات البصرية في حال التمرير فوق العنصر من القائمة المنسدلة 
يصبح الكود كالتالي (مثلا) : 
كود :
Private Sub CustomComboBox_Load(sender As Object, e As EventArgs) Handles MyBase.Load
   ComboBox1.DrawMode = DrawMode.OwnerDrawVariable '' or  = DrawMode.OwnerDrawFixed

   ComboBox1.Items.Add("1")
   ComboBox1.Items.Add("2")
   ComboBox1.Items.Add("3")
   ComboBox1.Items.Add("4")
   ComboBox1.Items.Add("5")
   ComboBox1.Items.Add("6")
   ComboBox1.Items.Add("7")
   ComboBox1.Items.Add("8")

End Sub

Private Sub ComboBox1_DrawItem(sender As Object, e As DrawItemEventArgs) Handles ComboBox1.DrawItem
   ' Check if the item is valid
   If e.Index = -1 Then
       Return
   End If

   ' Get the item's text
   Dim itemText As String = ComboBox1.Items(e.Index).ToString()

   ' Check if the mouse is hovering over the item
   Dim isHovering As Boolean = (e.State And DrawItemState.Selected) = DrawItemState.Selected

   ' Define colors for the item
   Dim backColor As Color
   Dim foreColor As Color

   '=========================================================================
   ' إختيار لون الخلفية للعنصر أو السطر
   Dim t1 As Color = Color.FromArgb(255, 224, 192)
   Dim C1 As Brush = New SolidBrush(t1)
   Dim C2 As Brush = New SolidBrush(Color.FromArgb(255, 255, 255))
   '=========================================================================
   If isHovering Then
       ' Set colors for the hovered state (e.g., blue background with white text)
       ' لون خط و خلفية العنصر المظلل
       backColor = SystemColors.Highlight
       foreColor = Color.White
       e.DrawBackground()
   Else
       ' Set colors for the normal state (e.g., default background with black text)
       backColor = e.BackColor
       foreColor = e.ForeColor

       ' Draw the background of the item ' فرض اللون التبادلي
       If ComboBox1.Items(e.Index).ToString() Mod 2 = 0 Then
           e.Graphics.FillRectangle(C1, e.Bounds)
       Else
           e.Graphics.FillRectangle(C2, e.Bounds)
       End If
   End If

   ' Create a brush for the text using the determined foreground color
   Using textBrush As New SolidBrush(foreColor)
       ' Draw the item's text
       e.Graphics.DrawString(itemText, e.Font, textBrush, e.Bounds)
   End Using

   ' Draw the focus rectangle, if needed
   e.DrawFocusRectangle()
End Sub
قال صلى الله عليه وسلم: 
«كلمتان خفيفتان على اللسان 
ثقيلتان في الميزان،حبيبتان إلى الرحمن: 
سبحان الله وبحمده، سبحان الله العظيم».
الرد }}}
تم الشكر بواسطة: salamandal , abo ragab
#4
(13-09-25, 11:58 AM)salamandal كتب : جزاك الله خيرا

اللهم أمين وإياك 


(14-09-25, 03:02 AM)Taha Okla كتب : جزاكم الله خيراً .

-------------------
مع تعديل بسيط على الكود لجعل اللون تبادلي مع الحفاظ على التأثيرات البصرية في حال التمرير فوق العنصر من القائمة المنسدلة 
يصبح الكود كالتالي (مثلا) : 
كود :
Private Sub CustomComboBox_Load(sender As Object, e As EventArgs) Handles MyBase.Load
   ComboBox1.DrawMode = DrawMode.OwnerDrawVariable '' or  = DrawMode.OwnerDrawFixed

   ComboBox1.Items.Add("1")
   ComboBox1.Items.Add("2")
   ComboBox1.Items.Add("3")
   ComboBox1.Items.Add("4")
   ComboBox1.Items.Add("5")
   ComboBox1.Items.Add("6")
   ComboBox1.Items.Add("7")
   ComboBox1.Items.Add("8")

End Sub

Private Sub ComboBox1_DrawItem(sender As Object, e As DrawItemEventArgs) Handles ComboBox1.DrawItem
   ' Check if the item is valid
   If e.Index = -1 Then
       Return
   End If

   ' Get the item's text
   Dim itemText As String = ComboBox1.Items(e.Index).ToString()

   ' Check if the mouse is hovering over the item
   Dim isHovering As Boolean = (e.State And DrawItemState.Selected) = DrawItemState.Selected

   ' Define colors for the item
   Dim backColor As Color
   Dim foreColor As Color

   '=========================================================================
   ' إختيار لون الخلفية للعنصر أو السطر
   Dim t1 As Color = Color.FromArgb(255, 224, 192)
   Dim C1 As Brush = New SolidBrush(t1)
   Dim C2 As Brush = New SolidBrush(Color.FromArgb(255, 255, 255))
   '=========================================================================
   If isHovering Then
       ' Set colors for the hovered state (e.g., blue background with white text)
       ' لون خط و خلفية العنصر المظلل
       backColor = SystemColors.Highlight
       foreColor = Color.White
       e.DrawBackground()
   Else
       ' Set colors for the normal state (e.g., default background with black text)
       backColor = e.BackColor
       foreColor = e.ForeColor

       ' Draw the background of the item ' فرض اللون التبادلي
       If ComboBox1.Items(e.Index).ToString() Mod 2 = 0 Then
           e.Graphics.FillRectangle(C1, e.Bounds)
       Else
           e.Graphics.FillRectangle(C2, e.Bounds)
       End If
   End If

   ' Create a brush for the text using the determined foreground color
   Using textBrush As New SolidBrush(foreColor)
       ' Draw the item's text
       e.Graphics.DrawString(itemText, e.Font, textBrush, e.Bounds)
   End Using

   ' Draw the focus rectangle, if needed
   e.DrawFocusRectangle()
End Sub

اللهم أمين وإياك 
عن أبي هريرة - رضي الله عنه - قال: قال رسول الله - صلى الله عليه وسلم -: ((كلمتان خفيفتان على اللسان، ثقيلتان في الميزان، حبيبتان إلى الرحمن: سبحان الله وبحمده، سبحان الله العظيم))؛ متفق عليه.
الرد }}}
تم الشكر بواسطة:


المواضيع المحتمل أن تكون متشابهة .
الموضوع : الكاتب الردود : المشاهدات : آخر رد
Photo [VB.NET] طريقة توسيط النص داخل أداة ListBox أبو خالد الشكري 1 765 26-08-25, 10:18 AM
آخر رد: Taha Okla
  [مثال] البحث باستخدام ComboBox Kamil 0 283 20-04-25, 09:15 PM
آخر رد: Kamil
  برنامج البحث عن لقطة داخل صورة أخرى Taha Okla 4 1,848 27-03-24, 04:23 PM
آخر رد: عبدالكريم برشدان
  تحريك اي عنصر داخل الفورم Kamil 0 489 13-01-24, 10:52 PM
آخر رد: Kamil
Star [مشروع] كيفية نقل البيانات الموجودة في الجداول داخل قاعدة البيانات الاولى إلى قاعدة البيانات aliday03 5 1,838 26-03-23, 03:19 PM
آخر رد: sanyor77
  [مشروع] اضافة وعرض اى نوع من الملفات داخل قاعدة بيانات SQL elgokr 15 10,776 18-07-22, 01:54 AM
آخر رد: أبو خالد الشكري
Lightbulb [VB.NET] كيف يتم عمل قاعدة بيانات داخل المشروع وليس السيرفر abo.alaa315 0 1,385 03-02-22, 02:26 PM
آخر رد: abo.alaa315
  لأول مرة .... اضافة رابط داخل الDataGridView والانتقال الى الرابط أو الملف ggtt17121985 0 1,331 13-12-21, 09:31 PM
آخر رد: ggtt17121985
  [مثال] طريقة استخدام MPV Player وتضمينه داخل يرنامجك معاند الحظ 1 2,075 04-12-21, 04:37 AM
آخر رد: ابو روضة
  [مثال] حفظ ملفات لـ PDF و الوورد والاكسيل داخل قاعدة البيانات( تحديث جديد) جميل علي 18 16,928 21-11-21, 11:39 PM
آخر رد: ibra9009

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


يقوم بقرائة الموضوع: