PDA

View Full Version : بستن یک آیتم



Mohammadi_A
شنبه 17 فروردین 1387, 11:29 صبح
با سلام خدمت دوستان
آیا میشه یک آیتم از یک Combo box را غیر فعال کرد همچنین برای موارد مشابه مثل RadioGroup - List Box و ...
اگه امکان داره ممنون میشم کدش رو برام بذارید:تشویق:

Cave_Man
شنبه 17 فروردین 1387, 13:33 عصر
کدجالبیه درمورد لیست باکس برای بقیه موارد هم میشه الگو گرفت
با اندکی تغییر
منبع :http://www.delphipages.com/threads/thread.cfm?ID=192605&G=192601


procedure SetDisabledItemLB(AListBox: TListBox; AIndex: Integer; AValue: Boolean);
begin
if not Assigned(AListBox) then
Exit;
if AIndex < AListBox.Items.Count then
begin
if AValue then
begin
if Integer(AListBox.Items.Objects[AIndex]) = 0 then
begin
if AIndex = AListBox.ItemIndex then
AListBox.Tag := -1;
AListBox.Items.Objects[AIndex] := Pointer(1);
end;
end
else
begin
if Integer(AListBox.Items.Objects[AIndex]) <> 0 then
begin
AListBox.Items.Objects[AIndex] := nil;
end;
end;
end;
end;



procedure TForm1.ListBox1Click(Sender: TObject);
begin
LockWindowUpdate(ListBox1.Handle);
with TListBox(Sender) do
begin
if Integer(Items.Objects[ItemIndex]) <> 0 then
begin
ItemIndex := Tag;
end
else
begin
Tag := ItemIndex;
end;
end;
LockWindowUpdate(0);
end;

procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
var
lb: TListBox;
begin
lb := TListBox(Control);
if Integer(lb.Items.Objects[Index]) <> 0 then
begin
lb.Canvas.Brush.Color := clBtnFace;
lb.Canvas.Font.Color := clBtnText;
end
else
begin
lb.Canvas.Brush.Color := clWindow;
lb.Canvas.Font.Color := clWindowText;
end;
if odSelected in State then
begin
lb.Canvas.Brush.Color := clHighlight;
lb.Canvas.Font.Color := clWhite;
end;
lb.Canvas.FillRect( Rect );
lb.Canvas.TextOut(Rect.left, Rect.top, lb.Items[Index]);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
SetDisabledItemLB(ListBox1,1,true);
ListBox1.Repaint;
end;