2010-05-20 22 views
1

我有一個繼承Listview哪個標準必須在瓷磚模式。使用此控件時,DrawItem提供的e.bounds顯然是largeIcon視圖的界限?當調試來檢查它實際設置的視圖時,它說它在平鋪視圖中?然而eDrawText吸引LargeIcon視圖?爲什麼我的listview在LargeIcon View中保持繪圖?

.........編輯:.................

這似乎當控制被放置在另一個用戶控件只出現呢?

.........編輯2:.................

它變得陌生......當我添加按鈕旁邊list在運行時更改視圖,「Tile」與「LargeIcon」相同,「List」視圖與「SmallIcons」相同?我也完全清除的OwnerDraw ...

..........編輯3:.................

MSDN文檔:

每個項目顯示爲一個全尺寸的圖標 與商品標籤和子項目 信息,它的右邊 平鋪視圖。出現的 子項信息是由應用程序指定的 。此 視圖僅在Windows XP 和Windows Server 2003系列上可用。 在較早版本的操作系統,該值被忽略並在LargeIcon 視圖ListView的 控制顯示器。

那麼我在XP?!?

......編輯4 .....................

陌生感的神聖母親...... 我們現在是在我們已經完全剝離了EVERYTING ...我們在表單上有一個標準的listview,手動填充了3個值。沒有所有者撤回。它被設置爲平鋪。 當我們開始這個表單時,列表被繪製爲LARGEICON。

現在,我們開始另一個空白的解決方案,複製此完全相同的形式向新項目,啓動調試和低看哪..它被吸入TILE視圖????

...幫助...

public class InheritedListView : ListView 
{ 
    //Hiding members ... mwuahahahahaha //yeah i was still laughing then 
    [BrowsableAttribute(false)] 
    public new View View 
    { 
     get { return base.View; } 
    } 

    public InheritedListView() 
    { 
     base.View = View.Tile; 

     this.OwnerDraw = true; 
     base.DrawItem += new DrawListViewItemEventHandler(DualLineGrid_DrawItem); 
    } 

    void DualLineGrid_DrawItem(object sender, DrawListViewItemEventArgs e) 
    { 
     View v = this.View; 

     //**when debugging, v is Tile, however e.DrawText() draws in LargeIcon mode, 
     // e.Bounds also reflects LargeIcon mode ???? ** 
    } 

................................

這段代碼在不同的解決方案表現不同:

private void InitializeComponent() 
    { 
     System.Windows.Forms.ListViewItem listViewItem1 = new System.Windows.Forms.ListViewItem("fhsdhdsfhsdfhs"); 
     System.Windows.Forms.ListViewItem listViewItem2 = new System.Windows.Forms.ListViewItem("fdshdsfhdsfhsd"); 
     System.Windows.Forms.ListViewItem listViewItem3 = new System.Windows.Forms.ListViewItem("hdshsdfhsdfhsdfsdfsdf"); 
     this.listView1 = new System.Windows.Forms.ListView(); 
     this.SuspendLayout(); 
     // 
     // listView1 
     // 
     this.listView1.Items.AddRange(new System.Windows.Forms.ListViewItem[] { 
     listViewItem1, 
     listViewItem2, 
     listViewItem3}); 
     this.listView1.Location = new System.Drawing.Point(36, 12); 
     this.listView1.Name = "listView1"; 
     this.listView1.Size = new System.Drawing.Size(487, 242); 
     this.listView1.TabIndex = 2; 
     this.listView1.TileSize = new System.Drawing.Size(480, 50); 
     this.listView1.UseCompatibleStateImageBehavior = false; 
     this.listView1.View = System.Windows.Forms.View.Tile; 
     // 
     // TestControl 
     // 
     this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 
     this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 
     this.ClientSize = new System.Drawing.Size(595, 712); 
     this.Controls.Add(this.listView1); 
     this.Name = "TestControl"; 
     this.Text = "TestControl"; 
     this.ResumeLayout(false); 

    } 

    #endregion 

回答

3

OK,我們發現它。魔法是:

Application.EnableVisualStyles(); 

我們跳過了這行代碼來測試我們的表單。 如果你創建你的ListView表單前不調用此方法,平鋪視圖被繪製成LARGEICON。

似乎完全合乎邏輯的...... :-(

http://blogs.msdn.com/rprabhu/archive/2003/09/28/56540.aspx

Q是什麼Application.EnableVisualStyles實際上做?與常見的兩個版本

Windows XP中船控件庫(COMCTL32。 dll) - 版本5.8和6.0 v5.8呈現在Windows NT/2000和Windows 9x上使用的「Classic」風格的控件v6.0使用XP Visual風格的外觀呈現控件由於大多數Windows Forms控件基於comctl32,它們如何呈現取決於哪個版本comctl32被用來做渲染。默認情況下,v5.8用於渲染應用程序的客戶端區域,v6.0用於渲染非客戶端區域。這就是爲什麼你看到標題欄和窗口邊框自動呈現「主題」,而控件(如Button,TextBox,ListView,ComboBox等)默認具有經典外觀。

在框架的v1.0中,在Windows窗體應用程序中獲取視覺樣式的方式是將清單文件與應用程序一起發送,該應用程序中包含信息以指示應該使用comctl32的v6.0渲染。雖然這很好,但許多開發人員覺得編寫,維護和部署清單文件很麻煩。他們覺得有必要能夠以編程的方式做到這一點。現在,Platform SDK確實提供了API來執行此操作。基本上,您需要創建並激活一個激活上下文,它與清單文件具有幾乎相同的DLL重定向信息。 Activation Context API可用於以適合您的應用程序的方式執行此操作。

如果你看看這些API,你可能會注意到它們不是很容易使用。雖然高級開發人員可能喜歡對激活上下文進行修改,但開發人員可能不希望某些「快速而骯髒」的代碼獲得視覺樣式。因此,Windows Forms團隊決定封裝這些API,並公開開發人員可以調用的一個簡單方法,將它們與這些複雜性隔離。所以,實際上,當您調用Application.EnableVisualStyles時,我們會在應用程序的消息循環周圍設置一個激活上下文,以便可以將comctl32函數調用正確重定向到comctl32 v6.0。這樣,您就不需要在應用中包含清單。

相關問題