确定C#标签特定部分的左上角(位置)

发布于 2025-02-14 01:07:24 字数 472 浏览 0 评论 0原文

我有一个窗口表单,可以在编程中创建的控制标签上拖动。我正在使用位置属性来确定每个标签位置。

每个标签都是用占位符'#'的预览创建的。我想知道该标签中特定字符的形式坐标是什么。

作为代码示例:

Label myLabel = new Label
            {
                Text = "Average: ##.#Unit",
                Name = "myLabelName"
            };

Controls.Add(myLabel);

...

// After label is dragged around
Point myLabelLocation = myLabel.Location;

这给了我标签的坐标。假设我想要类似的坐标,但是我希望它们成为第一个#。

看这件事的另一种方法是,我在'#'之前就“拆分”了标签。我如何获得这个位置?

I have a windows form that I can drag around programmatically created control labels. I am using the location property to determine each label position.

Each label is created as a preview with placeholder '#' where a number is to be. I want to know what the form coordinates are of a specific character in that label.

As a code example:

Label myLabel = new Label
            {
                Text = "Average: ##.#Unit",
                Name = "myLabelName"
            };

Controls.Add(myLabel);

...

// After label is dragged around
Point myLabelLocation = myLabel.Location;

This gives me the label's coordinates. Let's say I want similar coordinates, but I want them for the first #.

Another way to look at this, I "split" the label right before '#'. How do I get this location?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文