|
Thanks for your answer, it is execatly what I was aiming for, beacause I need some help understanding the pattern.
I've looked up decorator pattern in wikipedia, and i quote:
http://en.wikipedia.org/wiki/Decorator_pattern
"In object-oriented programming, the decorator pattern is a design pattern that allows new/additional behaviour to be added to an existing object dynamically."
dynamically, as you said.
but in the motivation part:
"As an example, consider a window in a windowing system. To allow scrolling of the window's contents, we may wish to add horizontal or vertical scrollbars to it, as appropriate. Assume windows are represented by instances of the Window class, and assume this class has no functionality for adding scrollbars. We could create a subclass ScrollingWindow that provides them, or we could create a ScrollingWindowDecorator that adds this functionality to existing Window objects. At this point, either solution would be fine."
which seemed like what i'm trying to do.
Thanks, Berlus
|
|
|
|
|
After rereading the article i'm attaching a sample class:
public abstract class ProgressBarDecorator : ProgressBar
{
protected ProgressBar m_decoratedProgressBar;
public ProgressBarDecorator()
{
}
public ProgressBarDecorator(ProgressBar p_decoratedProgressBar)
{
this.m_decoratedProgressBar = p_decoratedProgressBar;
}
}
public class NotifiableProgressBarDecorator : ProgressBarDecorator
{
public NotifiableProgressBarDecorator()
{
}
public NotifiableProgressBarDecorator(ProgressBar p_decoratedProgressBar)
: base(p_decoratedProgressBar)
{
}
protected override void OnCreateControl()
{
base.OnCreateControl();
this.BackColor = Color.Green;
this.Value = 50;
}
}
}
It is the base design fot my implementation, if it will be any good, i might consider posting as an article.
Your thoughts ans suggestions are most welcome.
Thanks,
Belrus
modified on Friday, June 18, 2010 5:17 PM
|
|
|
|
|
First thought is to use the 'code block' widget above the edit box when posting so your code is surrounded by <pre></pre> tags so the code is legible.
DaveIf this helped, please vote & accept answer!
Binging is like googling, it just feels dirtier. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
|
Right.
|
|
|
|
|
That isn't what you are trying to do. Adding a scrollbar to a window doesn't change anything about the underlying functionality of the window. How the window is closed, moved, z-ordered etc. all remain intact. Changing the methodology a progress bar uses to determine the amount of progress is a fundamental change to the existing underlying functionality, not an addition. Adding a user preference for the color of the progress bar would be more of a decorator.
I see from one of your other responses that it is a 3rd party control you are dealing with. Decorator pattern seems to be what you want only because you can't do it with subclassing because you don't have the source to do it. You are shoehorning your design requirement into a pattern based on other external factors.
Why are you using a control that doesn't do what you want it to?
|
|
|
|
|
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;
public ProgressBarDecorator()
{
}
public ProgressBarDecorator(ProgressBar p_decoratedProgressBar)
{
this.m_decoratedProgressBar = p_decoratedProgressBar;
}
}
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();
}
}
}
|
|
|
|
|
how can i show a splash screen which should be visible until the main form is fully loaded and shown?
|
|
|
|
|
There are many, many articles here on Code Project that show how to do what you want. Use the Search Box on the home page. You'll find loads of examples.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
Why do programmers often confuse Halloween and Christmas? - Because 31 Oct = 25 Dec.
Business Myths of the Geek #4 'What you think matters.'
|
|
|
|
|
And yet I haven't seen a splash screen implementation I really like; I do it differently and I'm afraid I really should write yet another article on the subject.
|
|
|
|
|
You continental types always were too picky!
On the rare occasions that I use a splash screen, I too do it differently.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
Why do programmers often confuse Halloween and Christmas? - Because 31 Oct = 25 Dec.
Business Myths of the Geek #4 'What you think matters.'
|
|
|
|
|
Here:
public partial class Splash : Form
{
private void Splash_Load(object sender, EventArgs e)
{
tmrWasteTime.Start();
}
private void tmrFader_Tick(object sender, EventArgs e)
{
if(this.Opacity >0.01)
this.Opacity = this.Opacity - 0.03;
else
kill_tmrFader();
}
Form1 form1;
private void kill_tmrFader()
{
tmrFader.Stop();
form1 = new Form1();
this.Hide();
}
int waste;
private void tmrWasteTime_Tick(object sender, EventArgs e)
{
if (waste < 2)
waste++;
else
kill_tmrWasteTime();
}
private void kill_tmrWasteTime()
{
tmrWasteTime.Stop();
tmrFader.Start();
}
}
In this, example, you realize I'm using some components like timers, you can modify it to fit your needs, however, make sure you call the Splash in this example from your Program.cs and modify form1 here to your called form.
Cheers.
Muammar.
modified on Friday, June 18, 2010 2:15 PM
|
|
|
|
|
as sql server express 2008 is limited, how can I determine the current size of the database using c#?
|
|
|
|
|
You can use the system procedure sp_helpdb for this.
|
|
|
|
|
If you get the latest download, they have increased the size from 4 to 10GB.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
Why do programmers often confuse Halloween and Christmas? - Because 31 Oct = 25 Dec.
Business Myths of the Geek #4 'What you think matters.'
|
|
|
|
|
wow!! really?
where is this article? and where is the URL for the download? I have SQL Server 2008 Express.
|
|
|
|
|
Just one of many links here[^].
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
Why do programmers often confuse Halloween and Christmas? - Because 31 Oct = 25 Dec.
Business Myths of the Geek #4 'What you think matters.'
|
|
|
|
|
Hi
I have problem with console when i run my GUI. I starts to show itself for no reason with GUI. Is there any possible way that I can just run my GUI without the console?
|
|
|
|
|
You get a Console when you either ask for one using explicit code, or when you specify a Console App (which will happily let you create and show Forms as well). What did you do? Which using statements did you get automatically, and which ones did you add? What are your project settings? what is in your static Main() method?
|
|
|
|
|
I actually I'm working with group and I'm just collecting their application and implement it as one application.
|
|
|
|
|
You likely have the project set to console app, set it to windows app.
|
|
|
|
|
thank you very much. yupe the setting was in the console app.
|
|
|
|
|
Hi,
Is there any way to find that the uploaded file is correctly saved in a given folder?
Thanks and Regards,
kalyan
|
|
|
|
|
File.Exists(path)
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Hi There everyone,
Does anyone know how i can automate the process of publishing a webapplication.
Normally in Visual studio i go to Build | publish and fill in the data.
However i want to do this using c# , so that the process can be completely automated.
I tried it using the Microsoft.Build.Engine. But i did not succeed.
Thanx in advance.
|
|
|
|