Components

Draw in TStatusBar

Posted in Components

Do not forget to set Style property of the StatusBar1.Panels to psOwnerDraw. Just write an OnDrawPanel event handler for the StatusBar like this:

procedure TForm1.StatusBar1DrawPanel(StatusBar: TStatusBar;
  Panel: TStatusPanel; const Rect: TRect);
var
  BitMap: TBitMap;
begin
  Bitmap:=TBitmap.Create;
  Bitmap.LoadFromFile('Factory.bmp');
  with StatusBar1.Canvas,Rect do 
  begin
    Brush.Color:=clRed;
    FillRect(Rect);
    Draw(Succ(Left),Succ(Top),BitMap);
  end;
end;

Disable alpha character in Edit

Posted in Components

You may use OnKeyPress event of your Edit. You should check, if key parameter is not in set '0'..'9' then you must write Key:=#0;

var
  NumSet: set of Char = ['0'..'9'];

procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
  if not (Key in NumSet) then
    Key:=#0;
end;

Disable RadioGroup item

Posted in Components

All, what you need to do, is to use Controls property of RadioGroup component.

procedure TForm1.Button1Click(Sender: TObject);
begin
  TRadioButton(RadioGroup1.Controls[1]).Enabled:=False;
end;

Detect if user select menu item

Posted in Components

Use should hook WM_MENUSELECT message for this. In this example, when user select some menu item, form color will change.

type
  TForm1 = class(TForm)
  private
    { Private declarations }
    procedure WMMenuSelect(var Msg: TWMMenuSelect);
      message WM_MENUSELECT;
  public
    { Public declarations }
  end;

...

procedure TForm1.WMMenuSelect(var Msg: TWMMenuSelect);
begin
  inherited;
  Randomize;
  Color:=RGB(Random(255), Random(255), Random(255));
end;

Delete/add item in RadioGroup

Posted in Components

Use Delete and Add procedures of the RadioGroup.Items for removing and adding item. If you want add item in RadioGroup to a defined place, then use Exchange procedure after Add procedure.

procedure TForm1.Button1Click(Sender: TObject);
begin
  RadioGroup1.Items.Delete(2);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  with RadioGroup1 do
  begin
    Items.Add('  New'+IntToStr(Items.Count-2));
    Items.Exchange(2, Items.Count-1);
  end;
end;