Click here to Skip to main content
15,921,452 members
Home / Discussions / C#
   

C#

 
AnswerRe: Creating a new user control using decorator pattern Pin
T M Gray18-Jun-10 8:33
T M Gray18-Jun-10 8:33 
GeneralRe: Creating a new user control using decorator pattern Pin
Berlus18-Jun-10 11:07
Berlus18-Jun-10 11:07 
GeneralRe: Creating a new user control using decorator pattern [modified] Pin
Berlus18-Jun-10 11:09
Berlus18-Jun-10 11:09 
GeneralRe: Creating a new user control using decorator pattern Pin
DaveyM6918-Jun-10 11:14
professionalDaveyM6918-Jun-10 11:14 
GeneralRe: Creating a new user control using decorator pattern Pin
Berlus18-Jun-10 11:18
Berlus18-Jun-10 11:18 
GeneralRe: Creating a new user control using decorator pattern Pin
Luc Pattyn18-Jun-10 11:58
sitebuilderLuc Pattyn18-Jun-10 11:58 
GeneralRe: Creating a new user control using decorator pattern Pin
T M Gray18-Jun-10 11:41
T M Gray18-Jun-10 11:41 
GeneralRe: Creating a new user control using decorator pattern Pin
Berlus18-Jun-10 12:17
Berlus18-Jun-10 12:17 
T M Gray wrote:
Why are you using a control that doesn't do what you want it to?


Form where do i get such control ?

anyway, here is the first version of the class, I hope i'm not abusing this forum ...

using System;
using System.Drawing;
using System.Net.NetworkInformation;
using System.Windows.Forms;

namespace TestProgressBar
{
    public abstract class ProgressBarDecorator : ProgressBar
    {
        protected ProgressBar m_decoratedProgressBar; // the Window being decorated

        public ProgressBarDecorator()
        {

        }

        public ProgressBarDecorator(ProgressBar p_decoratedProgressBar)
        {
            this.m_decoratedProgressBar = p_decoratedProgressBar;
        }

    }

    // the first concrete decorator which adds vertical scrollbar functionality
    public class NotifiableProgressBarDecorator : ProgressBarDecorator
    {
        public long FullAmount;

        public void InformOnNewData(long p_newDelta)
        {
            float normalizedSize = Maximum - Minimum;

            if (FullAmount != 0)
            {
                int newValue = Value + (int) (p_newDelta/(float) FullAmount*normalizedSize);

                if ((Value + newValue) <= Maximum)
                {
                    Value += newValue;
                }
                else
                {
                    Value = Maximum;
                }
            }
        }

        public void Clear()
        {
            FullAmount = 0;
        }

        public NotifiableProgressBarDecorator()
        {
        }

        public NotifiableProgressBarDecorator(ProgressBar p_decoratedProgressBar)
            : base(p_decoratedProgressBar)
        {
        }
    }

    public class NetworkNotifiableProgressBarDecorator : NotifiableProgressBarDecorator
    {
        private NetworkInterface adapter;
        private Timer m_timer = new Timer();
        private long m_lastSentBytes;

        public NetworkNotifiableProgressBarDecorator()
        {
            adapter = NetworkInterface.GetAllNetworkInterfaces()[1];

            m_timer.Interval = 500;
            m_timer.Tick += onTimerTick;
        }

        public void Init(int p_totalNofBytes)
        {
            FullAmount = p_totalNofBytes;
            m_lastSentBytes = adapter.GetIPv4Statistics().BytesSent;
            m_timer.Start();
        }

        private void onTimerTick(object p_sender, EventArgs p_args)
        {
            long sentBytes = adapter.GetIPv4Statistics().BytesSent;
            if ( sentBytes - m_lastSentBytes > 0)
            {
                InformOnNewData(sentBytes - m_lastSentBytes);
            }
            m_lastSentBytes = sentBytes;
        }

        public void Stop()
        {
            m_timer.Stop();
        }
    }

}

Questionalways visible splash screen Pin
Jassim Rahma18-Jun-10 6:54
Jassim Rahma18-Jun-10 6:54 
AnswerRe: always visible splash screen Pin
Henry Minute18-Jun-10 7:11
Henry Minute18-Jun-10 7:11 
GeneralRe: always visible splash screen Pin
Luc Pattyn18-Jun-10 8:18
sitebuilderLuc Pattyn18-Jun-10 8:18 
GeneralRe: always visible splash screen Pin
Henry Minute18-Jun-10 8:20
Henry Minute18-Jun-10 8:20 
AnswerRe: always visible splash screen Pin
Muammar©18-Jun-10 8:06
Muammar©18-Jun-10 8:06 
Questiondetermine sql server 2008 express size Pin
Jassim Rahma18-Jun-10 6:12
Jassim Rahma18-Jun-10 6:12 
AnswerRe: determine sql server 2008 express size Pin
dan!sh 18-Jun-10 6:24
professional dan!sh 18-Jun-10 6:24 
AnswerRe: determine sql server 2008 express size Pin
Henry Minute18-Jun-10 7:13
Henry Minute18-Jun-10 7:13 
GeneralRe: determine sql server 2008 express size Pin
Jassim Rahma19-Jun-10 5:20
Jassim Rahma19-Jun-10 5:20 
GeneralRe: determine sql server 2008 express size Pin
Henry Minute19-Jun-10 5:45
Henry Minute19-Jun-10 5:45 
QuestionConsole is showing up with GUI Pin
muteb18-Jun-10 5:03
muteb18-Jun-10 5:03 
AnswerRe: Console is showing up with GUI Pin
Luc Pattyn18-Jun-10 5:20
sitebuilderLuc Pattyn18-Jun-10 5:20 
GeneralRe: Console is showing up with GUI Pin
muteb18-Jun-10 5:22
muteb18-Jun-10 5:22 
AnswerRe: Console is showing up with GUI Pin
PIEBALDconsult18-Jun-10 6:10
mvePIEBALDconsult18-Jun-10 6:10 
GeneralRe: Console is showing up with GUI Pin
muteb18-Jun-10 18:51
muteb18-Jun-10 18:51 
QuestionFile Upload Pin
kalyan_vb18-Jun-10 4:37
kalyan_vb18-Jun-10 4:37 
AnswerRe: File Upload Pin
Not Active18-Jun-10 4:56
mentorNot Active18-Jun-10 4:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.