|
I wanna expand the ability of some class provided by framework like Bitmap, but I find it modified by sealed.
How can i do with it?
Another similar problem is when i try to inherit XmlElement, I find its construction is modified by internal. Then the compiler find it as an error. any solution to bypass?
|
|
|
|
|
I had the same problem with SqlDataReader. I just created a new class that wrapped each SqlDataReader method and property and then inherited from my class. It kind of sucks but I don't think there is any other way.
|
|
|
|
|
Well, the wrapper is boring but i fininally made it.
I think if Microsoft holds its position on sealing their class, then it will be a good idea to design a wizard to automatively build a wrapper. Hope C#'s reflection ability will make it possible.
Do you think so?
|
|
|
|
|
Yes it stinks. The reason for Bitmap being sealed is because it is a wrapper around GDI+ which is a native DLL. .NET doesn't support inheritence from a native image, yet anyway
James
Sonork: Hasaki
"I left there in the morning
with their God tucked underneath my arm
their half-assed smiles and the book of rules.
So I asked this God a question
and by way of firm reply,
He said - I'm not the kind you have to wind up on Sundays."
"Wind Up" from Aqualung, Jethro Tull 1971
|
|
|
|
|
I can't speak for them all...
but some are sealed for performance reasons.
and I quote from "Applied Microsoft .NET Framework Programming":
" the CLR knows the exact layout of the fields defined within the String type, and the CLR accesses these feilds directly." ... If String were not sealed, "you could add your own fields, which would break the assumptions the CLR makes, In addition, you could break some assumptions that the CLR has made about String objects being immutable."
|
|
|
|
|
Andy Smith wrote:
and I quote from "Applied Microsoft .NET Framework Programming":
" the CLR knows the exact layout
Here is Mircosoft "knowing" everything again...
Nick Parker
|
|
|
|
|
How can I draw a bitmap button with a transparent background.
Im using the code below to try and do this but its not working how it should.
Bitmap b = new Bitmap("D:\\-=[Pics]=-\\test.jpg");
b.MakeTransparent(b.GetPixel(0,0));
pe.Graphics.FillRectangle (Brushes.Transparent,ClientRectangle);
pe.Graphics.DrawImage(b,ClientRectangle);
Im trying to paint the button transparent then draw an image whose transparency key is the same as the color at 0,0 of the bitmap. It sort of works but when the image is drawn on the button the background looks more like swiss cheese than transparent.
Any help would be great.
Thanks Danny
|
|
|
|
|
Try opening the JPEG in an image viewer, I bet your background color got mangled during the compression of the file resulting in a slightly different color in spots (but nothing the human eye would notice).
If possible you should stick to lossless image formats such as: BMP, GIF, PNG
HTH,
James
Sonork: Hasaki
"I left there in the morning
with their God tucked underneath my arm
their half-assed smiles and the book of rules.
So I asked this God a question
and by way of firm reply,
He said - I'm not the kind you have to wind up on Sundays."
"Wind Up" from Aqualung, Jethro Tull 1971
|
|
|
|
|
What could be done in C# which would add much in language expressiveness
without any penalties to security and efficiency.
Before implement any language feature I think designers discussed them many
times and surely they analyzed any similar implementation in all the languages
(not only C,C++, but Java, FoxPro, Pascal, ADA, etc). So C# is not just a
revamped dialect version of C++ + garbage collection (such attempts to create
garbage collection feature to C++ have been made many times), that's why my
question is purely ritoric: why they didn't do that? What is that ... read
below.
In language description we read that in order to go out of innermost
cycle we should use goto operator. Yes, of course, but wouldn't it be better to
write something like this?
for (condition_1)
{
....
while(condition_2)
{
....
break level; // level see next comment
/* level - int expression, if 0 means regular break;
1 - means one level up, in this particular case
means exit from for cycle
*/
...
continue level; // see comments above
}
...
}
I've been wondering why it hadn't been done since the first C-compilers
appeared, I worked then on PDP11. Java made it better, but still it is too
similar to goto..
Another question: Look at this snippet of code
if(codition_1)
{
....//do smth
}
else
{
if(codition_2)
{
....//do smth
}
else
{
if(codition_3)
{
....//do smth
}
else
{
}
}
}
isn't it ugly? Imagine 20 conditions analyzed, what will happen to nesting
level? Then compare to this: (borrowed from FoxPro,Clipper...)
switch
{
case (condition_1)
.... // no need of break, that has become obligatory in C# !!!
case (condition_1)
...
default:
}
By the way switch operator in old C-style definition could be used as well,
they wouldn't interfere with each other.
I don't see any reasons not to implement such useful features.
Alex .
ovarlamov@sprint.ca
|
|
|
|
|
I agree with you that C# switch statement is unneccesarily poor. It is such things that make me almost want to move to VB.Net.
VB and C# are on the same level, performance-wise, and VB has some _great_ syntax niceties such as a GOOD switch statement ( Select/Case ) and the With statement.
Although, in the long run I doubt i'll ever switch to vb.net... if only for the reason that I fully expect that a programmer who has "c#" on his resume can demand a higher pay than one with "VB.net" on it; regardless if that is an intelligent decision.
|
|
|
|
|
Hi Guys,
I need a little help.
The scenario is as follows,
I have an interface I,
Class C implements I.
C compiles to dll.
In another project
I want to Assembly.Load C
and cast it to interface I so that I can use the methods in C
Is this possible. What do I need to do? I'm very new to Assemblies!
If not what the alternatives?
Please help!
- Tariq
|
|
|
|
|
Yes its quite possible, I've written an article that does just that Using reflection to extend .NET programs.
James
Sonork: Hasaki
"I left there in the morning
with their God tucked underneath my arm
their half-assed smiles and the book of rules.
So I asked this God a question
and by way of firm reply,
He said - I'm not the kind you have to wind up on Sundays."
"Wind Up" from Aqualung, Jethro Tull 1971
|
|
|
|
|
Hi, I would like to check if there is running any instance of my application, in order to set the focus on it if the user try to start a new one.
Any idea?
Thank you.
|
|
|
|
|
Something like this:
Int32 RunningProcesses = Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName ).Length;
if ( RunningProcesses >= 1 ) {
MessageBox.Show( "already running the program" );
}
--
David Wengier
Sonork ID: 100.14177 - Ch00k
|
|
|
|
|
Just wanted to say thanks for posting this, because you probably saved me hours of trying to figure this out in C#!
Thanks!
Marc
|
|
|
|
|
Hi all,
I've been trying to have a simple checkbox in my datagrid using C# and it's being a pain to get it to work.
Here is the cenario.
I have a DataSet populated with a table "Employees" let's say. This table has fields such id, name, email.
All I want to do is to display an extra column in my datagrid that will display a checkbox for each row.
Note, there is no data associated with this checkbox. I just wanted the user to select some of the Employees from the datagrid by checking the checkbox. Then, when they click the button "Print", I will loop through the datagrid, get the selected ones and print.
Anyone can give me some instructions or example of how to do that?
I've been looking some people examples that do something similar. But they don't really show how to add an extra column to the datagrid with a checkbox for each record of your already populated dataset.
Please, any help will be appreciated.
Thanks to all.
Anderson
Anderson F.
afraga22@hotmail.com
|
|
|
|
|
You can add an unbound column to your datagrid and use a bool columnstyle for that unbound column. You can download a sample showing how to add an unbound column from:
http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.asp#q787q
Clay Burch
www.syncfusion.com
|
|
|
|
|
Hello Clay,
Thanks a lot.
That's a pretty good link.
I will try it and I let you know when I get it to work.
Thanks again.
Anderson
Anderson F.
afraga22@hotmail.com
|
|
|
|
|
We offically have the ASP/ASP.NET message board beat by 18 messages, we are on our way....
Nick Parker
|
|
|
|
|
Ok, this makes me feel really stupid, but when I am looking at the code view in VS.NET I have the two drop down boxes at the top. This is very similar to VB6 where the left combo box lists all the objects(i.e. - buttons, grids, labels) and the right most combo box will list all methods and properties associated to what is selected in the left combo box. Why do I only see my forms for my project listed in the left combo box? Where are my objects that are on that form. How can I see all the methods and properties available to those object on my form? Please someone point me in the right direction. Thanks
Nick Parker
|
|
|
|
|
On the top right is a dialog box where you can choose class view, solution explorer or resource view ( the last is useless, I've not seen anything there yet ,and I've added resources ). That's where you'll find your methods and classes.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
"I'm somewhat suspicious of STL though. My (test,experimental) program worked first time. Whats that all about??!?!
- Jon Hulatt, 22/3/2002
|
|
|
|
|
Thanks,
Now I probably sound like I am complaining(I am), but is there any way that I can move this or have it view the methods and properties the "old-fashioned way" or should I just give in?
Anyway, Thanks again Christian
Nick Parker
|
|
|
|
|
VB.NET uses those drop down boxes as you expect, so the answer is yes, but you would have to code in VB.NET
Not that that is a bad thing
--
David Wengier
Sonork ID: 100.14177 - Ch00k
|
|
|
|
|
Yes, you can drag/redock and size that dialog.
I'd also guess you'd get something like the old Wizard bar if you right clicked in the toolbar area and checked what other toolbars you can make visible.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
"I'm somewhat suspicious of STL though. My (test,experimental) program worked first time. Whats that all about??!?!
- Jon Hulatt, 22/3/2002
|
|
|
|
|
Thanks,
I will probably keep it the way it is right now, thanks agian.
Nick Parker
|
|
|
|