如何用图像覆盖文本框? [英] How to overlay a textbox with an image?
本文介绍了如何用图像覆盖文本框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好!
我被困在WPF中.
我有一个文本框(在网格内),我想在该文本框的左上角显示一个图像,该图像覆盖该文本框的各个部分,如下所示:
点击此处
这就是它在HTML中的外观(使用position:absolute).
您是否看到红色图像如何用其四分之一的尺寸覆盖文本框(名称")?!
Hi everyone!
I''m stuck here in WPF.
I have a textbox (inside a grid) and I want to show an image right on the upper left corner of the textbox overlaying parts of the textbox, like so:
klick here
This is how it looks in HTML (using position:absolute).
Do you see how the red image covers the textbox (of "Name") with a quarter of its size?!
How can I achieve this in WPF?
推荐答案
我不建议这样做,因为这会损害文本的可读性,分散用户的注意力并引起用户的不适. 一种简单的方法是: http://stackoverflow .com/questions/21765677/how-to-overlay-an-image-over-an-image-in-wpf [ ^ ].
代替视频,使用图像.诀窍是使用相同的网格以及相同的行和列.您也可以使用Canvas
.另外,您可以使任何UI元素都是半透明的: ^ ].
—SA
I would not advise doing such things, because it would compromise text readability, distract and irritate the users.
One trivial way would be this: http://stackoverflow.com/questions/21765677/how-to-overlay-an-image-over-an-image-in-wpf[^].
Instead of video, use image. The trick is to use the same grid and the same row and column. You can also useCanvas
. Also, you can make any of the UI elements semi-transparent: https://msdn.microsoft.com/en-us/library/system.windows.uielement.opacity%28v=vs.110%29.aspx[^].
—SA
这就是我最终所做的(它就像一个符咒一样):
我正在使用自定义的Adorner( [
Here is what I finally did (and it works like a charm):
I''m using a custom Adorner([MSDN]).
All I had to do is replace the "drawEllipse" (and the other brush-stuff) with "drawImage" and adjust the location (using the AdornedElement)
这篇关于如何用图像覆盖文本框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文