السلام عليكم:
هل استطيع عرض ايقون داخل ليست بوكس
وشكرا"
السلام عليكم:
هل استطيع عرض ايقون داخل ليست بوكس
وشكرا"
السلام عليكم
استخدم Listview بدل ListBox
مرحبا:
شكرا" على الرد بس انا اريد ان استخدم ( ليست بوكس) لانها تحتوي على Selectedindex
السلام عليكم
مرة اخرى باستخدام listview
ListView1.HideSelection = False
ListView1.FullRowSelect = True
ListView1.Items.Add("11112")
ListView1.Items.Add("111 312")
ListView1.Items.Add("11113323 22")
ListView1.Items(1).Selected = True
MsgBox(ListView1.SelectedItems(0).Index)جرب هذا الكود
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace ListBoxDrawing
{
public partial class frmMain : Form
{
struct Item
{
public string Text;
public Color Color;
public Bitmap Image;
public Item(string text, Color color, Bitmap img) {
Text = text;
Color = color;
Image = img;
}
}
Item item;
public frmMain()
{
InitializeComponent();
}
protected override void OnLoad(EventArgs e)
{
listBox1.DrawMode = DrawMode.OwnerDrawVariable;
listBox1.ItemHeight = 18;
listBox1.Items.Clear();
listBox1.Items.Add(new Item("www.arabteam2000-forum.com", Color.Green, Bitmap.FromHicon(this.Icon.Handle)));
listBox1.Items.Add(new Item("www.vc4arab.com", Color.Blue, Bitmap.FromHicon(this.Icon.Handle)));
listBox1.Items.Add(new Item("www.vb4arab.com", Color.Red, Bitmap.FromHicon(this.Icon.Handle)));
base.OnLoad(e);
}
private void listBox1_DrawItem(object sender, DrawItemEventArgs e)
{
try {
if(e.Index < 0)
return;
item = (Item)listBox1.Items[e.Index];
Rectangle rectImg = new Rectangle(5, e.Bounds.Top, e.Bounds.Height - 2, e.Bounds.Height - 2);
Rectangle rect = new Rectangle(rectImg.Right + 5, e.Bounds.Top + 3, e.Bounds.Height + 50, e.Bounds.Height - 7);
Brush brush;
Brush brushString;
e.DrawBackground();
if((e.State & DrawItemState.Selected) == DrawItemState.Selected) {
brush = Brushes.White;
brushString = Brushes.White;
} else {
brush = Brushes.Black;
brushString = Brushes.Gray;
}
e.Graphics.DrawImage(item.Image, rectImg);
e.Graphics.FillRectangle(new SolidBrush(item.Color), rect);
e.Graphics.DrawRectangle(Pens.Black, rect);
e.Graphics.DrawString(
item.Text, e.Font, brushString,
(10 + rectImg.Width + rect.Width + 10),
((e.Bounds.Height - e.Font.Height) / 2) + e.Bounds.Top);
} catch(Exception ex) {
MessageBox.Show(ex.Message);
}
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
item = (Item)listBox1.SelectedItem;
}
}
}السلام عليكم :
شكرا جزيلا على كل الردود..وخصوصاMoudey