|
This may sound like a stupid question, but is your project something other than a Windows Forms app?
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
No such thing as a stupid qstn. But you're correct. My application is a Library (DLL) project which will be used by an used as a reference by UI (Windows Forms) project.
|
|
|
|
|
OK. You're probably missing the reference to System.Windows.Forms.dll.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
You know I said "there is no such thing as a stupid question". I was wrong. My initial question was really stupid!! .
I added "using System.Resources" but overlooked that it belongs in the System.Windows.Forms.Dll assembly. I was expecting that the Resources related stuff should be common and not be part of Win forms!!
Anyways, thanks much for your help.
- Malhar
|
|
|
|
|
Hi everybody!
I'm currently working on a class that has some public properties of type double . For some of them i have to restrict the set accessor, so that only values greater 0 can be assigned. Currently I'm ignoring an assigned value that is smaller 0
public double Alpha
{
set
{
if (value > 0)
this.alpha = value;
}
}
but I'm not really happy with this solution, cause the user has no feedback if the value specified by him is really assigned. Is it good practice to add an else-block and throw an ArgumentOutOfRangeException there? If so, should i offer some method to check if a double value would be valid for alpha or some static min and max fields?
Thanks in advance!
www.troschuetz.de
|
|
|
|
|
You can add a bool variable which indicate if the value has been assigned.
Like this:
<br />
public double Alpha<br />
{<br />
set<br />
{<br />
if (value > 0){<br />
assigned = true;<br />
this.alpha = value;<br />
}<br />
}<br />
}<br />
But im not sure i got your question!
I hope it helps..
VentoEngine corp.
Program your life ^^
|
|
|
|
|
This is a design decision that depends on many factors. However, generally speaking, if it were me and this variable was exposed to the user via the UI, I would put my "feedback" mechanism directly into the UI rather than putting it into the class itself.
That is, if the user defined this value in a textbox, for example, I would write the textbox in such a way that it simply would not allow the user to enter an incorrect value. I would then put something into the help file to explain the behavior. I think that is better than cluttering up your classes with a lot of exception crap and the UI with pop up warning boxes etc.
|
|
|
|
|
At first thanks for the answer.
The class I'm writing is part of a class library, so the variable may be exposed to the user via GUI but didn't necessarily have to. So I'm searching for a way, to let an user of the class check for validity of an assigned value no matter if it happens directly in code or via GUI. Currently I favor the following solution:
public double Alpha
{
set
{
if (value <= 0)
throw new ArgumentOutOfRangeException("Assigned value has to be greater 0");
this.alpha = value;
}
}
public bool IsValidAlpha(double value)
{
return value > 0;
}
}
if (obj.IsValidAlpha(1.0))
obj.Alpha = 1.0;
else
...
www.troschuetz.de
-- modified at 5:41 Thursday 1st December, 2005
|
|
|
|
|
One solution indeed could be to throw an exception when an invalid value is entered.
But you should capture this error in the user interface before the data is entered into the model you are using.
The exception is only for the other developers that use your model in their applications.
WM.
What about weapons of mass-construction?
|
|
|
|
|
At first thanks for the answer.
The class I'm writing is part of a class library, so I don't write a GUI myself. I'm searching for a way, to let an user of the class check for validity of an assigned value no matter if it happens directly in code or via GUI. Currently I favor the following solution:
public double Alpha
{
set
{
if (value <= 0)
throw new ArgumentOutOfRangeException("Assigned value has to be greater 0");
this.alpha = value;
}
}
public bool IsValidAlpha(double value)
{
return value > 0;
}
}
if (obj.IsValidAlpha(1.0))
obj.Alpha = 1.0;
else
...
www.troschuetz.de
|
|
|
|
|
You should be calling IsValidAlpha from within the setter instead of duplicating the code.
|
|
|
|
|
|
Hi:
I want to give an arbitrary number of arguments/parameters to a method and have it modify the arguments. C# says I cannot combine params and ref in the method decleration.
Please could someone suggest what I should do?
Thanks, Sam
|
|
|
|
|
Throw the objects you want to pass inside an array or ArrayList (or List<> if you're using .NET 2.0). Pass the array or list as an argument, where you can then modify the elements of the array/list.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Bought a House!
Judah Himango
|
|
|
|
|
How can I read a specific bit or series of bits (as a bit array) from a file. I can use a file stream and binary reader to get specific bytes but I do not know how to easily convert this into a bit array (at least not very efficiently).
Jim
|
|
|
|
|
To turn a byte into bits, bool is the most obvious choice ( the only one I can think of with 2 states ) and you & the value with 0x1, 0x2, 0x4, 0x8, ox10, etc to strip the bits.
I reckon this is what you've thought of, but I don't know of any more efficient way, excepting that I'd be more inclined to do this when I need the value, and not store it as bits in memory.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I still wonder if there's a quicker way - but speed is not essential for what I am doing - reading mp3 header information.
Jim
|
|
|
|
|
How can I set the position that is used for determining which item is chosen by the user pressing the up/down arrow keys? I've tried .Items[pos].Selected which works if called after the form is loaded, but it doesn't work when called from the constructor.
|
|
|
|
|
Answering my own question. making the call in the load event handler did the trick.
|
|
|
|
|
I'm creating a class that inherits from TreeView, the structure of the treeview ends up like this:
MapCategory
-Map
--MapFolder
---MapContents
-Map
MapCategory
-Map
etc. The class has two view modes, which arrange the contents into different folders. It's a complete change so I clear the Map node's children and recreate by parsing through a nested Hashtable.
However this is slow, parsing through the hashtable doesn't take long at all, but removing/adding nodes does take a noticable time. I tried to serialize the two views, but TreeNodeCollection isn't serializable, and copying the nodes out of the collection into an array, serializing it, then deserializing it into an AddRange() method call doesn't improve speed at all, since it still has to add them all.
Is there any quicker way of switching these views?
|
|
|
|
|
Could you not just have 2 treeviews, one for each view. Then just display the correct view?
|
|
|
|
|
That's my last resort, however I would prefer a solution that doesn't use up that much memory. Since each map can take up to 2MB of memory for one view, and 6MB for the other view, so having 8MB for each map could be too much. Actually on second thoughts that's not how much the nodes take up, I was watching the memory in the Task Manager, forgeting it's also loading the map at the same time. But memory is still an issue, just not that big an issue.
-- modified at 13:00 Wednesday 30th November, 2005
|
|
|
|
|
Don't know if you've solved it yet, but the tree exposes two functions called BeginUpdate and EndUpdate . Put the BeginUpdate before any tree modifications and EndUpdate when you're done. Should do the trick.
--
Joel Lucsy
|
|
|
|
|
Pen p = new Pen( Color.Blue );
p.EndCap = System.Drawing.Drawing2D.LineCap.Triangle
//How do I get it triangle to be bigger?
//How do I get a dashed line?
Thanks a lot in advance.....
|
|
|
|
|
Hello Dear SkunkedWorks
For drawing Dashed Line use these sample codes :
dashValues is an array of dash's length.
float[] dashValues = {5, 2, 15, 4};
Pen blackPen = new Pen(Color.Black, 5);
blackPen.DashPattern = dashValues;
e.Graphics.DrawLine(blackPen, new Point(5, 5), new Point(405, 5));
Bye.
|
|
|
|