wpf 将窗体控件发送到窗体的前后

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15304130/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 07:58:41  来源:igfitidea点击:

Send a windows form control to front and back on a form

c#wpfvisual-studio-2010wpf-controls

提问by user613326

Is it possible in vs2010 c# To create a picture box and a textbox on a form
where on the same form are some buttons too

是否可以在 vs2010 c# 中在表单
上创建图片框和文本框,其中同一个表单上也有一些按钮

And then by code put the picture and textbox as the most frontal element and later by code to put them as the most back background visual elements so be able to switch between front and back elements ?

然后通过代码将图片和文本框作为最前面的元素,然后通过代码将它们作为最后面的背景视觉元素,以便能够在前后元素之间切换?

During design time one can do this, but i don't see a property for it that could be changed Or am i just overlooking it ?

在设计时可以做到这一点,但我没有看到可以更改的属性,或者我只是忽略了它?

回答by snowy hedgehog

That's where Z-Index comes in for you Z Axis. Read this:

这就是 Z-Index 为您提供 Z 轴的地方。读这个:

http://msdn.microsoft.com/en-us/library/system.windows.controls.canvas.zindex(v=vs.95).aspx

http://msdn.microsoft.com/en-us/library/system.windows.controls.canvas.zindex(v=vs.95).aspx

Take a Canvasand put inside whatever you want and then change Z-Index however you want. Here is an example:

取一个Canvas并放入您想要的任何内容,然后根据需要更改 Z-Index。下面是一个例子:

<Canvas>
    <Ellipse Canvas.ZIndex="3" Canvas.Left="5" Canvas.Top="5" Fill="Silver" Width="10" Height="10" />
</Canvas>

回答by sa_ddam213

Yes this can be done, but it depends on what Layoutcontrol the Controlsis inside

是的,这可以做到,但这取决于里面的Layout控制Controls

For example on Gridetc, you can use Panel.ZIndex

例如在Grid等上,您可以使用Panel.ZIndex

    <Grid>
        <Button Panel.ZIndex="1" />
        <Button Panel.ZIndex="0" />
    </Grid>

These are AttachedPropertiesthat are inherated from the parent container

这些是AttachedProperties从父容器继承的

回答by user613326

     Textbox.sendtoback();
     Textbox.bringtofront();