简体   繁体   English

在Windows窗体中识别控件

[英]Identifying controls in a Windows Form

Can anybody identify what type of Windows Form control(s) the Select signature to edit, Choose default signature, and Edit Signature are in the Microsoft Outlook insert signature modal? 谁能识别Microsoft Outlook插入签名模式中的“选择要编辑的签名”,“选择默认签名”和“编辑签名”是哪种类型的Windows窗体控件? I cannot figure out if it's a super-shruken panel, or if it's some other control I'm not finding? 我不能弄清楚它是不是超级破碎的面板,还是我找不到的其他控件?

在此处输入图片说明

They are not controls at all. 它们根本不是控件。 Most of what you see on that dialog is what I call "pseudo controls", that is painted bits that look and operate as controls, but which do not have system windows. 您在该对话框中看到的大多数内容都是我所说的“伪控件​​”,它是绘成的位,看起来像控件,但可以作为控件使用,但没有系统窗口。 You can see this by using a Spy tool to find the (non-existent) system windows. 您可以通过使用间谍工具查找(不存在)系统窗口来查看此信息。

You can achieve this yourself with Graphics.DrawText and ControlPaint.DrawXXX, where XXX I'm not sure of. 您可以使用Graphics.DrawText和ControlPaint.DrawXXX自己实现,其中我不确定XXX。 Maybe Border, or 3DBorder? 也许是Border,还是3DBorder?

Here's a cheap and dirty example. 这是一个便宜又肮脏的例子。 I used the WinForms Label control because it was easy. 我使用WinForms Label控件是因为它很容易。

using System;
using System.Drawing;
using System.Windows.Forms;

public class Form1 : Form
{
    [STAThread]
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new Form1());
    }

    public Form1()
    {
        ClientSize = new Size(400, 200);
        Controls.Add(new LineLabel { Text = "Edit signature", Location = new Point(10, 10), Anchor = AnchorStyles.Left | AnchorStyles.Right, Width = 380 });
    }
}

public class LineLabel : Label
{
    protected override void OnPaint(PaintEventArgs e)
    {
        base.OnPaint(e);

        SizeF textSize = e.Graphics.MeasureString(this.Text, this.Font);
        int leftWidth = (int)(textSize.Width + 2);
        Rectangle bounds = new Rectangle(leftWidth, Height / 2 - 4, Bounds.Width - leftWidth, 2);
        ControlPaint.DrawBorder(e.Graphics, bounds, Color.DarkGray, ButtonBorderStyle.Solid);
    }
}

They are GroupBoxes, albeit looking a little modified in terms of their borders. 它们是GroupBoxes,尽管在边框方面看起来有些修改。 If you would like to customize your own, you could do that for a WinForms groupbox (to some extent) but it will prove a LOT easier to go with a WPF Groupbox and read up on styling in Styling a GroupBox . 如果您想自定义自己的内容,可以在某种程度上对WinForms组框执行此操作,但是事实证明,使用WPF组框可以轻松完成很多工作,并可以在对组样式化中阅读样式

A must-read is also MSDN - How To Define a GroupBox Template . 也是必读的MSDN-如何定义GroupBox模板

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM