- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我试图使 ListView 的列从右到左显示。这已经是 asked and answered 。但问题在于图标和复选框。当我使用 SetWindowLong 制作 ListView RTL 时,它也会镜像图形和复选框,这是不需要的。我可以使用编辑工具镜像图形,虽然麻烦但可行,但我不知道如何处理复选框。
我认为他们都有相同的原因,所以我搜索了一下,在 Microsoft Docs 中找到了一篇关于 RTL 布局的完整文章。在Activating Mirroring per Device Context部分指出了图形问题。它建议使用 LAYOUT_RTL
和 LAYOUT_BITMAPORIENTATIONPRESERVED
标志更改 DC 的布局样式。
这是我结合文章中建议的方法和上面提到的答案实现的功能:
const
LAYOUT_RTL = 1;
LAYOUT_BITMAPORIENTATIONPRESERVED = 8;
function GetLayout(DC: HDC): DWORD; stdcall; external 'gdi32.dll';
function SetLayout(DC: HDC; dwLayout: DWORD): DWORD; stdcall; external 'gdi32.dll';
procedure MakeRTL(const Handle: HWND);
var
DC: HDC;
begin
SetWindowLong(Handle, GWL_EXSTYLE,
GetWindowLong(Handle, GWL_EXSTYLE) or WS_EX_LAYOUTRTL);
DC := GetWindowDC(Handle);
if DC <> 0 then
SetLayout(DC, GetLayout(DC) or LAYOUT_RTL or LAYOUT_ORIENTATIONMASK);
InvalidateRect(Handle, nil, True);
end;
但这并没有改变任何事情。我尝试阻止它们中的任何一个,更改它们的顺序并更改不同的位置来调用它,但没有成功。
现在的问题是,如何使ListView的列从右向左显示,而不需要镜像图形或复选框?
我使用的是 Win10 x64 和 Delphi 2010。
如果你想重现这个问题,这里是我的delphi代码:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, ImgList, StdCtrls, CommCtrl, ShellAPI;
type
TForm1 = class(TForm)
ListView1: TListView;
ImageList1: TImageList;
ListView2: TListView;
Button1: TButton;
Label1: TLabel;
procedure FormActivate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Label1Click(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
const
LAYOUT_RTL = 1;
LAYOUT_BTT = 2;
LAYOUT_VBH = 4;
LAYOUT_ORIENTATIONMASK = LAYOUT_RTL or LAYOUT_BTT or LAYOUT_VBH;
LAYOUT_BITMAPORIENTATIONPRESERVED = 8;
function GetLayout(DC: HDC): DWORD; stdcall; external 'gdi32.dll';
function SetLayout(DC: HDC; dwLayout: DWORD): DWORD; stdcall; external 'gdi32.dll';
procedure MakeRTL(const Handle: HWND);
var
DC: HDC;
begin
SetWindowLong(Handle, GWL_EXSTYLE,
GetWindowLong(Handle, GWL_EXSTYLE) or WS_EX_LAYOUTRTL);
DC := GetWindowDC(Handle);
if DC <> 0 then
SetLayout(DC, GetLayout(DC) or LAYOUT_RTL or LAYOUT_ORIENTATIONMASK);
InvalidateRect(Handle, nil, True);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
MakeRTL(ListView_GetHeader(ListView1.Handle));
MakeRTL(ListView1.Handle);
end;
procedure TForm1.FormActivate(Sender: TObject);
var
I: Integer;
begin
for I := 0 to ListView1.Items.Count - 1 do
begin
ListView1.Items[I].Checked := True;
ListView2.Items[I].Checked := True;
end;
end;
procedure TForm1.Label1Click(Sender: TObject);
begin
ShellExecute(0, 'open', 'https://icons8.com/icons/set/check', '', '', SW_SHOWNORMAL);
end;
end.
dfm:
object Form1: TForm1
Left = 0
Top = 0
BiDiMode = bdLeftToRight
Caption = 'Form1'
ClientHeight = 169
ClientWidth = 353
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
ParentBiDiMode = False
OnActivate = FormActivate
PixelsPerInch = 96
TextHeight = 13
object Label1: TLabel
Left = 277
Top = 128
Width = 47
Height = 26
Cursor = crHandPoint
Alignment = taCenter
Caption = 'graphics by Icons8'
Font.Charset = DEFAULT_CHARSET
Font.Color = clBlue
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = [fsUnderline]
ParentFont = False
WordWrap = True
OnClick = Label1Click
end
object ListView1: TListView
Left = 8
Top = 8
Width = 250
Height = 73
Checkboxes = True
Columns = <
item
Caption = 'Cap'
Width = 100
end
item
Caption = 'Sub1'
Width = 100
end>
Items.ItemData = {
03620000000200000000000000FFFFFFFFFFFFFFFF01000000FFFFFFFF000000
00054900740065006D00310005500072006F007000310001000000FFFFFFFFFF
FFFFFF01000000FFFFFFFF00000000054900740065006D00320005500072006F
0070003200FFFFFFFF}
LargeImages = ImageList1
SmallImages = ImageList1
TabOrder = 0
ViewStyle = vsReport
end
object ListView2: TListView
Left = 8
Top = 87
Width = 250
Height = 73
Checkboxes = True
Columns = <
item
Caption = 'Cap'
Width = 100
end
item
Caption = 'Sub1'
Width = 100
end>
Items.ItemData = {
03620000000200000000000000FFFFFFFFFFFFFFFF01000000FFFFFFFF000000
00054900740065006D00310005500072006F007000310001000000FFFFFFFFFF
FFFFFF01000000FFFFFFFF00000000054900740065006D00320005500072006F
0070003200FFFFFFFF}
SmallImages = ImageList1
TabOrder = 1
ViewStyle = vsReport
end
object Button1: TButton
Left = 264
Top = 8
Width = 75
Height = 25
Caption = 'RTL'
TabOrder = 2
OnClick = Button1Click
end
object ImageList1: TImageList
ColorDepth = cd32Bit
DrawingStyle = dsTransparent
Left = 272
Top = 40
Bitmap = {
494C0101020008003C0010001000FFFFFFFF2110FFFFFFFFFFFFFFFF424D3600
0000000000003600000028000000400000001000000001002000000000000010
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000618062C0E3E0E741557159F1557159F0E3F0E730617062B0000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000001456149E218A
21FE218B21FF218B21FF218B21FF218B21FF218B21FF218B21FF218B21FF218B
21FF218A21FE1455149C00000000000000000000000000000000000000000107
010D145814A1218A21FE218B21FF218B21FF218B21FF218B21FF218A21FE1557
159F0207020C0000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000218A21FD218B
21FF218B21FF218B21FF218B21FF218B21FF218B21FF218B21FF218B21FF218B
21FF218B21FF218921FC000000000000000000000000000000000107010D1B71
1BCF218B21FF218B21FF218B21FF218B21FF218B21FF218B21FF218B21FF218B
21FF1A701ACE0207020C00000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000218B21FF218B
21FF218B21FF218B21FF155915A4208520F4218B21FF218B21FF218B21FF218B
21FF218B21FF218B21FF00000000000000000000000000000000165816A2218B
21FF218B21FF218B21FF155915A4208520F4218B21FF218B21FF218B21FF218B
21FF218B21FF1456149E00000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000218B21FF218B
21FF218B21FF124E128F000100010929094B208720F8218B21FF218B21FF218B
21FF218B21FF218B21FF00000000000000000000000005160528218A21FD218B
21FF218B21FF114A1187000000000722073E208520F4218B21FF218B21FF218B
21FF218B21FF218A21FD05150526000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000218B21FF218B
21FF114A1187000000000D3B0D6C010901110722073E208520F4218B21FF218B
21FF218B21FF218B21FF0000000000000000000000000F430F7B218B21FF218B
21FF114A1187000000000D3B0D6C010901110722073E208520F4218B21FF218B
21FF218B21FF218B21FF0F410F78000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000218B21FF1A6B
1AC400000000114A1187218B21FF1B6F1BCC010901110722073E208420F3218B
21FF218B21FF218B21FF0000000000000000000000001557159F218B21FF1A6B
1AC400000000114A1187218B21FF1B6F1BCC010901110722073E208420F3218B
21FF218B21FF218B21FF1456149E000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000218B21FF218B
21FF196919C1218B21FF218B21FF218B21FF1B6F1BCC010901110722073E2084
20F3218B21FF218B21FF0000000000000000000000001456149E218B21FF218B
21FF196919C1218B21FF218B21FF218B21FF1B6F1BCC010901110722073E2084
20F3218B21FF218B21FF1456149D000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000218B21FF218B
21FF218B21FF218B21FF218B21FF218B21FF218B21FF1A691AC00006000B0925
0944208620F6218B21FF0000000000000000000000001044107C218B21FF218B
21FF218B21FF218B21FF218B21FF218B21FF218B21FF1A6F1ACB010901110722
073E208420F3218B21FF10421079000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000218B21FF218B
21FF218B21FF218B21FF218B21FF218B21FF218B21FF218B21FF1A6F1ACB0310
031E1B711BD0218B21FF0000000000000000000000000519052D218A21FE218B
21FF218B21FF218B21FF218B21FF218B21FF218B21FF218B21FF1A6F1ACB0310
031E1B711BD0218A21FE0617062B000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000218B21FF218B
21FF218B21FF218B21FF218B21FF218B21FF218B21FF218B21FF218B21FF2087
20F8218B21FF218B21FF00000000000000000000000000000000165E16AC218B
21FF218B21FF218B21FF218B21FF218B21FF218B21FF218B21FF218B21FF2087
20F8218B21FF155C15A800000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000218A21FD218B
21FF218B21FF218B21FF218B21FF218B21FF218B21FF218B21FF218B21FF218B
21FF218B21FF218921FC00000000000000000000000000000000020902101B72
1BD1218B21FF218B21FF218B21FF218B21FF218B21FF218B21FF218B21FF218B
21FF1B711BD00108010F00000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000001456149E2188
21F9218B21FF218B21FF218B21FF218B21FF218B21FF218B21FF218B21FF218B
21FF218821F91455149C00000000000000000000000000000000000000000209
0210165E16AD218B21FF218B21FF218B21FF218B21FF218B21FF218A21FE165D
16AB0108010F0000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
000000000000061A062F10471082155915A4155915A4114611810519052E0000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000424D3E000000000000003E000000
2800000040000000100000000100010000000000800000000000000000000000
000000000000000000000000FFFFFF0000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
000000000000}
end
end
最佳答案
您的调用没有效果的原因是您检索到的设备上下文根本没有以任何方式使用。您应该怀疑这一点,因为在您当前的设计中,您甚至无法调用 ReleaseDC
并且 DC 泄漏。
当系统通过发送绘画消息触发它时,所有绘画都在一个绘画周期中完成。您可以拦截该消息以修改要使用的设备上下文的布局 - VCL 设计允许您首先检索上下文。
下面是经过相应修改的完整示例代码,使用插入器类来修改 ListView 的消息处理。
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, ImgList, StdCtrls, CommCtrl, ShellAPI;
type
TListView = class(comctrls.TListView)
protected
procedure WMPaint(var Message: TWMPaint); message WM_PAINT;
end;
TForm1 = class(TForm)
ListView1: TListView;
ImageList1: TImageList;
ListView2: TListView;
Button1: TButton;
Label1: TLabel;
procedure FormActivate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Label1Click(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function GetLayout(DC: HDC): DWORD; stdcall; external 'gdi32.dll';
function SetLayout(DC: HDC; dwLayout: DWORD): DWORD; stdcall; external 'gdi32.dll';
procedure MakeRTL(const Handle: HWND);
begin
SetWindowLong(Handle, GWL_EXSTYLE,
GetWindowLong(Handle, GWL_EXSTYLE) or WS_EX_LAYOUTRTL);
InvalidateRect(Handle, nil, True);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
MakeRTL(ListView_GetHeader(ListView1.Handle));
MakeRTL(ListView1.Handle);
end;
procedure TForm1.FormActivate(Sender: TObject);
var
I: Integer;
begin
for I := 0 to ListView1.Items.Count - 1 do
begin
ListView1.Items[I].Checked := True;
ListView2.Items[I].Checked := True;
end;
end;
procedure TForm1.Label1Click(Sender: TObject);
begin
ShellExecute(0, 'open', 'https://icons8.com/icons/set/check', '', '', SW_SHOWNORMAL);
end;
{ TListView }
const
LAYOUT_RTL = 1;
LAYOUT_BITMAPORIENTATIONPRESERVED = 8;
procedure TListView.WMPaint(var Message: TWMPaint);
var
Layout: DWORD;
PS: TPaintStruct;
begin
Message.DC := BeginPaint(Handle, PS);
Layout := GetLayout(Message.DC);
if (Layout and LAYOUT_RTL) <> 0 then
SetLayout(Message.DC, Layout or LAYOUT_BITMAPORIENTATIONPRESERVED);
inherited;
EndPaint(Handle, PS);
end;
end.
关于listview - 防止 RTL TListView 镜像复选框和/或图形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53968824/
我正在使用 Embarcadero 的 C++ Builder XE8。我有一个 ListView 并动态添加列及其项目。我需要一个图像列表,因为我想使用 (ListItem->SubItemImag
我正在尝试在 TListView 中放置一个图标当某些行显示时,我有 TImageList与加载的图像,但它没有连接。我的代码是这样的 with sListView2 do begin test
当使用 TListView 并且主题在应用程序中被禁用时,焦点和选定的项目显示如下: 注意两个图像中三角形所在的位置。项目的绘制框不会在图标出现的位置绘制。在 TListBox 中,绘制的项目填充整个
我已经使用 TListView 制作了我的应用程序,以将主数据集显示为列表作为导航记录的方式。我已将 LiveBindings 与 Sync * 连接一起使用。 主要问题是它将整个表加载到内存中。大
我有一个 TListView 的后代,它提供了一些附加功能,例如排序和从 TDataset 加载自身的能力。我现在希望进一步扩展这个组件,以便在将项目添加到 ListView 时可以指定绘图的某些方面
TListView 控件是否有一个在控件滚动时触发的事件? 我宁愿不必对 TListView 控件进行子类化。 最佳答案 这非常有效,但可能会违反您问题的限制。 在包含使用 TListView 的表单
编写 FMX 应用程序并使用以下文档... http://docwiki.embarcadero.com/RADStudio/Berlin/en/Customizing_FireMonkey_List
我创建了 ListView 并添加了复选框来检查每一行(如果需要)。一切都很好,直到 ListView 中有很多项目,因此需要对其进行排序。我在线检查,然后发现如果滚动滚动条,复选框不会与其他内容一起
我正在对 tlistview 进行编程,以便它从右到左显示其列(以便正确显示希伯来语文本)。我在表单的创建方法中使用以下代码,其中“lv”是 ListView SetWindowLong (lv
我有一个包含 3 列的 Tlistview,我需要来自 Tcollection 对象,如下所示 FListeDispoProduit := TListeDispoProduit.Create(TPro
我有一个显示小缩略图的TListView(ViewStyle:=vsIcon)。在运行时,我将图像分配给项目: for i := 0 to Total - 1 DO with ListVie
我正在使用 Delphi 2010,并且我试图允许用户在 TListView 中的每行 2 个选项之间进行选择。使用 TListView,我可以将样式设置为 vsReport 并启用复选框,但这只会让
当项目添加到 TListView 时,如何捕获事件? 根据文档,我认为 OnInsert 事件可以完成这项工作。它甚至将实际的 TListItem 对象传递给处理程序: OnInsert Occurs
是否可以修复 TListView 中 subitem 图像的绘制,以便它们不会如图所示在左侧被截断? 最佳答案 嗯,Pieter van Wyk,我做了一个简单的示例,展示了如何自行绘制 TListV
使用标准 TListView 组件 (ViewStyle = vsReport),我附加了一个 TImageList 并成功将图像添加到第一列 (Item.ImageIndex := 0) )以及后续
带有 FireMonkey 的 Delphi 10.4.1。 我在 TListView 上有 50 个项目,ID 从 1 到 50。这里没有发布代码,因为我什至不知道从哪里开始。 如果我搜索 ID=3
我需要更改我的 listView 的所有标题的背景颜色以突出显示它们。我在 Object Inspector 上一无所获,在 Style Designer 上也一无所获,你们能给我一些指导吗? 最佳答
我有一个 ViewStyle 设置为 vsReport 的 TListView。如何更改网格的颜色和网格线的宽度。 D2009 中的网格线有点太粗了,我想要与 D5 中的宽度相同。 谢谢 最佳答案 没
我正在使用 TListView我已经成功地填充了每个项目的标题和第一个子项目。请参见下面的示例。 user pass working status valid data1 pass -
我有一个包含 4 列的 TListview(当然都是字符串),但是,我在其中存储数据: 标题:任意字符串 SubItems[0]:整数,例如'5016' SubItems[1]:日期,例如'03/22
我是一名优秀的程序员,十分优秀!