我决定发布我为使我的解决方案发挥作用所做的工作。 GvS 有最接近的答案,并让我朝着正确的方向前进,所以我给了他(可能是她,但来吧)正确的答案复选标记,因为我不能给自己。
我从来没有弄清楚如何从一个选项卡“交叉淡入淡出”到另一个选项卡(降低一个选项卡的不透明度并提高另一个选项卡的不透明度),但我发现等待在位图上绘制一个灰色框,越来越多的灰色给它淡入我的背景的效果,这也是灰色的。然后,我将第二个选项卡作为灰色位图开始,我慢慢添加较少的灰色,并与每次迭代的选项卡图像相结合,使其具有淡化效果。
这个解决方案会产生一个很好的淡入淡出效果(即使我自己这么说),但它是非常线性的。我将为 alphablend 变量使用随机数生成器,看看这是否会使其线性度降低一些,但用户可能会再次欣赏可预测性。顺便说一句,我使用 button_click 触发切换选项卡事件。
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;
public int alphablend;
public Bitmap myBitmap;
private void button1_Click(object sender, EventArgs e)
{
alphablend = 0;
pictureBox1.Visible = true;
myBitmap = new Bitmap(tabControl1.Width, tabControl1.Height);
while (alphablend <= 246)
{
tabControl1.DrawToBitmap(myBitmap, new Rectangle(0, 0, tabControl1.Width, tabControl1.Height));
alphablend = alphablend + 10;
pictureBox1.Refresh();//this calls the paint action
}
tabControl1.SelectTab("tabPage2");
while (alphablend >= 0)
{
tabControl1.DrawToBitmap(myBitmap, new Rectangle(0, 0, tabControl1.Width, tabControl1.Height));
alphablend = alphablend - 10;
pictureBox1.Refresh();//this calls the paint action
}
pictureBox1.Visible = false;
}
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
Graphics bitmapGraphics = Graphics.FromImage(myBitmap);
SolidBrush greyBrush = new SolidBrush(Color.FromArgb(alphablend, 240, 240, 240));
bitmapGraphics.CompositingMode = CompositingMode.SourceOver;
bitmapGraphics.FillRectangle(greyBrush, new Rectangle(0, 0, tabControl1.Width, tabControl1.Height));
e.Graphics.CompositingQuality = CompositingQuality.GammaCorrected;
e.Graphics.DrawImage(myBitmap, 0, 0);
}