为什么我的列表视图保持LargeIcon查看图纸? [英] Why does my listview keep drawing in LargeIcon View?

查看:221
本文介绍了为什么我的列表视图保持LargeIcon查看图纸?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个列表视图继承该标准已在平铺模式。当使用该控制,DRAWITEM给出e.bounds这些显然的largeIcon视图边界??调试时要检查它实际上是设置的观点,它说,它在瓷砖观点?然而e.DrawText吸引LargeIcon观点??

.........编辑:.........

这似乎只发生在控件放置在另一个用户控件?

.........编辑2:.........

它变得陌生......当我添加按钮旁边的列表更改视图在运行时,平铺是一样的LargeIcon和目录的看法是一样的SmallIcons ??? 我也完全删除的OwnerDraw ...

..........编辑3:.........

MSDN文档: 平铺视图

  

每个项目显示为一个全尺寸的图标   与物品标签和子项目   信息到它的权利。该   显示子项信息   应用程序指定的。本   观点仅适用于Windows XP   和Windows Server 2003家族。   在较早版本的操作系统,该值被忽略,在ListView   在LargeIcon控制显示器   视图。

好吧,我在XP?!?

......编辑4 .....................

陌生感神圣的母亲...... 我们现在是在一点上,我们已经完全剥离下来EVERYTING ......我们有一个标准的ListView窗体上,手动充满了3个值。没有的OwnerDraw。它被设置为平铺。 当我们开始这个表格,列表绘制为LARGEICON。

现在,我们开始另一张空白的解决方案,这完全一样的形式复制到新的项目,开始调试和低见。它是画在平铺视图????

...帮助...

 公共类InheritedListView:ListView控件
{
    //隐藏会员... mwuahahahahaha //是啊,我还在笑,然后
    [BrowsableAttribute(假)]
    大众新景观景观
    {
        {返回base.View; }
    }

    公共InheritedListView()
    {
        base.View = View.Tile;

        this.OwnerDraw = TRUE;
        base.DrawItem + =新DrawListViewItemEventHandler(DualLineGrid_DrawItem);
    }

    无效DualLineGrid_DrawItem(对象发件人,DrawListViewItemEventArgs E)
    {
        视图V = this.View;

        // **在调试时,v是瓷砖,但e.DrawText()画在LargeIcon模式,
        // e.Bounds也反映LargeIcon模式???? **
     }
 

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

这code行为有所不同,在不同的解决方案:

 私人无效的Ini​​tializeComponent()
    {
        System.Windows.Forms.ListViewItem listViewItem1 =新System.Windows.Forms.ListViewItem(fhsdhdsfhsdfhs);
        System.Windows.Forms.ListViewItem listViewItem2 =新System.Windows.Forms.ListViewItem(fdshdsfhdsfhsd);
        System.Windows.Forms.ListViewItem listViewItem3 =新System.Windows.Forms.ListViewItem(hdshsdfhsdfhsdfsdfsdf);
        this.listView1 =新System.Windows.Forms.ListView();
        this.SuspendLayout();
        //
        //是ListView1
        //
        this.listView1.Items.AddRange(新System.Windows.Forms.ListViewItem [] {
        listViewItem1,
        listViewItem2,
        listViewItem3});
        this.listView1.Location =新System.Drawing.Point(36,12);
        this.listView1.Name =ListView1的;
        this.listView1.Size =新System.Drawing.Size(487,242);
        this.listView1.TabIndex = 2;
        this.listView1.TileSize =新System.Drawing.Size(480,50);
        this.listView1.UseCompatibleStateImageBehavior = FALSE;
        this.listView1.View = System.Windows.Forms.Vi​​ew.Tile;
        //
        // 测控
        //
        this.AutoScaleDimensions =新System.Drawing.SizeF(6F,13F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.ClientSize =新System.Drawing.Size(595,712);
        this.Controls.Add(this.listView1);
        this.Name =系统testControl;
        this.Text =系统testControl;
        this.ResumeLayout(假);

    }

    #endregion
 

解决方案

OK,我们发现它。咒语是:

  Application.EnableVisualStyles();
 

我们跳过这行code来测试我们的表单。 如果您在创建表单与你的列表视图之前不调用此方法,平铺视图被绘制成LARGEICON。

似乎完全合乎逻辑的... :-(

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

问:什么是Application.EnableVisualStyles实际上做?

Windows XP中附带两个版本的公共控件库(COMCTL32.DLL) - 版本5.8和6.0。 V5.8中的经典的风格,你在Windows NT / 2000和Windows 9x中呈现的控制。 V6.0使得使用XP视觉样式的外观和感觉的控制。由于大多数Windows窗体控件是基于COMCTL32,它们是如何呈现取决于哪个版本COMCTL32是用来做渲染。缺省情况下,V5.8用于呈现该应用的客户区并v6.0中用于呈现的非客户区。这就是为什么你看到的标题栏和窗口边框自动呈现为主题的,而控制(如按钮,文本框,ListView控件,组合框等)具有经典的外观默认情况下。

在框架1.0的方式来获得视觉样式在Windows窗体应用程序是发布一个清单文件与应用程序,具有在它的信息,以指示COMCTL32那v6.0中应该用于渲染。虽然这工作得很好,很多开发商觉得麻烦作家,维护和部署清单文件。他们认为,能够以编程方式做到这一点的需要。现在,该平台SDK确实提供API来做到这一点。基本上,你需要创建并激活激活背景下,有pretty的多清单文件中它在同一个DLL重定向信息。该激活上下文API可用于执行此操作的适合你的应用程序的方式。

如果你看一下这些API,你可能会发现,他们都不是很容易使用。而高级开发人员可能喜欢鼓捣周围的激活上下文,它可能不是一个开发谁想要一些快速和肮脏的code获得视觉样式就行了。因此,Windows窗体小组决定来包装这些API和揭露,开发人员可以调用,将这些复杂性隔离它们的简单方法。因此,从本质上讲,当你调用Application.EnableVisualStyles,我们在各地设立的应用程序的消息循环激活的背景下,这样COMCTL32函数调用可以适当重定向到COMCTL32 V6.0。这样一来,你就不需要包括与您的应用程序清单。

I have a inherited Listview which standard has to be in Tile Mode. When using this control, the DrawItem gives e.bounds which are clearly bounds of largeIcon view ?? When debugging to check the view it is actually set to, it says it's in Tile view ?? Yet e.DrawText draws LargeIcon view ??

......... Edit: .................

This seems only to happen when the control is placed upon another usercontrol?

......... Edit 2: .................

It gets stranger ... When i add buttons next to the list to change the view at runtime, "Tile" is the same as "LargeIcon", and "List" view is the same as "SmallIcons" ??? I've also completely removed the ownerdraw ...

.......... Edit 3: .................

MSDN Documentation: Tile view

Each item appears as a full-sized icon with the item label and subitem information to the right of it. The subitem information that appears is specified by the application. This view is available only on Windows XP and the Windows Server 2003 family. On earlier operating systems, this value is ignored and the ListView control displays in the LargeIcon view.

Well I am on XP ?!?

...... Edit 4 .....................

Holy mother of strangeness ... We are now at the point we've completely stripped down EVERYTING ... We have a standard listview on a form, manually filled with 3 values. No Ownerdraw. It is set to Tile. When we start this form, the list is drawn as LARGEICON.

Now, we start another blank solution, copy this exact same form to the new project, start debug and low and behold .. it is drawn in TILE view ????

... help ...

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 ???? **
     }

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

This code behaves differently at different solutions:

    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

解决方案

OK, we found it. The magic spell is:

Application.EnableVisualStyles();

We skipped this line of code to test our form. If you don't call this method before you create your form with your listview, TILE view gets drawn as LARGEICON.

Seems totally logical ... :-(

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

Q What does Application.EnableVisualStyles actually do?

Windows XP ships with two versions of the Common Controls Library (comctl32.dll) - versions 5.8 and 6.0. v5.8 renders controls in the "Classic" style that you get on Windows NT/2000 and Windows 9x. v6.0 renders controls using the XP Visual Styles look and feel. Since most Windows Forms controls are based on comctl32, how they are rendered depends on which version of comctl32 is used to do the rendering. By default, v5.8 is used to render the client area of the app and v6.0 is used to render the non-client area. That is why you see the title bar and window borders automatically render "themed", while the controls (like Button, TextBox, ListView, ComboBox and so on) have the classic look by default.

In v1.0 of the Framework, the way to get visual styles in a Windows Forms app was to ship a manifest file with the app, that has information in it to indicate that v6.0 of comctl32 should be used for rendering. While this works fine, many developers felt it cumbersome to author, maintain and deploy manifest files. They felt the need to be able to do this programmatically. Now, the Platform SDK does provide API to do this. Basically, you need to create and activate an Activation Context that has pretty much the same DLL redirection information in it as the manifest file. The Activation Context API can be used to do this in a way suitable to your application.

If you take a look at these API, you will probably notice that they aren't very easy to use. While the advanced developers may like to tinker around with activation contexts, it is probably not something a developer who wants some "quick and dirty" code to get visual styles will do. So the Windows Forms team decided to wrap these API and expose a simple method that developers could call, that would isolate them from these complexities. So, essentially, when you call Application.EnableVisualStyles, we set up an activation context around the application's message loop, so that comctl32 function calls can be properly redirected to comctl32 v6.0. That way, you don't need to include a manifest with your app.

这篇关于为什么我的列表视图保持LargeIcon查看图纸?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆