SkinUI入门教程

SkinUI入门教程


3.18 网格控件

<p>网格控件由CSkinGridView类来代表,继承于CSkinListView,支持CSkinListView的所有属性和方法。</p> <h2>1 属性和相关方法:</h2> <h4>1.1 设置单元格大小</h4> <ul> <li>通过XML属性控制如下: <pre><code class="language-xml">CellSize=&amp;quot;100,100&amp;quot;</code></pre></li> <li>通过C++程序代码调用方法控制如下: <pre><code class="language-c">void SetCellSize(const CSize&amp;amp; size);</code></pre></li> </ul> <h4>1.2 设置单元格间距</h4> <ul> <li>通过XML属性控制如下: <pre><code class="language-xml">MarginSize=&amp;quot;10,10&amp;quot;</code></pre></li> <li>通过C++程序代码调用方法控制如下: <pre><code class="language-c">void SetMarginSize(const CSize&amp;amp; size);</code></pre></li> </ul> <h4>1.3 设置列数</h4> <ul> <li>通过XML属性控制如下: <pre><code class="language-xml">ColumnCount=&amp;quot;5&amp;quot;</code></pre></li> <li>通过C++程序代码调用方法控制如下: <pre><code class="language-c">void SetColumnCount(LONG nColumnCount);</code></pre></li> </ul> <h2>请看下面的示例</h2> <h4>效果图</h4> <p><img src="http://www.skinui.cn/doc/img/3/18/1.png" alt="网格控件" /></p> <h4>布局文件</h4> <pre><code class="language-xml">&amp;lt;SkinDialog DefaultWidth=&amp;quot;445&amp;quot; DefaultHeight=&amp;quot;300&amp;quot; SysButton=&amp;quot;CLOSE&amp;quot; Icon=&amp;quot;128&amp;quot; Caption=&amp;quot;IDS_CONTROL_SHOW18&amp;quot; Animation=&amp;quot;SizeChange&amp;quot;&amp;gt; &amp;lt;SkinRelativeLayout LayoutWidth=&amp;quot;154&amp;quot; AlignParentLeft=&amp;quot;15&amp;quot; AlignParentTop=&amp;quot;45&amp;quot; AlignParentBottom=&amp;quot;60&amp;quot; BkgColor=&amp;quot;ID_COLOR_WHITE&amp;quot; Border=&amp;quot;ID_COLOR_LINE&amp;quot;&amp;gt; &amp;lt;SkinGridView Id=&amp;quot;101&amp;quot; AlignParentLeft=&amp;quot;2&amp;quot; AlignParentRight=&amp;quot;2&amp;quot; AlignParentTop=&amp;quot;2&amp;quot; AlignParentBottom=&amp;quot;2&amp;quot; CellSize=&amp;quot;70,30&amp;quot; ColumnCount=&amp;quot;2&amp;quot; VScrollBar=&amp;quot;VScrollBar.xml&amp;quot;&amp;gt; &amp;lt;SkinListItem LayoutWidth=&amp;quot;FillParent&amp;quot; LayoutHeight=&amp;quot;30&amp;quot; Image=&amp;quot;ListItem.png&amp;quot; Layout=&amp;quot;ListItem.xml&amp;quot; ChildText1=&amp;quot;Item1&amp;quot;/&amp;gt; &amp;lt;SkinListItem LayoutWidth=&amp;quot;FillParent&amp;quot; LayoutHeight=&amp;quot;30&amp;quot; Image=&amp;quot;ListItem.png&amp;quot; Layout=&amp;quot;ListItem.xml&amp;quot; ChildText1=&amp;quot;Item2&amp;quot;/&amp;gt; &amp;lt;SkinListItem LayoutWidth=&amp;quot;FillParent&amp;quot; LayoutHeight=&amp;quot;30&amp;quot; Image=&amp;quot;ListItem.png&amp;quot; Layout=&amp;quot;ListItem.xml&amp;quot; ChildText1=&amp;quot;Item3&amp;quot;/&amp;gt; &amp;lt;SkinListItem LayoutWidth=&amp;quot;FillParent&amp;quot; LayoutHeight=&amp;quot;30&amp;quot; Image=&amp;quot;ListItem.png&amp;quot; Layout=&amp;quot;ListItem.xml&amp;quot; ChildText1=&amp;quot;Item4&amp;quot;/&amp;gt; &amp;lt;SkinListItem LayoutWidth=&amp;quot;FillParent&amp;quot; LayoutHeight=&amp;quot;30&amp;quot; Image=&amp;quot;ListItem.png&amp;quot; Layout=&amp;quot;ListItem.xml&amp;quot; ChildText1=&amp;quot;Item5&amp;quot;/&amp;gt; &amp;lt;/SkinGridView&amp;gt; &amp;lt;/SkinRelativeLayout&amp;gt; &amp;lt;SkinRelativeLayout LayoutWidth=&amp;quot;254&amp;quot; AlignParentRight=&amp;quot;15&amp;quot; AlignParentTop=&amp;quot;45&amp;quot; AlignParentBottom=&amp;quot;60&amp;quot; BkgColor=&amp;quot;ID_COLOR_WHITE&amp;quot; Border=&amp;quot;ID_COLOR_LINE&amp;quot;&amp;gt; &amp;lt;SkinGridView Id=&amp;quot;102&amp;quot; AlignParentLeft=&amp;quot;2&amp;quot; AlignParentRight=&amp;quot;2&amp;quot; AlignParentTop=&amp;quot;2&amp;quot; AlignParentBottom=&amp;quot;2&amp;quot; CellSize=&amp;quot;60,60&amp;quot; ColumnCount=&amp;quot;4&amp;quot; VScrollBar=&amp;quot;VScrollBar.xml&amp;quot;&amp;gt; &amp;lt;SkinListItem LayoutWidth=&amp;quot;FillParent&amp;quot; LayoutHeight=&amp;quot;30&amp;quot; Image=&amp;quot;ListItem.png&amp;quot; Layout=&amp;quot;UserListItem2.xml&amp;quot; ChildImage1=&amp;quot;Male.png&amp;quot; ChildText2=&amp;quot;姓名1&amp;quot;/&amp;gt; &amp;lt;SkinListItem LayoutWidth=&amp;quot;FillParent&amp;quot; LayoutHeight=&amp;quot;30&amp;quot; Image=&amp;quot;ListItem.png&amp;quot; Layout=&amp;quot;UserListItem2.xml&amp;quot; ChildImage1=&amp;quot;Female.png&amp;quot; ChildText2=&amp;quot;姓名2&amp;quot;/&amp;gt; &amp;lt;SkinListItem LayoutWidth=&amp;quot;FillParent&amp;quot; LayoutHeight=&amp;quot;30&amp;quot; Image=&amp;quot;ListItem.png&amp;quot; Layout=&amp;quot;UserListItem2.xml&amp;quot; ChildImage1=&amp;quot;Male.png&amp;quot; ChildText2=&amp;quot;姓名3&amp;quot;/&amp;gt; &amp;lt;SkinListItem LayoutWidth=&amp;quot;FillParent&amp;quot; LayoutHeight=&amp;quot;30&amp;quot; Image=&amp;quot;ListItem.png&amp;quot; Layout=&amp;quot;UserListItem2.xml&amp;quot; ChildImage1=&amp;quot;Female.png&amp;quot; ChildText2=&amp;quot;姓名4&amp;quot;/&amp;gt; &amp;lt;SkinListItem LayoutWidth=&amp;quot;FillParent&amp;quot; LayoutHeight=&amp;quot;30&amp;quot; Image=&amp;quot;ListItem.png&amp;quot; Layout=&amp;quot;UserListItem2.xml&amp;quot; ChildImage1=&amp;quot;Male.png&amp;quot; ChildText2=&amp;quot;姓名5&amp;quot;/&amp;gt; &amp;lt;/SkinGridView&amp;gt; &amp;lt;/SkinRelativeLayout&amp;gt; &amp;lt;SkinButton Id=&amp;quot;201&amp;quot; LayoutWidth=&amp;quot;150&amp;quot; LayoutHeight=&amp;quot;30&amp;quot; ChildText1=&amp;quot;添加节点&amp;quot; Image=&amp;quot;Button.png&amp;quot; Layout=&amp;quot;Button.xml&amp;quot; AlignParentLeft=&amp;quot;15&amp;quot; AlignParentBottom=&amp;quot;15&amp;quot; PressDownOffset=&amp;quot;1&amp;quot;/&amp;gt; &amp;lt;SkinButton Id=&amp;quot;202&amp;quot; LayoutWidth=&amp;quot;250&amp;quot; LayoutHeight=&amp;quot;30&amp;quot; ChildText1=&amp;quot;添加节点&amp;quot; Image=&amp;quot;Button.png&amp;quot; Layout=&amp;quot;Button.xml&amp;quot; AlignParentRight=&amp;quot;15&amp;quot; AlignParentBottom=&amp;quot;15&amp;quot; PressDownOffset=&amp;quot;1&amp;quot;/&amp;gt; &amp;lt;/SkinDialog&amp;gt;</code></pre> <h4>h文件</h4> <pre><code class="language-cpp">#pragma once class CGridViewDialog : public CSkinDialog { public: enum { IDC_GRIDVIEW1 = 101, IDC_GRIDVIEW2 = 102, IDC_BUTTON1 = 201, IDC_BUTTON2 = 202, }; public: CGridViewDialog(const tstring&amp;amp; strXml); public: virtual void OnInitDialog(); protected: void OnBtnClickedAddItem1(UINT uNotifyCode, int nID, CSkinView* pView); void OnBtnClickedAddItem2(UINT uNotifyCode, int nID, CSkinView* pView); SKINUI_DECLARE_MESSAGE_MAP() private: CSkinGridView* m_pGridView1; CSkinGridView* m_pGridView2; };</code></pre> <h4>cpp文件</h4> <pre><code class="language-cpp">#include &amp;quot;stdafx.h&amp;quot; #include &amp;quot;GridViewDialog.h&amp;quot; SKINUI_BEGIN_MESSAGE_MAP(CGridViewDialog, CSkinDialog) ON_SKINUI_COMMAND(IDC_BUTTON1, OnBtnClickedAddItem1) ON_SKINUI_COMMAND(IDC_BUTTON2, OnBtnClickedAddItem2) SKINUI_END_MESSAGE_MAP() CGridViewDialog::CGridViewDialog(const tstring&amp;amp; strXml) : CSkinDialog(strXml) , m_pGridView1(NULL) , m_pGridView2(NULL) { } void CGridViewDialog::OnInitDialog() { CSkinDialog::OnInitDialog(); m_pGridView1 = static_cast&amp;lt;CSkinGridView*&amp;gt;(GetChildById(IDC_GRIDVIEW1)); m_pGridView2 = static_cast&amp;lt;CSkinGridView*&amp;gt;(GetChildById(IDC_GRIDVIEW2)); } static int nIndex1 = 6; void CGridViewDialog::OnBtnClickedAddItem1(UINT uNotifyCode, int nID, CSkinView* pView) { if(m_pGridView1) { CSkinListItem* pListItem = new CSkinListItem(m_pGridView1); if(pListItem) { pListItem-&amp;gt;SetLayoutHeight(30); pListItem-&amp;gt;SetImage(_T(&amp;quot;ListItem.png&amp;quot;)); pListItem-&amp;gt;SetLayout(_T(&amp;quot;ListItem.xml&amp;quot;)); pListItem-&amp;gt;SetChildText(100001, _T(&amp;quot;Item&amp;quot;) + SkinUI::IntToString(nIndex1++)); } m_pGridView1-&amp;gt;ResetScrollInfo(); m_pGridView1-&amp;gt;ScrollBottom(); m_pGridView1-&amp;gt;RedrawView(); } } static int nIndex2 = 6; static BOOL bMale = FALSE; void CGridViewDialog::OnBtnClickedAddItem2(UINT uNotifyCode, int nID, CSkinView* pView) { if(m_pGridView2) { CSkinListItem* pListItem = new CSkinListItem(m_pGridView2); if(pListItem) { pListItem-&amp;gt;SetLayoutHeight(30); pListItem-&amp;gt;SetImage(_T(&amp;quot;ListItem.png&amp;quot;)); pListItem-&amp;gt;SetLayout(_T(&amp;quot;UserListItem2.xml&amp;quot;)); pListItem-&amp;gt;SetChildImage(100001, bMale ? _T(&amp;quot;Male.png&amp;quot;) : _T(&amp;quot;Female.png&amp;quot;)); pListItem-&amp;gt;SetChildText(100002, _T(&amp;quot;姓名&amp;quot;) + SkinUI::IntToString(nIndex2++)); bMale = !bMale; } m_pGridView2-&amp;gt;ResetScrollInfo(); m_pGridView2-&amp;gt;ScrollBottom(); m_pGridView2-&amp;gt;RedrawView(); } }</code></pre>

页面列表

ITEM_HTML