【问题标题】:Replicate Windows 7 "add a device" dialog in C#在 C# 中复制 Windows 7“添加设备”对话框
【发布时间】:2011-11-28 20:58:42
【问题描述】:

我正在寻找复制“添加设备”对话框(由于我的声誉,我无法附加图片,但只需进入“设备和打印机”并点击 在 C# 中从 Windows 7 添加设备”),更具体地说是“ListView”控件的类型。.NET Framework 中是否有任何控件可以让我列出左侧有图标和文本的项目对吗?

最坏的情况,我将重写 ListView 的绘制方法。

【问题讨论】:

  • 您使用的是 WinForms 还是 WPF?
  • 抱歉,忘记指定标准 Windows 窗体

标签: .net winforms windows-7 dialog


【解决方案1】:

嗯,找到了答案。这比我想象的要容易得多。我没有意识到“平铺”模式是如何绘制项目的。所以,我只是做了一个小的 DrawItem 方法。

这对我有用,但需要对任何其他项目进行修改。

    private void Devices_DrawItem(object sender, DrawListViewItemEventArgs e)
    {

        e.DrawBackground();

        // Get the device image, changes depending of it's status.
        Image DeviceIcon = Devices.LargeImageList.Images[e.Item.ImageIndex];

        // Draw the device image.
        e.Graphics.DrawImage(DeviceIcon, e.Bounds.Left, e.Bounds.Top);

        // Draw the device name.
        e.Graphics.DrawString(e.Item.Text, new Font(Devices.Font, Devices.Font.Style | FontStyle.Bold), SystemBrushes.ControlText, e.Bounds.Left + DeviceIcon.Width + 5, e.Bounds.Top + 3);

        // Draw the device type.
        e.Graphics.DrawString(e.Item.SubItems[1].Text, Devices.Font, SystemBrushes.ControlText, e.Bounds.Left + DeviceIcon.Width + 5, e.Bounds.Top + 18);

        // Draw the device port.
        e.Graphics.DrawString(e.Item.SubItems[2].Text, Devices.Font, SystemBrushes.ControlText, e.Bounds.Left + DeviceIcon.Width + 5, e.Bounds.Top + 33);

        e.DrawFocusRectangle();

    }

【讨论】:

    猜你喜欢
    • 2014-06-10
    • 1970-01-01
    • 1970-01-01
    • 2012-02-12
    • 1970-01-01
    • 1970-01-01
    • 2018-09-18
    • 1970-01-01
    • 2013-05-27
    相关资源
    最近更新 更多