delphi StringGrid的问题
StringGrid的某一列格子有时要输入很多字符会出现比这个格子长度还要长的情况问怎么样才能在这个格子上加一个类似于ScrollBar的滚动条(只有两头就可以)使得当文...
StringGrid的某一列格子有时要输入很多字符 会出现比这个格子长度还要长的情况
问 怎么样才能在这个格子上加一个 类似于ScrollBar的滚动条(只有两头就可以)使得当文字部分超出 格子宽度时 可以用这个东西拖动文字?
谢谢!
可不可以在选定的格子两头只出现ScrollBar的两个按钮来拖动文字呢? 展开
问 怎么样才能在这个格子上加一个 类似于ScrollBar的滚动条(只有两头就可以)使得当文字部分超出 格子宽度时 可以用这个东西拖动文字?
谢谢!
可不可以在选定的格子两头只出现ScrollBar的两个按钮来拖动文字呢? 展开
3个回答
展开全部
我写了一个,你把下面的内容各自保存成dfm,和pas,写的比较粗糙,你就将就看看,美工自己考虑吧。
以下是dfm
object Form1: TForm1
Left = 192
Top = 114
Width = 696
Height = 480
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
OnClose = FormClose
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 13
object StringGrid1: TStringGrid
Left = 80
Top = 112
Width = 457
Height = 161
ColCount = 3
DefaultRowHeight = 50
FixedCols = 0
RowCount = 3
FixedRows = 0
TabOrder = 0
OnDrawCell = StringGrid1DrawCell
ColWidths = (
96
115
113)
end
end
以下是Pas
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, StdCtrls;
type
TForm1 = class(TForm)
StringGrid1: TStringGrid;
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
private
{ Private declarations }
FScrollText: TStrings;
procedure CreateScrollBoxText(ACol, ARow:Integer);
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
FScrollText := TStringList.Create;
StringGrid1.Cells[0,0] := '12352345302475932759734570294502345972357923';
StringGrid1.Cells[0,1] := 'sdgfsfdgdafasfdasffasfas';
StringGrid1.Cells[0,2] := 'sdgfsfdgdafasfdasffasfas';
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
FScrollText.Free;
end;
function GetCellID(ACol, ARow: integer): string;
begin
Result := 'CellBox_' + IntToStr(ACol) + '_' + IntToStr(ARow);
end;
procedure TForm1.CreateScrollBoxText(ACol, ARow:Integer);
var
SBox: TScrollBox;
Rect: TRect;
CellID: String;
lab: TLabel;
PPP: TPoint;
Text: String;
begin
CellID := GetCellID(ACol, ARow);
Text := StringGrid1.Cells[ACol, ARow];
//判断该单元格对应的显示对象是否有被创建
if Self.FScrollText.IndexOf(CellID) = -1 then
begin
//创建ScrollBox
SBox := TScrollBox.Create(Self);
SBox.Name := CellID;
SBox.Parent := Self;
Self.FScrollText.AddObject(CellID, SBox);
//创建lab
lab := TLabel.Create(Self);
lab.Parent := SBox;
lab.Name := 'Lab_' + CellID;
lab.Caption := Text;
lab.AutoSize := False;
lab.Width := Length(Text) * 6; //这里计算Lab的长度,这个计算方式我就不找了
lab.Top := 0;
lab.Left:= 0;//位置我就不计算了
end else
begin
SBox := (Self.FScrollText.Objects[Self.FScrollText.IndexOf(CellID)] as TScrollBox);
end;
Rect := StringGrid1.CellRect(ACol, ARow);
PPP.X := Rect.Left;
PPP.Y := Rect.Top;
PPP := StringGrid1.ClientToScreen(PPP);
PPP := Self.ScreenToClient(PPP);
SBox.Top := PPP.Y;
SBox.Left := PPP.X;
SBox.Height := Rect.Bottom - Rect.Top;
SBox.Width := Rect.Right - Rect.Left;
SBox.BorderStyle := bsNone;
SBox.Color := clRed;//StringGrid1.Color;
SBox.VertScrollBar.Visible := false;
SBox.BringToFront;
end;
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
CreateScrollBoxText(ACol, ARow);
end;
end.
以下是dfm
object Form1: TForm1
Left = 192
Top = 114
Width = 696
Height = 480
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
OnClose = FormClose
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 13
object StringGrid1: TStringGrid
Left = 80
Top = 112
Width = 457
Height = 161
ColCount = 3
DefaultRowHeight = 50
FixedCols = 0
RowCount = 3
FixedRows = 0
TabOrder = 0
OnDrawCell = StringGrid1DrawCell
ColWidths = (
96
115
113)
end
end
以下是Pas
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, StdCtrls;
type
TForm1 = class(TForm)
StringGrid1: TStringGrid;
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
private
{ Private declarations }
FScrollText: TStrings;
procedure CreateScrollBoxText(ACol, ARow:Integer);
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
FScrollText := TStringList.Create;
StringGrid1.Cells[0,0] := '12352345302475932759734570294502345972357923';
StringGrid1.Cells[0,1] := 'sdgfsfdgdafasfdasffasfas';
StringGrid1.Cells[0,2] := 'sdgfsfdgdafasfdasffasfas';
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
FScrollText.Free;
end;
function GetCellID(ACol, ARow: integer): string;
begin
Result := 'CellBox_' + IntToStr(ACol) + '_' + IntToStr(ARow);
end;
procedure TForm1.CreateScrollBoxText(ACol, ARow:Integer);
var
SBox: TScrollBox;
Rect: TRect;
CellID: String;
lab: TLabel;
PPP: TPoint;
Text: String;
begin
CellID := GetCellID(ACol, ARow);
Text := StringGrid1.Cells[ACol, ARow];
//判断该单元格对应的显示对象是否有被创建
if Self.FScrollText.IndexOf(CellID) = -1 then
begin
//创建ScrollBox
SBox := TScrollBox.Create(Self);
SBox.Name := CellID;
SBox.Parent := Self;
Self.FScrollText.AddObject(CellID, SBox);
//创建lab
lab := TLabel.Create(Self);
lab.Parent := SBox;
lab.Name := 'Lab_' + CellID;
lab.Caption := Text;
lab.AutoSize := False;
lab.Width := Length(Text) * 6; //这里计算Lab的长度,这个计算方式我就不找了
lab.Top := 0;
lab.Left:= 0;//位置我就不计算了
end else
begin
SBox := (Self.FScrollText.Objects[Self.FScrollText.IndexOf(CellID)] as TScrollBox);
end;
Rect := StringGrid1.CellRect(ACol, ARow);
PPP.X := Rect.Left;
PPP.Y := Rect.Top;
PPP := StringGrid1.ClientToScreen(PPP);
PPP := Self.ScreenToClient(PPP);
SBox.Top := PPP.Y;
SBox.Left := PPP.X;
SBox.Height := Rect.Bottom - Rect.Top;
SBox.Width := Rect.Right - Rect.Left;
SBox.BorderStyle := bsNone;
SBox.Color := clRed;//StringGrid1.Color;
SBox.VertScrollBar.Visible := false;
SBox.BringToFront;
end;
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
CreateScrollBoxText(ACol, ARow);
end;
end.
展开全部
在表格中增加一个memo控件,用户不选中stringgrid时间,将其设为不可见;
当用户选中某一格时,则将该memo控件调整尺寸贴到该格单元格上,
并将该单元格内容复制到memo控件中,再置其为可见.
当用户选中某一格时,则将该memo控件调整尺寸贴到该格单元格上,
并将该单元格内容复制到memo控件中,再置其为可见.
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
如果加个滚动条的话比较烦,你可以把全部信息写进一个提示里面,当鼠标放上去的时候,会自动出现全部的提示,这样就简单多了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询