Всем добра! Мне нужно сделать так, чтобы строчка (item) в popup-окне в моем комбобоксе (использую девовский TcxCustomComboBox), содержащая текст с символами #13#10, разбивалась на несколько строчек, но чтобы при этом это всё был один итем! То есть, чтобы при выделении одного айтема подсвечивались все строки. Я пока решил не модифицировать стандартный TcxCustomComboBox, а поиграть с его событиями. Повесил парочку обработчиков:
| Код | procedure TForm1.cxSingleLineComboBoxPropertiesDrawItem( AControl: TcxCustomComboBox; ACanvas: TcxCanvas; AIndex: Integer; const ARect: TRect; AState: TOwnerDrawState); var vSList: TStringList; vHeight: integer; vItemRect: TRect; begin ACanvas.Canvas.Brush.Color := clWhite; ACanvas.Canvas.Font.Color := clBlack; vSList := TStringList.Create(); try vSList.Text := AControl.Properties.Items[AIndex]; vSList.LineBreak := #13#10; vHeight := ACanvas.TextHeight(vSList[0]); for var i: integer := 0 to vSList.Count - 1 do ACanvas.TextOut(ARect.Left, ARect.Top + vHeight * i, i.ToString() + ') ' + vSList[i]); finally vSList.Free(); end; end; procedure TForm1.cxSingleLineComboBoxPropertiesMeasureItem( AControl: TcxCustomComboBox; AIndex: Integer; ACanvas: TcxCanvas; var AHeight: Integer); var vSList: TStringList; begin vSList := TStringList.Create(); try vSList.Text := AControl.Properties.Items[AIndex]; vSList.LineBreak := #13#10; AHeight := AHeight * vSList.Count; finally vSList.Free(); end; end;
|
Всё работает неплохо, но не получается сделать выделение. Пробовал так:
| Код | procedure TForm1.cxSingleLineComboBoxPropertiesDrawItem( AControl: TcxCustomComboBox; ACanvas: TcxCanvas; AIndex: Integer; const ARect: TRect; AState: TOwnerDrawState); var vSList: TStringList; vHeight: integer; vItemRect: TRect; begin ACanvas.Canvas.Brush.Color := clWhite; ACanvas.Canvas.Font.Color := clBlack; vSList := TStringList.Create(); try vSList.Text := AControl.Properties.Items[AIndex]; vSList.LineBreak := #13#10; vHeight := ACanvas.TextHeight(vSList[0]); vItemRect := Rect(ARect.Left, ARect.Top, AControl.Width, vHeight * vSList.Count); if odSelected in AState then ACanvas.FrameRect(vItemRect, clLime); for var i: integer := 0 to vSList.Count - 1 do ACanvas.TextOut(ARect.Left, ARect.Top + vHeight * i, i.ToString() + ') ' + vSList[i]); finally vSList.Free(); end; end;
|
но не работает. Подскажите какие-нибудь идеи как вообще такое сделать? |