0

Hi I wonder if someone can help. I have managed to create a volume meter and am using the pipe "|" character for the visual display. I am able to change the color based on the volume Peak level and that works fine, but all the characters font colors change. What I am after however is for the original colors to remain. So that the string of pipes show Green, Yellow, Orange and then Red. Here is my code... So the question is how do I retain the original font colors, but change the new font colors as the volume starts to peak. If that Makes any sense. Many Thanks.

public void audiometering()
{
    // start timer and select the volume value
    vmt.Start();
    MMDevice defaultDevice = devEnum.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia);
    var volume = defaultDevice.AudioMeterInformation.MasterPeakValue;
    var scale = (int)Math.Floor(volume * 20);
    vUMonitorToolStripMenuItem.Text = volume.ToString();
    // calculate scale of volume and display as pipes
    var sb = new StringBuilder();
    sb.Append('|', scale);
    sb.Append(' ', 20 - scale);
    vUMonitorToolStripMenuItem.Font = new Font(vUMonitorToolStripMenuItem.Font, FontStyle.Bold);

    if ((scale <= 5))
    {
        vUMonitorToolStripMenuItem.ForeColor = Color.Green;
    }
    if ((scale >= 5 && scale <= 10))
    {
        vUMonitorToolStripMenuItem.ForeColor = Color.Yellow;
    }
    if ((scale >= 10 && scale <= 15))
    {
        vUMonitorToolStripMenuItem.ForeColor = Color.Orange;
    }
    if ((scale >= 15))
    {
        vUMonitorToolStripMenuItem.ForeColor = Color.Red;
    }
    vUMonitorToolStripMenuItem.Text = sb.ToString();
}
DaveShaw
  • 52,123
  • 16
  • 112
  • 141
  • A ToolStripMenuItem can only have one ForeColor for all the text, you will either need to use a different UI, or write a custom MenuItem that you can control the colors yourself. – DaveShaw Dec 09 '16 at 11:41
  • 1
    Possible duplicate of [Multiple colors in a C# .NET label](http://stackoverflow.com/questions/275836/multiple-colors-in-a-c-sharp-net-label), It is about a label but the resulting answer will be the same/similar. – TheLethalCoder Dec 09 '16 at 11:42
  • Thanks for the response guys, the only reason I think it could work is because at certain points there are 2 colors clearly visible in the label. – John Henderson Dec 09 '16 at 11:51
  • Well it can't work. All you may see are visual glitches. – TaW Dec 09 '16 at 12:48

0 Answers0