因为combobox中有的item太长,无法完全显示,采用hint的办法显示
在onselect中实现了
procedure TfrmPingGuManage.cboAnswer1Select(Sender: TObject);
begin
cboanswer1.Hint:=cboanswer1.Text;
end;
现在想做成不用选择,随着鼠标移动在不同的item上,hint就随着响应出来。
在onselect中实现了
procedure TfrmPingGuManage.cboAnswer1Select(Sender: TObject);
begin
cboanswer1.Hint:=cboanswer1.Text;
end;
现在想做成不用选择,随着鼠标移动在不同的item上,hint就随着响应出来。
解决方案 »
- delphi7怎么实现打印功能?
- 做过WIA接口扫描或VC。NET很熟的朋友请进
- 用cooltrayicon控件后出现的小问题?????
- 关于dbgrid的问题,这个问题应该对所有的人都有帮助吧..
- Web Service 里面的如何操纵cookie?
- 关于TFileStream的几个问题????
- 请问如何完全删除richedit上的一行!!
- 如何用将 Form 提交的图片存入数据库?(菜鸟散分啦)
- 急!急!使用存储过程,系统提示ERROR CREATING CURSOR HANDLE!!救我一命!
- 很菜的问题:oncreatform()事件中加了一句form2。show(),本想在创建窗体之前显示form2,结果运行时提示出错,难道不能加?
- 小弟在线急求,用DELPHI下文件夹覆盖拷贝的问题/100分
- fastreopt
CurHint : THintWindow;procedure TForm1.FormCreate(Sender: TObject);
begin
With Combobox1 do
begin
ShowHint := True;
Style := csOwnerDrawFixed;
Items.Add('测试行一测试行一测试行一测试行一');
Items.Add('测试行二测试行二测试行二测试行二');
Items.Add('测试行三测试行三测试行三测试行三');
ItemIndex := 0;
end;
CurHint := THintWindow.Create(self);
end;procedure TForm1.ComboBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
var
HintRect : TRect;
begin
with TCombobox(Control) do
begin
if odSelected in State then
begin
Canvas.Brush.Color := clHighlight;
Canvas.Font.Color := clHighlightText;
//self.Caption := Items[index]; //窗体Caption显示它,状态栏也可以吧!Label也可以吧
CurHint.ReleaseHandle;
CurHint.Free;
CurHint := THintWindow.Create(Self);
HintRect.Left := Mouse.CursorPos.X;
HintRect.Top := Mouse.CursorPos.Y;
HintRect.Right := HintRect.Left + 300;//长度自己定
HintRect.Bottom := HintRect.Top + 20;
if DroppedDown then CurHint.ActivateHint(HintRect, Items[index]);
end
else
begin
Canvas.Brush.Color := clWindow;
Canvas.Font.Color := clWindowText;
end;
Canvas.TextRect(rect,rect.left+1,rect.top+1,Items[index]);
end;
end;
另外问一下我用下面的代码
procedure TfrmPingGuManage.cboAnswer1DropDown(Sender: TObject);
var I:Integer;
vMaxWidth:Integer;
begin
vMaxWidth:=TComboBox(Sender).Width;
for I:=0 to TComboBox(Sender).Items.Count-1 do
vMaxWidth:=Max(vMaxWidth,
TComboBox(Sender).Canvas.TextWidth(TComboBox(Sender).Items[I])+8);
TComboBox(Sender).Perform(CB_SETDROPPEDWIDTH,vMaxWidth,0);
end;
这样item不管多长都显示出来了,不过就是左边的起点不知道怎么设置,导致右边的一块虽然也
显示了,可是还是看不到。
如果能设置显示的左起点,我的目的也能达到,如果可以再麻烦给指导下。
要是这个也能给说下,就最好了
刚学用Delphi几天,听说这个界面容易做的说,再次表示感谢
ps:cboanswer1.Hint:=cboanswer1.Text;
这样显示的hint就是根据内容自动调整显示位置的说,组建里面可能作好了,我再看看的说
应该可以,一次搞好,这个东西可以留下来一直用,嘿嘿