一:繼承 執行個體一:在屬性頁控件中顯示不同屬性頁
VB | VC | |
控件 | TabStrip | Tab Control |
VB實作原理: 将不同的屬性頁設計在一個Picture控件數組中,通過對數組元素的 Visible屬性值的設定來在點選一個屬性頁标題時顯示一個屬性頁。控件的 初始化和屬性頁的處理多很麻煩。 VB實作代碼:
Function creattabs() ‘建立TabStrip控件
Dim intX As Integer
TEST.TabStrp.Tabs.Clear
Set reftbs = TEST.TabStrp.Tabs.Add(, , " Results " )
reftbs.ToolTipText = " The results of the test "
Set reftbs = TEST.TabStrp.Tabs.Add(, , " Passed " )
reftbs.ToolTipText = " The report of passed products "
Set reftbs = TEST.TabStrp.Tabs.Add(, , " Failed " )
reftbs.ToolTipText = " The report of failed products "
For intX = 0 To 3
With TEST.Picture1(intX)
.BorderStyle = 0
.Left = TEST.TabStrp.ClientLeft
.Top = TEST.TabStrp.ClientTop
.Width = TEST.TabStrp.ClientWidth
.Height = TEST.TabStrp.ClientHeight
.Visible = False
End With
Next intX
End Function
Function selecttabs()
If tab1 Then
TEST.Picture1( 0 ).Visible = True
TEST.Picture1( 1 ).Visible = False
TEST.Picture1( 2 ).Visible = False
TEST.Picture1( 3 ).Visible = False
End If
If tab2 Then
TEST.Picture1( 0 ).Visible = False
TEST.Picture1( 1 ).Visible = True
TEST.Picture1( 2 ).Visible = False
TEST.Picture1( 3 ).Visible = False
End If
If tab3 Then
TEST.Picture1( 0 ).Visible = False
TEST.Picture1( 1 ).Visible = False
TEST.Picture1( 2 ).Visible = True
TEST.Picture1( 3 ).Visible = False
End If
If tab4 Then
TEST.Picture1( 0 ).Visible = False
TEST.Picture1( 1 ).Visible = False
TEST.Picture1( 2 ).Visible = False
TEST.Picture1( 3 ).Visible = True
End If
End Function
VC實作原理: 利用面向對象程式設計的繼承原理,将Page頁從已經設計好的Dialog繼 承過來,控件初始化時隻需将屬性頁的指針指向對應的Dialog即可,屬性 頁的處理有Dialog自己來完成,向普通的Dialog處理一樣。 VC實作代碼: 在頭檔案(.h)中聲明:
CPage1 m_Page1; // 出勤頁
CPage2 m_Page2; // 加班頁
CPage3 m_Page3; // 請假頁
CPage4 m_Page4; // 出差頁
CPropertySheet m_Sheet;
在初始化中加入如下代碼:
m_Sheet.AddPage( & m_Page1); // 加第1頁
m_Sheet.AddPage( & m_Page2); // 加第2頁
m_Sheet.AddPage( & m_Page3); // 加第3頁
m_Sheet.AddPage( & m_Page4); // 加第4頁
m_Sheet.Create( this , WS_CHILD | WS_VISIBLE, 0 ); // 建立視窗
m_Sheet.ModifyStyleEx ( 0 , WS_EX_CONTROLPARENT);
m_Sheet.ModifyStyle( 0 , WS_TABSTOP ); // 修改風格
// 設定視窗位置
m_Sheet.SetWindowPos( NULL, 0 , 100 , 0 , 0 ,
SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE );