简体   繁体   English

C#我可以在标签B上的标签A上显示一个图片框吗? (WinForm的)

[英]C# Can I make a picturebox that exists on tab A show on tab B? (winform)

I have a C# winform app that has a tab control, I have a picturebox on tab A and would like the very same picturebox to appear on tab B. Can this be done? 我有一个C#winform应用程序,它有一个标签控件,我在标签A上有一个图片框,并希望在标签B上显示相同的图片框。可以这样做吗?

Thank you Alison 谢谢Alison

Simply add the picture box to the second tab.. 只需将图片框添加到第二个标签..

tabControl1.TabPages["tabB"].Controls.Add(pictureBox1);

This will remove the picture box from tab A and put it, as is, inside tab B. 这将从标签A中删除图片框并将其放在标签B内。

Edit: you can have this code in the SelectedIndexChanged of the tab control to have the picture box jump between the tabs: 编辑:您可以在选项卡控件的SelectedIndexChanged中使用此代码,以使图片框在选项卡之间跳转:

private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
{
    tabControl1.TabPages[tabControl1.SelectedIndex].Controls.Add(pictureBox1);
}

I'm affraid you can't 我很害怕你不能

I though I could do it once by overriding the designer.cs file to add the control to both tabs and only got an error. 我可以通过重写designer.cs文件将控件添加到两个选项卡中来完成一次操作,但只会收到错误。

You can either make two pictureboxes, and keep them synchronized, or... 您可以制作两个图片框,并使它们保持同步,或者......

You can get the event to the tab control, OnTabChanged or something like that. 您可以将事件发送到选项卡控件OnTabChanged或类似的内容。 If the tab is Tab A or Tab B , just move the picture box to that tab. 如果选项卡是Tab ATab B ,只需将图片框移动到该选项卡即可。 I'm not exactly sure how you would do that, but I assume you would just remove it from whereever it is currently, and put it in the right place. 我不确定你会怎么做,但我认为你只是将它从目前的地方删除,并把它放在正确的地方。

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

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