|
On the very link you list it shows you need to have:
using System.Windows.Media.Brush;
So do you have your project set for .Net Framework 4.0? and have you included a reference to PresentationFramework.dll?
The following code works fine for me, I'm assuming your project is a C# WPF project:
Border myBorder1 = new Border();
myBorder1.BorderBrush = Brushes.SlateBlue;
myBorder1.BorderThickness = new Thickness(5, 10, 15, 20);
myBorder1.Background = Brushes.AliceBlue;
myBorder1.Padding = new Thickness(5);
myBorder1.CornerRadius = new CornerRadius(15);
If you'll notice I added Border to the beginning of defining myBorder1 as this is the proper way to declare the variable.
modified 21-Oct-11 0:40am.
|
|
|
|
|
It's only in .Net 4, if using 3.5 (this is a WPF question so it must be at least that) use new SolidBrush(col).
|
|
|
|
|
I want to encapsulate a large number of older DOS tools within a gui and I have chosen to do this with Visual Studio 2008 C#, but I am unhappy with my current direction.
What I have done, is using a file menu system and panels my users can click on any tool or option within the menu and all panels get set to invisible and then the one that the user wants is set to visible. This works, but it is a pain for a few reasons, probably more than I know...
The panels are all part of the same form.cs which means functions and variables all live within the same file and namespace. I would like a solution where each panel would reside within it's own file\namespace for easy code reuse and organization.
When in design view, having to move panels around to get to the panel you want to use seems unecessarily frustratring. I feel like I should be able to do this in some very simple way that I just must be missing in my "new to gui" mind.
I am not so worried about making it easier, as I am about doing it right. Any suggestions or thoughts that I could employ to best implement a solution?
Thanks for any help given,
Tim
|
|
|
|
|
Maybe what you need to look at is a tabbed solution. Have a main TabControl in your form. Implement each of your present panels as a separate UserControl, which inherits from a TabPage, and then show the correct page for each menu item. This would mean you could separate each panel in the design and coding process, making your life a lot easier.
When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman
|
|
|
|
|
How do I force the code for tab2 to be in a different file then the code on tab1? It looks like they both default into Form1.cs? The design view is easier to work with than what I had though in tabbed view, so it is a step in the right direction.
Tim
|
|
|
|
|
You should create separate UserControls for each 'panel'. Design and code each one separately. Then add the custom control to your tabcontrol, showing and closing the tab with the menu.
When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman
|
|
|
|
|
Ok, I'll read up on the userControls. Thanks for the pointer.
|
|
|
|
|
Yes, UserControls were going to be my recommendation. A user control is a class (that inherits from UserControl) so all its internal code goes in its own file. You should then expose events, properties and methods to allow UI interaction with other parts of the application, and some way of hooking up a data model for interaction with the business tier (might be very minimal if your app is basically just a wrapper for several existing ones, as that's essentially a UI only problem).
|
|
|
|
|
Or possibly as some sort of plug-in system where each utility has its own Panel or TabPage in its DLL.
|
|
|
|
|
Hi,
I have a function that converts r(red), g(green) and b(blue) values to a uint (same as RGB macro in C++).
If I implement as follows I get no errors or warnings:
private uint rgb(byte r, byte g, byte b)
{
return ((uint)((r|((uint)(g)<<8))|(((uint)b)<<16)));
}
However, if I implement like this:
private uint rgb(byte r, byte g, byte b)
{
return ((uint)((r|((ushort)(g)<<8))|(((uint)b)<<16)));
}
I get a warning "Bitwise or operator used on a sign extended operand".
But ushort is un-signed, so why am I getting the warning?
Thanks - John.
|
|
|
|
|
ushort will be being expanded to uint because b is still being shifted as a uint (as it must be). That will cause the ushort to be 'sign extended' i.e. the new bits to be filled with the top bit, I suppose, though that doesn't really make sense (an unsigned type should always be zero extended).
|
|
|
|
|
It would appear that the logical expression is yielding an int value which is,by definition, signed. You should cast each part of the expression to uint as in the first case. you should also review your use of parentheses around your expressions, a better expression would be:
return (uint)(r | (((uint)g) << 8) | (((uint)b) << 16));
return (uint)(r | (g << 8) | (b << 16));
|
|
|
|
|
Thanks Guys,
I would have expected an expression containing unsigned variables to yield an unsigned, but I must be wrong and by default it yields an int.
return (uint)(r | (g << 8) | (b << 16));
...Seems like the best option.
Thanks again.
|
|
|
|
|
The documentation[^] is a little bit ambiguous, but the implication is that a left shift will return int (Int32 ) by default, hence the problems you encountered. I am sure there is a more explicit rule somewhere in the depths of the language specification if you care to look (but hey, life is short!).
|
|
|
|
|
hi
i had an set of x and y coordinates , it is a closed loop of polygon, so how we can find the area so please give me the idea
|
|
|
|
|
This may not be easy depending on the polygon[^].
"Last year I went fishing with Salvador Dali. He was using a dotted
line. He caught every other fish." Steven Wright
|
|
|
|
|
Triangulate the polygon (you can find this algorithm in lots of places) and add up the area of all the triangles.
|
|
|
|
|
Exactly what I would have recommended. The better algorithms can even deal with concave polygons or 'holes'.
And from the clouds a mighty voice spoke: "Smile and be happy, for it could come worse!"
And I smiled and was happy And it came worse.
|
|
|
|
|
There is a better algorithm than adding triangles
It is quite straight forward you need calculate two sums
sum1 = sum of ( pt[i].x * pt[i+1 % n].y)
sum2 = sum of ( pt[i+1 % n].x * pt[i].y)
then the area is sum1 - sum2
http://www.mathopenref.com/coordpolygonarea.html[^]
|
|
|
|
|
Excellent.
|
|
|
|
|
Be aware that this method does not work with polygons with crossovers. Mind you, that is true of simplistic triangulators too.
This is a good link if the OP does not need the triangulated form for other purposes (e.g. collision detection).
|
|
|
|
|
Excellent answer, and an interesting site, thanks +5 !
It appears this algorithm will work on polygons that have areas that "go inward," as long as they do not cross.
best, Bill
"Last year I went fishing with Salvador Dali. He was using a dotted
line. He caught every other fish." Steven Wright
|
|
|
|
|
I need to get the free physical memory available so I don't get OutOfMemory Exception.
I have tried GlobalMemoryStatusEx but it seems the windows swaps out ram to virtual and the value is unreliable and ultimately results in out of memory also.
Any thoughts?
Its the man, not the machine - Chuck Yeager
If at first you don't succeed... get a better publicist
If the final destination is death, then we should enjoy every second of the journey.
|
|
|
|
|
You might want to have a look at MemoryFailPoint Class[^].
Creating an instance of a MemoryFailPoint class creates a memory gate. A memory gate is a check for sufficient resources prior to initiating an activity requiring a large amount of memory. Failing the check throws an InsufficientMemoryException[^] that avoids starting an operation, reducing the possibility of an application failing during execution due to lack of resources. This allows an application to decrease its performance in an effort to avoid an OutOfMemoryException[^] and any state corruption that may result from improper handling of an OutOfMemoryException[^] in arbitrary locations in code.
0100000101101110011001000111001011101001
|
|
|
|
|
Getting the free Physical memory will not necessarily help avoid an OutOfMemory exception - .NET is perfectly happy using virtual memory.
Have a look at this article: it covers the OOM problem in some depth. http://msdn.microsoft.com/en-us/magazine/cc163528.aspx[^]
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|