0

Using MetroFramework 1.3.5 and .NET Transitions, in Windows Forms, I have written the code for a live MetroTile. Here is the Timer Tick method used to update the tile:

private void updateTiles_timer_Tick(object sender, EventArgs e)
{
    metroPanel1.BackColor = Color.Transparent;
    Bitmap bm = new Bitmap(metroPanel1.Width, metroPanel1.Height);
    metroTile_startStop.DrawToBitmap(bm, new Rectangle(metroTile_startStop.Location.X, metroTile_startStop.Location.Y, metroTile_startStop.Width, metroTile_startStop.Height));
    metroPanel1.BackgroundImage = bm;

    if (animationFlag)
    {
        metroTile_startStop.Text = Properties.Resources.startStopTile_alternateText;
        animationFlag = false;
     }
     else
     {
         metroTile_startStop.Text = "Start";
         animationFlag = true;
     }
     Transition.run(metroTile_startStop, "Top", metroTile_startStop.Height - 16, 4, new TransitionType_Linear(500));
}

private void metroPanel1_Click(object sender, EventArgs e)
{
    metroTile_startStop.PerformClick();
}

The tile is placed inside a MetroPanel with the Size(tile.Width + 10, tile.Height + 8). metroPanel1_Click() is necessary if, during a transition, the user clicks the background bitmap.

I don't have sufficient experience and I need help in writing a custom control so I can easily reuse it in future projects. The control should have a property which sets the timer interval and the possibility to set the tile texts. If I have a working code, then I can extend it to set the tile image, customize animations etc.

Thank you!

Cristian M
  • 715
  • 2
  • 12
  • 32
  • *I need help in writing a custom control.* It seems you forgot to ask your question. – Reza Aghaei Mar 14 '16 at 12:03
  • I tried to create a custom control starting from code examples from other controls, but I did not figure out how to update the tile when the Timer Tick method is called (when I change the tile text, the tile is not updated (maybe I should use Paint()?) and how to create new control properties (like Timer Interval and Alternate Text). – Cristian M Mar 18 '16 at 20:52
  • You should break the problem to smaller and specific parts and then you can solve the problem. When you ask a small and specific question and write some code to reproduce a problem, usually you are the first one who solve the problem and if you can't find the problem.Also using your specific problem description and your code samples to reproduce the problem other users can help you to solve the problem. So I recommend you to edit the question and ask an specific question. – Reza Aghaei Mar 18 '16 at 21:29
  • @RezaAghaei Thank you for your advice. You can find my specific question here: http://stackoverflow.com/questions/36104358/how-to-update-text-in-a-metrotile – Cristian M Mar 19 '16 at 16:46

0 Answers0