这段代码如何流动? [英] How this code flows ?

查看:71
本文介绍了这段代码如何流动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用这个软件供我个人使用,我目前正在使用面板。



我写了这段代码隐藏并显示面板因为我使用按钮在软件中的窗口之间切换。

我知道它是如何工作的,但我不完全理解它,不是代码本身,它的功能如何,它如何协同工作。所以这里是代码



Im working on this software for my personal use, and im currently using panels.

And I wrote this code which hides and shows the panels because im using buttons to switch between windows in the software.
I know how it works but im not understanding it fully, not the code itself, just how its functional, how its functioning together. So here is the code

private void sideDashboard_Click(object sender, EventArgs e)
{
    activePan.Visible = false;
    gainpan.Visible = false;
    losPan.Visible = false;
}

private void mostActive_Click(object sender, EventArgs e)
{
    activePan.Visible = true;
    gainpan.Visible = false;

}

private void mostGainers_Click(object sender, EventArgs e)
{
    activePan.Visible = true;
    gainpan.Visible = true;
    losPan.Visible = false;
}

private void mostLosers_Click(object sender, EventArgs e)
{
    activePan.Visible = true;
    gainpan.Visible = true;
    losPan.Visible = true;
}





让我解释..



所以我有3个窗口命名(Pan是Panel的缩写)



activePan

收益率

losPan





我有4个按钮

sideDashboard

mostActive

mostGainers

mostLosers



正如你所看到的那样,他们彼此联系但我不完全理解的是它是如何在代码外面做。



就像我知道我从sideDashboard开始,这是你看到的主要窗口,当它被按下时它会清除所有它隐藏了它们,所以你不能看到它们但它们仍然存在。



然后当你按下最活跃的



它显示activePan但隐藏上面的那个? (gainPan)为什么?

我尝试删除该代码但是当按下按钮时我的软件真的很麻烦





Let me explain..

So I have 3 windows named (Pan is short for Panel)

activePan
gainpan
losPan


And I have 4 Buttons
sideDashboard
mostActive
mostGainers
mostLosers

As you can see they are connected to eachother but what im not fully understanding is how its doing outside the code.

Like I know that I start on the sideDashboard which is the main window that you see and when ever that is being pressed it clears out all the windows it hides them so you cant see them but they are still there.

Then when you press mostActive

it shows the activePan but hides the one above? (gainPan) Why?
I tried removing that code but that made my software really buggy when pressing the buttons

activePan.Visible = true;
gainpan.Visible = false;







然后我们有下一个按钮(bigGainers)

其中读取代码






Then we have the next button which is (mostGainers)
Which reads the code

activePan.Visible = true;
gainpan.Visible = true;
losPan.Visible = false;





又来了它隐藏在它上面的Panel



And there again it hides Panel above it which is

losPan.Visible = false;





但是为什么它隐藏在上面的那个但仍然显示它背后的2?



然后是最后一个面板





But Why is it hiding the one above but still showing the 2 behind it?

and then the last Panel which is

private void mostLosers_Click(object sender, EventArgs e)





它只显示一切,我试图隐藏它下方的2,这将改变代码来自







It just shows everything, I tried hiding the 2 below it which would be changing the code from


private void mostLosers_Click(object sender, EventArgs e)
        {
            activePan.Visible = true;
            gainpan.Visible = true;
            losPan.Visible = true;
        }











private void mostLosers_Click(object sender,EventArgs e)

{

activePan.Visible = false;

gainpan.Visible = false;

losPan.Visible = true;

}



这没有用,这让我的代码非常错!



请记住,此时我的代码功能齐全,但我不知道我是如何解决它的,我知道我是怎么做到的,我只是不明白我的意思确实



我尝试了什么:



我试过改变从真实到虚假的事情,看看结果是什么,但它使代码有缺陷和无功能,没有让我明白它的功能如何




To

private void mostLosers_Click(object sender, EventArgs e)
{
activePan.Visible = false;
gainpan.Visible = false;
losPan.Visible = true;
}

That didnt work it made my code very buggy!

Keep in mind that my code is fully functional at this moment, but im not sure how I solved it, Well I know how I did it I just dont understand what I did

What I have tried:

I've tried changing things from true to false to see what the outcome is but it made the code buggy and non functional, didnt make me understand how its functioning

推荐答案

好的 - 你有三个可能占据同一屏幕房地产的面板。

所以你一次只能显示其中一个。

所以当你想要显示一个面板时,你设置它是可见属性为 true - 但这还不足以确保可以看到它,因为其他两个中的一个可能在同一个地方,并且可以覆盖它 - 所以你必须通过将 Visible 属性设置为 false 来确保隐藏竞争:

这意味着您的三个按钮需要如下所示:

OK - you have three panels which presumably occupy the same screen "real estate".
So you can only display one of them at a time.
So when you want to show a panel, you set it's Visible property to true - but that's not enough to make sure it can be seen, because one of the other two could be in the same place, and could cover it - so you have to ensure that the "competition" is hidden by setting their Visible property to false:
Which means that your three buttons need to look like this:
private void mostActive_Click(object sender, EventArgs e)
{
    activePan.Visible = true;
    gainpan.Visible = false;
    losPan.Visible = false;
}
 
private void mostGainers_Click(object sender, EventArgs e)
{
    activePan.Visible = false;
    gainpan.Visible = true;
    losPan.Visible = false;
}
 
private void mostLosers_Click(object sender, EventArgs e)
{
    activePan.Visible = false;
    gainpan.Visible = false;
    losPan.Visible = true;
}



如果你没有明确地隐藏你不想看到的内容,它可能会留在那里并涵盖你想要看到的内容!

这有意义吗?



什么是好的第二个选项到z-order什么会我想用来显示其他面板?



暂时不要担心z顺序 - 你可能不需要玩现在用它。

相反,写一个方法可以关闭所有面板,并显示其中一个:




If you don't explicitly hide what you don't want to see, it will likely stay there and cover what you do want to see!
Does that make sense?

"What is a good "second option" to the "z-order" what would I want to use to display other panels?"

Don't worry about z-order for the moment - you probably don't need to play with it at the moment.
Instead, write a method which turns all your panels off, and displays one of them:

private Panel ShowOnly(Panel showThis)
    {
    activePan.Visible = false;
    gainpan.Visible = false;
    losPan.Visible = false;
    if (showThis != null)
        {
        showThis.Visible = true;
        }
    return showThis;
    }





然后每次调用它,传递你想要的面板名称,剩下的就完成了。



You then call it each time, passing the name of the Panel you want visible and it does the rest.

private void mostActive_Click(object sender, EventArgs e)
    {
    ShowOnly(activePan);
    }
 
private void mostGainers_Click(object sender, EventArgs e)
    {
    ShowOnly(gainpan);
    }
 
private void mostLosers_Click(object sender, EventArgs e)
    {
    ShowOnly(losPan);
    }



您的全部隐藏功能同样简单:


And your "Hide them all" feature is equally simple:

private void sideDashboard_Click(object sender, EventArgs e)
    {
    ShowOnly(null);
    }



这样,添加新面板只意味着将 Visible = false 行添加到ShowOnly ,当你希望它可见时,用新面板调用它。


That way, adding a new Panel just means adding the Visible=false line to ShowOnly, and calling it with the new panel when you want it visible.


这篇关于这段代码如何流动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆