m8815010
版主
   
 發表:99 回覆:372 積分:289 註冊:2003-11-13
發送簡訊給我
|
引言:
也就是把文字壓扁塞進固定長度的表格中,要如何做請教各位先進.
< face="Verdana, Arial, Helvetica"> kswedu你好 : 我之前在究研這一篇時: < href="http://delphi.ktop.com.tw/topic.php?TOPIC_ID=45583">http://delphi.ktop.com.tw/topic.php?TOPIC_ID=45583 有些小小心得,提出來分享看看< >! 就是比如說一個>>,還不止這一個,但我忘了< >!功能都差不多,但都有使用上的限制! 也就是說不是>注意
1. 本範例是在一個TEdit上動態顯示一個給定字串不同字寬的樣式,因為不知kswedu兄要放入何種表格!
2. 按▲鍵放寬字串,按▼鍵縮減字寬
3. 不同元件可能會需要額外不同的對應
4. 字寬縮小到一定地步時會有反效果,這不是程式的bug,而是SetTextCharacterExtra這隻function原本的表式方式!
In Unit.h
~~~
class TForm1 : public TForm
{
__published: // IDE-managed Components
TEdit *Edit1;
TCSpinButton *CSpinButton1;
void __fastcall CSpinButton1DownClick(TObject *Sender);
void __fastcall CSpinButton1UpClick(TObject *Sender);
private: // User declarations
void __fastcall EditWndProc(TMessage&);
TWndMethod OldEditWndProc;
public: // User declarations
__fastcall TForm1(TComponent* Owner);
}; ~~~
In Unit.cpp
~~~
TForm1 *Form1; int GapCnt=0; //---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
OldEditWndProc=Edit1->WindowProc;
Edit1->WindowProc=EditWndProc;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::EditWndProc(TMessage& Message)
{
OldEditWndProc(Message); if (Message.Msg==WM_PAINT || Message.Msg==WM_MOUSEMOVE || Message.Msg==WM_LBUTTONDOWN || Message.Msg==WM_LBUTTONDBLCLK || Message.Msg==WM_KILLFOCUS || Message.Msg==WM_SETFOCUS) {
HDC dc=GetDC(Edit1->Handle);
SetTextCharacterExtra(dc,GapCnt);
SelectObject(dc,Edit1->Font->Handle);
TextOut(dc,1,1,"ILOVEYOU",8);
ReleaseDC(Edit1->Handle,dc);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::CSpinButton1DownClick(TObject *Sender)
{
GapCnt--;
Edit1->Invalidate();
SendMessage(Edit1->Handle,WM_PAINT,0,0);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::CSpinButton1UpClick(TObject *Sender)
{
GapCnt ;
Edit1->Invalidate();
SendMessage(Edit1->Handle,WM_PAINT,0,0);
} 圖例: 發表人 - m8815010 於 2004/04/16 16:56:04 發表人 - m8815010 於 2004/04/16 16:57:56
|