Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. Fade TabPage between TabControl's tab selection

Fade TabPage between TabControl's tab selection

Scheduled Pinned Locked Moved Managed C++/CLI
graphicshelpcssalgorithmsquestion
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    roshihans
    wrote on last edited by
    #1

    After searching on the internet, the possible solution that come out is by using TabPage.DrawToBitmap, put the bitmap in a PictureBox, set the position of PictureBox to the same location of TabPage, and fade it. The code is below :

    System::Void tabControl1_SelectedIndexChanged(System::Object^ sender, System::EventArgs^ e)
    {
    alphaBlend = 250;
    repaint = true;

    // set TabPicture visibility, location, and size
    TabPictureBox->Visible = true;
    int posX = tabControl1->Location.X + tabControl1->TabPages\[tabControl1->SelectedIndex\]->Margin.Left + 1;
    int posY = tabControl1->Location.Y + tabControl1->ItemSize.Height + 1 + 
    	tabControl1->TabPages\[tabControl1->SelectedIndex\]->Margin.Top;
    TabPictureBox->Location = System::Drawing::Point(posX, posY);
    TabPictureBox->Size = tabControl1->TabPages\[tabControl1->SelectedIndex\]->Size;
    
    // set Bitmap
    TabBitmap = gcnew Bitmap(tabControl1->TabPages\[tabControl1->SelectedIndex\]->Width, 
    	tabControl1->TabPages\[tabControl1->SelectedIndex\]->Height);			
    tabControl1->TabPages\[tabControl1->SelectedIndex\]->DrawToBitmap(TabBitmap,
    		Rectangle(0, 0, tabControl1->TabPages\[tabControl1->SelectedIndex\]->Width, 
    			tabControl1->TabPages\[tabControl1->SelectedIndex\]->Height));
    
    while (alphaBlend > 0)
    {				
    	alphaBlend = alphaBlend - 25;
    	TabPictureBox->Refresh();
    }
    
    TabPictureBox->Visible = false;
    repaint = false;
    

    }

    System::Void TabPictureBox_Paint(System::Object^ sender, System::Windows::Forms::PaintEventArgs^ e)
    {
    if (repaint)
    {
    if (TabBitmap != nullptr)
    {
    Bitmap^ temp = gcnew Bitmap(TabBitmap);
    Graphics^ bitmapGraphics = Graphics::FromImage(temp);
    if (alphaBlend < 0) alphaBlend = 0;
    SolidBrush^ greyBrush = gcnew SolidBrush(Color::FromArgb(alphaBlend, Color::White));
    bitmapGraphics->CompositingMode = CompositingMode::SourceOver;
    bitmapGraphics->FillRectangle(greyBrush, Rectangle(0, 0, TabBitmap->Width, TabBitmap->Height));
    e->Graphics->CompositingQuality = CompositingQuality::GammaCorrected;
    e->Graphics->DrawImage(temp, 0, 0);
    }
    }
    }

    The problem is that each time I select the tabPage, my CPU usage spike to 70 - 80% and the fading effect is kind of slow. Is there any solution to fix it so that I can draw the bitmap faster and with minimum CPU usage (less than 50%)? Thanks.

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups