Moin,
Also ich nutze ein custom Tabcontrol das einen Slide Effekt beim TabPage Switchen zeigt, was nicht schlecht aussieht:
Src Code:
Das ganze funktioniert soweit auch recht nett, aber es gibt ein kleines Problem:
Beim ersten ansprechen (durchswitchen) der TabPages, tauchen die Controls auf der nächsten Seite schlagartig erst auf wenn der slide effect fertig ist.
ist man bereits ein zweites mal durchgeswitcht geht das fließend und die controls sind in dem slide effekt zu sehen.
Kann mir jemand helfen wie ich den Code anpassen muss das auch zu beginn (beim ersten switchen) der slide effekt zu sehen ist?
Habe mich schon durch gedebugged und diverse Loops getauscht und geändert, aber kein ergebnis erzielt
Also ich nutze ein custom Tabcontrol das einen Slide Effekt beim TabPage Switchen zeigt, was nicht schlecht aussieht:
Src Code:
C#-Quellcode
- using System;
- using System.Drawing;
- using System.Windows.Forms;
- public class AnimTab : TabControl
- {
- int OldIndex;
- private int _Speed = 9;
- public int Speed
- {
- get { return _Speed; }
- set
- {
- if (value > 20 | value < -20)
- {
- MessageBox.Show("Speed needs to be in between -20 and 20.");
- }
- else
- {
- _Speed = value;
- }
- }
- }
- public AnimTab()
- {
- SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw, true);
- }
- public void DoAnimationScrollLeft(Control Control1, Control Control2)
- {
- Graphics G = Control1.CreateGraphics();
- Bitmap P1 = new Bitmap(Control1.Width, Control1.Height);
- Bitmap P2 = new Bitmap(Control2.Width, Control2.Height);
- Control1.DrawToBitmap(P1, new Rectangle(0, 0, Control1.Width, Control1.Height));
- Control2.DrawToBitmap(P2, new Rectangle(0, 0, Control2.Width, Control2.Height));
- foreach (Control c in Control1.Controls)
- {
- c.Hide();
- }
- int Slide = Control1.Width - (Control1.Width % _Speed);
- int a = 0;
- for (a = 0; a <= Slide; a += _Speed)
- {
- G.DrawImage(P1, new Rectangle(a, 0, Control1.Width, Control1.Height));
- G.DrawImage(P2, new Rectangle(a - Control2.Width, 0, Control2.Width, Control2.Height));
- }
- a = Control1.Width;
- G.DrawImage(P1, new Rectangle(a, 0, Control1.Width, Control1.Height));
- G.DrawImage(P2, new Rectangle(a - Control2.Width, 0, Control2.Width, Control2.Height));
- SelectedTab = (TabPage)Control2;
- foreach (Control c in Control2.Controls)
- {
- c.Show();
- }
- foreach (Control c in Control1.Controls)
- {
- c.Show();
- }
- }
- protected override void OnSelecting(System.Windows.Forms.TabControlCancelEventArgs e)
- {
- if (OldIndex < e.TabPageIndex)
- {
- DoAnimationScrollRight(TabPages[OldIndex], TabPages[e.TabPageIndex]);
- }
- else
- {
- DoAnimationScrollLeft(TabPages[OldIndex], TabPages[e.TabPageIndex]);
- }
- }
- protected override void OnDeselecting(System.Windows.Forms.TabControlCancelEventArgs e)
- {
- OldIndex = e.TabPageIndex;
- }
- public void DoAnimationScrollRight(Control Control1, Control Control2)
- {
- Graphics G = Control1.CreateGraphics();
- Bitmap P1 = new Bitmap(Control1.Width, Control1.Height);
- Bitmap P2 = new Bitmap(Control2.Width, Control2.Height);
- Control1.DrawToBitmap(P1, new Rectangle(0, 0, Control1.Width, Control1.Height));
- Control2.DrawToBitmap(P2, new Rectangle(0, 0, Control2.Width, Control2.Height));
- foreach (Control c in Control1.Controls)
- {
- c.Hide();
- }
- int Slide = Control1.Width - (Control1.Width % _Speed);
- int a = 0;
- for (a = 0; a >= -Slide; a += -_Speed)
- {
- G.DrawImage(P1, new Rectangle(a, 0, Control1.Width, Control1.Height));
- G.DrawImage(P2, new Rectangle(a + Control2.Width, 0, Control2.Width, Control2.Height));
- }
- a = Control1.Width;
- G.DrawImage(P1, new Rectangle(a, 0, Control1.Width, Control1.Height));
- G.DrawImage(P2, new Rectangle(a + Control2.Width, 0, Control2.Width, Control2.Height));
- SelectedTab = (TabPage)Control2;
- foreach (Control c in Control2.Controls)
- {
- c.Show();
- }
- foreach (Control c in Control1.Controls)
- {
- c.Show();
- }
- }
- }
Das ganze funktioniert soweit auch recht nett, aber es gibt ein kleines Problem:
Beim ersten ansprechen (durchswitchen) der TabPages, tauchen die Controls auf der nächsten Seite schlagartig erst auf wenn der slide effect fertig ist.
ist man bereits ein zweites mal durchgeswitcht geht das fließend und die controls sind in dem slide effekt zu sehen.
Kann mir jemand helfen wie ich den Code anpassen muss das auch zu beginn (beim ersten switchen) der slide effekt zu sehen ist?
Habe mich schon durch gedebugged und diverse Loops getauscht und geändert, aber kein ergebnis erzielt
C# Developer
Learning C++
Learning C++