首页 > 其他分享 >ListBox自画

ListBox自画

时间:2024-08-14 16:05:00浏览次数:5  
标签:Index TextHeight 自画 LBox Canvas TextTopPos TextLeftPos ListBox

https://www.packtpub.com/en-us/product/delphi-cookbook-second-edition-9781785287428/chapter/delphi-basics-1/section/using-owner-draw-combos-and-listboxes-ch01lvl1sec12

 

 

procedure TForm7.ListBox1DrawItem(Control: TWinControl; Index: Integer;   Rect: TRect; State: TOwnerDrawState);
var
LBox: TListBox;
R: TRect;
S: string;
TextTopPos, TextLeftPos, TextHeight: Integer;
const
IMAGE_TEXT_SPACE = 4;       //  图标 与 文本 之间  的  间隔
begin
LBox := Control as TListBox;

R := Rect;
LBox.Canvas.FillRect(R);
ImageList1.Draw(LBox.Canvas, R.Left, R.Top, Index);   //画 图标

S := LBox.Items[Index];
TextHeight := LBox.Canvas.TextHeight(S);
TextLeftPos := R.Left +   ImageList1.Width + IMAGE_TEXT_SPACE;
TextTopPos := R.Top + R.Height div 2 - TextHeight div 2  ;
LBox.Canvas.TextOut(TextLeftPos, TextTopPos, S);      //画 文本
end;

 

标签:Index,TextHeight,自画,LBox,Canvas,TextTopPos,TextLeftPos,ListBox
From: https://www.cnblogs.com/tulater/p/18359200

相关文章

  • WPF ZoomIn ZoomOut Pan ListBox Image
    <ListBoxx:Name="lbx"Grid.Row="1"Grid.Column="0"ItemsSource="{BindingImgsList,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"SelectionChanged="lbx_SelectionChanged&quo......
  • ListBox横向排布Item
    <Windowx:Class="TwoColumnListBox.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.mi......
  • WPF ListBox's ItemsSource depend on another's ListBoxItem and fully implemented
    //xaml<Grid><Grid.ColumnDefinitions><ColumnDefinition/><ColumnDefinition/><ColumnDefinition/></Grid.ColumnDefinitions><ListBoxGrid.Column="0"ItemsSource=&......
  • Windows图形界面(GUI)-DLG-C/C++ - 列表框(ListBox)
    公开视频-> 链接点击跳转公开课程博客首页-> ​​​​​​链接点击跳转博客主页列表框(ListBox)控件类型单选列表框(Single-selectionListBox):用户一次只能选择一个列表项。它通常用于当选择范围被限定到一个单一的选项时。多选列表框(Multi-selectionListBox):用户可以同......
  • WPF ListBox's itemsource depend on another listbox's selecteditem
    //xaml<ListBoxGrid.Row="1"Grid.Column="0"ItemsSource="{Binding}"x:Name="countryLbx"DisplayMemberPath="CountryName"/><ListBoxGrid.Row="1"Grid.Column="1&......
  • 【winform】ListBox如何给item项添加hover
    1、绑定move事件listBox1.MouseMove+=newMouseEventHandler(listBox_MouseMove);2、编写代码privatevoidlistBox_MouseMove(object?sender,MouseEventArgse){ListBox?listBox=senderasListBox;//获取鼠标在ListBox中的位置int......
  • MFC---列表框控件ListBox、组合框控件Combo Box(常用控件)
    前面两节讲了比较常用的按钮控件,并通过按钮控件实例说明了具体用法。本文要讲的是列表框控件(ListBox)及其使用实例。列表框控件简介列表框给出了一个选项清单,允许用户从中进行单项或多项选择,被选中的项会高亮显示。列表框可分为单选列表框和多选列表框,顾名思义,单选列表框中......
  • WPF ListBox ListBox.ItemTemplate DataTemplate
    <Windowx:Class="WpfApp144.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.microsoft......
  • ListBox中的ItemTemplate
    //ListBox中的ItemTemplate用于定义每个单独项的外观,允许你自定义ListBox中显示的每个数据项的样式和布局。//可以在ItemTemplate中放置控件、数据绑定和其他布局结构,以便在ListBox中呈现每个数据项时具有一致的外观。ItemTemplate的使用使得ListBox能够根据需要对每个项目进行......
  • WPF ListBox thumbnails and image mvvm behavior CallMethodAction
    <Windowx:Class="WpfApp108.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.microsoft......