|
Okay - so you've parsed the user input and you have a bunch of expressions which evaluate to a boolean and the logical operators. What I've done in the past is create a class that represents a filter. A filter can be any sequence of conditional statements. The Filter class has three derived classes. AndFilter, OrFilter and BooleanFilter. The base class Filter looks like this:
public abstract class Filter
{
public abstract bool Evalutate();
}
The concrete classes override Evaluate are
BooleanFilter - this is a simple one. Its job is just to return the boolean value it was created with. This is what you create for each conditional statement (I'll show you how to plug it all together in a moment):
public class BooleanFilter : Filter
{
private bool value;
public BooleanFilter(bool value)
{
this.value = value;
}
public override bool Evaluate()
{
return value;
}
}
Then there is the AndFilter (the OrFilter class is almost identical so I'll not show it). The job of this class is to determine if the Evaluation of Filter A && Filter B
public class AndFilter : Filter
{
private Filter filterA;
private Filter filterB;
public AndFilter(Filter filterA, Filter filterB)
{
this.filterA = filterA;
this.filterB = filterB;
}
public override bool Evaluate()
{
bool result = filterA.Evaluate() & filterB.Evaluate();
return result;
}
}
Okay - So we have our filter classes now. All we need to do is to chain them up. Now, you have probably realised we are still evaluating in groups of two, but where this differs from your design is that this will evaluate a tree structure, not a sequential structure. Always you are comparing the nodes on the left to the nodes on the right. Some example code:
BooleanFilter a = new BooleanFilter(false);
BooleanFilter b = new BooleanFilter(false);
BooleanFilter c = new BooleanFilter(true);
BooleanFilter d = new BooleanFilter(true);
AndFilter andAB = new AndFilter(a, b);
AndFilter andBC = new AndFilter(b, c);
OrFilter orBC = new OrFilter(b, c);
Filter aOrBOrC = OrFilter(a, orBC);
Filter aAndBOrC = AndFilter(a, orBC);
Does this help?
ColinMackay.net
"Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucius
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
-- modified at 20:28 Sunday 8th January, 2006
|
|
|
|
|
I figured it out. I actually had the right solution the whole time, I just needed to let the loop run its course instead of using the break command when it equated to false. Dumb....very dumb.
|
|
|
|
|
i want to get the X, Y mouse position respect the monitor screen.
how?
|
|
|
|
|
ok i've solved with System.Windows.Forms.Form.MousePosition.X and .Y
|
|
|
|
|
Or you can use Control.MousePosition.X and Y
|
|
|
|
|
Hello all,
I have created a dialog (with alot of buttons and checkboxes), and I want this dialog to act like a message box:
I have a class, lets call it DialogBox, which has a method showInfo() which returns int type value. The method shows the dialog and return the value based on the users choice. The problem is: I want to do a loop that waits for the user choice.
I hope that my problem is clear!
cheers!
tmp0
|
|
|
|
|
No, I have no idea what you want. ShowDialog will make your dialog instance act like a message box. If you want to keep showing the dialog over and over until the input is acceptable, this is bad UI, your dialog should not close until it has the input it needs, and it should tell the user why it refuses to close, or better yet, don't make the OK button clickable until validation succeeds.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Hello Christian!
Sorry if it was a silly question; I should have simply said that I want a modal dialog (not a modeless dialog), which describes my problem more clearly.
Anyway, ShowDialog() did solve my problem! Thank you!
tmp0
|
|
|
|
|
Anyone know of a lossless jpg library in C# ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Depends if you want it free or not.
Atalasoft DotImage[^] does lossless JPEG.
ColinMackay.net
"Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucius
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
|
|
|
|
|
$1000 for an SDK that gives us lossless jpg is not unreasonable, but I'm not the one paying, and the one paying has decreed - find something free. Especially when this is overall an imaging SDK, and my core function is to write imaging code...
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Ah... Sorry then - I don't know of anything else.
ColinMackay.net
"Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucius
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
|
|
|
|
|
No worries. I had found that SDK with google, but thanks for the suggestion all the same. I'm dreading finding some open source library in C and trying to get it to bridge to managed C++ in a dll. That's not the way to go, IMO.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Shouldn't you then spend your time on things others don't have?
We say "get a life" to each other, disappointed or jokingly. What we forget, though, is that this is possibly the most destructive advice you can give to a geek.
boost your code || Fold With Us! || sighist
|
|
|
|
|
Yeah, that's my theory.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
|
It's a different compression, but falls under the jpg banner.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Christian Graus wrote: lossless jpg
jpeg is never lossless, so you need another picture format.
'A programmer is just a tool which converts caffeine into code'
|
|
|
|
|
There is in fact a lossless compression which is known as lossless jpg. It is NOT a normal jpg at 100%, I know that is still lossy.
Thanks for taking the time to answer though.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Christian Graus wrote: There is in fact a lossless compression which is known as lossless jpg
I've never heard about this, sorry.
'A programmer is just a tool which converts caffeine into code'
|
|
|
|
|
I'm not sure that it's widely used.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
what i noticed is that when your program crashes or you kill the process etc... (i mean generally situations when appplicaion is being closed in an unnormal way ) notifyicon remains in system tray area. it disappears as soon as you move mouse cursor over it, but if you don't do it it might be there for ages... :]. so my little question is, how to force application to get rid of it in such case. the point is it's not only about my programs, but generally there are many situations when after emergency closure program leaves icon . or perhaps we should force system to refresh its tray? but how to do it? any ideas? thank you in advance
|
|
|
|
|
Explicitly referencing and removing the icon from the tray
// hide icon from the systray
notifyIcon1.Visible = false;
|
|
|
|
|
i know how to hide icon from the tray, but how to do it when crash occurs... literally, i need a place in code where this snippet should be or a general way of handling crashes, process kills etc...
|
|
|
|
|
You can add an event handler for AppDomain.UnhandledException to catch any exception that wasn't handled yet and then remove the icon from the systray.
This also means you have to have access to the notifyicon at this place, what might not be desirable at this moment.
Regards,
mav
|
|
|
|