SmartResize - a fairly simple Windows Forms sample

I wrote a simple class deriving from System.Windows.Forms.Form some time ago after listening to Shawn Burke’s DEV 394 talk from Tech-Ed U.S. It uses the application idle event to use CPU resources more sparingly when resizing a form. This can be useful if you’re deploying to clients with less than stellar machines, or if you have a large number of docked/anchored controls on a form. I probably should have called it “CheapResize” instead of “SmartResize” but that doesn’t sound quite as catchy.  It also adds “begin resize” and “end resize” events to the form. I couldn’t see any similar code on GotDotNet so I submitted it. Here it is. The SmartResize class is written in C#, and there are two demos (one in C# and one in VB.NET) which inherit from it. The catchy “I Love .NET” image in the C# sample was an image I created and then made into an iron on transfer for a T-Shirt.

Comments

carlos olavo lima
muito grato
3/07/2004 9:43:00 AM
carlos olavo lima
muito grato
3/07/2004 9:44:00 AM
carlos olavo lima
muito grato
3/07/2004 9:46:00 AM

»

I am the worst programmer in my family

I was just talking to my brother via messenger. He said he was going to a round-table discussion with Don Box and Chris Anderson today. Him and about 10 other people having a chat to those guys. This brought it into sharp relief for me. By the numbers I must be the worst programmer in my family. Patrick has been to Redmond for partner briefings with Microsoft, was on the Whidbey alpha program and is close to finishing his masters degree. Dominic has done an internship at MSR and is working towards his Ph.D. and they are both younger than me! Yikes.

Comments

JosephCooney
Worst Programmer Reloaded
12/03/2004 10:04:00 PM

»

SSCLI Rocks

I know there are lots of people that probably already know this, but if you’re a .NET developer you really should download and take a look at the SSCLI aka ROTOR. The SSCLI is not just for CLR wonks to play around with. Although it does have a full CLR implementation the parts that interest me the most is the full source to some of the system base classes that are also included. Admittedly not all of the most commonly used namespaces are there, but some of my favourites like System.Xml, System.Text.RegularExpressions and System.CodeDom are in there. I can think of a number of cool little projects I’m going to undertake using this code. ROTOR is a great place to find examples of  “production quality” C# code, and even though tools like Reflector do a great job of reconstructing code from MSIL it is usually much easier to read the actual code it’s self.

Update: I just thought I would include some info on resources in the SSCLI. The SSCLI uses strongly typed resource files (where each resource string value is a property accessible via it’s key). Apparently this is the way of the future since resgen.exe in the .NET Framework 1.2 (a.k.a Whidbey) has been expanded to create these resource class files also. The Whidbey version of resgen.exe uses the CodeDOM (and can output any language that supports CodeDOM). SSCLI (since the Base Class Libraries are written in C#) uses a Perl script called gensr.pl to generate C# classes. If you want to recompile parts of the SSCLI with minimal pain you will need to generate these resource classes either using the Whidbey resgen.exe or the Perl script. I have used the resgen.exe approach and it outputs “drop-in replacements” for the Perl files.  I discovered this information here IIRR http://weblogs.asp.net/vga/archive/2003/12/26/45958.aspx

Something else that I should also mention about SSCLI\ROTOR is that Microsoft indicated at the PDC BOF that there would be a new SSCLI release forked off the Whidbey code base, released (hopefully) a short period of time after Whidbey is released. Joel Pobar has the details here. I think it is great to see Microsoft continue to support SSCLI going forward.

Comments

Dave Wanta
btw, I’ve indexed and linked the code over at
http://www.123aspx.com/rotor/default.aspx

Cheers!
Dave
26/01/2004 9:16:00 AM
None Given
Nope - I think it is much safer if you download the sources to Mono instead. At least then you would not have to agree to the SSCLI license terms which essentially ensure you cab never add anything to dotGNU or Mono projects.

I dunno - if you feel that interested in seeing the source for a CLI - why would you want to limit what you can do with your knowledge in the future?

27/01/2004 12:34:00 AM
JosephCooney
Hi Mr Given - I can’t help but take the bait now can I. how is MONO safer? I’ve read the SSCLI license and it seems quite reasonable. In a nutshell I can’t use the source code in commercial applications and if I modify the source the license that MS released the SSCLI under has to also apply to those modifications. The license also specificly states:

You may use any information in intangible form that you remember after
accessing the Software.


So I don’t think I am "giving up" a great deal.
I certainly think taking a look at the MONO source is a valuable thing, but the SSCLI BCL are very similar to Microsoft’s "production" BCL, and thus may be of more interest to .NET developers. For example if I’m writing a regular expression and want to see how it is parsed and run I can just change the namespaces in the SSCLI RegEx implementation, add it as a project and "step through" the source as it is parsed an evaluated.
27/01/2004 12:58:00 AM
Scoblized!
17/01/2005 3:33:00 AM

»

WSE & Web Services link interface

I’ve been trying to get into WebServices again lately. I implemented my first “production“ web service at the start to middle of 2002 - it even used DIME which was the “new thing” then. Since then I’ve only done one other application that used web services in a fairly cool (but trivial to implement) way. Now I’m trying to learn about WSE, prepare for indigo and prepare for certification exam 70-320 (the last one I need to pass to become an MCSD.NET). I borrowed Kieth Ballinger’s Web Services book off Dominic which was an easy read and had some good insights as well. I’ve also read a few interesting articles:

WS-Security Authentication and Digital Signitures (old WSE 1 stuff, still good)
Performance Considerations for Making Web Service Calls from ASPX Pages (hint - make them asynchronously …which leads nicely into)
Asynchronous Web Service Calls over HTTP with the .NET Framework

WSDL
An old (december 2002) but good article on Schema-First design by Yasser Shohoud
Inside WSDL with .NET Attribution (instead of designing your schema first learn what attributes you can use to shape it)
Response to the previous article by Christian Weyer showing some problems with the article’s code and WS-BP conformance.
Christian Weyer’s WsContractFirst VS.NET Add-in

Comments

Christian Weyer
Be sure to check out the Service Agent pattern for calling your services:
http://weblogs.asp.net/cweyer/archive/2004/01/10/49419.aspx
10/01/2004 12:30:00 AM
JosephCooney
Thanks Christian - Your blog is the mega-link-interface of cool web services stuff.
10/01/2004 7:33:00 PM

»

Should an O/R mapper also be a code generator? A code-gen fan answers

Steve Eichert asks should an O/R mapper be a code generator? and makes the assertion that it should not. I don’t know a great deal about O/R mappers, but I have spent some time thinking about the merits of design time vs. run-time code generation (and some of the same things apply here I think). There is a certain class of bugs that can be caught by compile time type checking that cannot be caught at compile time if you’re doing things “dynamically” (either dynamically generating assemblies with CodeDOM or Reflection.Emit, setting properties reflectively etc). Even casting can introduce bugs into your application that could be detected by compile time type checking. The less of it you have to do the better. Another advantage of generated code is that it is usually easier to step through and debug vs. slightly more esoteric reflection code (and WAAAY easier to understand + debug than assemblies created with CodeDOM or Reflection.Emit on the fly). Reflection is also slow (the number 50 is popping into my head as in 50x slower, but I can’t find a URL to back that up right now).

Altho Frans seems a little “tense” in some of his comments I agree with a lot of what he is saying. The only time I ever look at generated code is if I’m using a codegen tool for the first time and want to get a feel for what sort of output it produces (or if there is a bug in a generator). Like Frans I also have no problem with verbose generated code - if it could be elegantly written in 5 lines (and handle all cases) then I would hardly write a generator for it. Code generation is just one re-use technique that can be used when other types of re-use (like encapsulation or inheritance) cannot be used. Also I am firmly of the opinion that generated code should never be edited. Inherit from generated code, build in extensibility points into your generated code, but don’t edit it.

I noticed in some of the comments in this post asking about methods for creating assemblies on the fly. The main ways of doing this in .NET that I know of are Reflection.Emit, creating a CodeDOM object graph and passing it to a class that implements ICodeCompiler, or building a string on the fly and passing it to an ICodeGenerator. My brother Dominic has some nice demos of Reflection.Emit in action from a talk he did at the local users group about 6 months ago. CodeDOM is one of the more mind-bending APIs in .NET, and has a number of limitations, and can result in some fairly verbose generator code, but you can produce useful things with it.

As always YMMV, not available at all stores, may contain traces of nut, contents may have settled during shipping etc.

Comments

Steve
I think you’ve hit on one of the main advantages of code generation vs. creating dynamic assemblies at runtime. Debuging dynamically generated assemblies can be a major pain in the butt.


I also agree that if your using a code generator you shouldn’t touch the code, since if you start editing it, you can’t re-run the generator without losing some of the work you’ve done.


With that said, I still prefer runtime generation of dynamic assemblies over code generation. I wonder if there’s a way around the debugging limitations? Also, I think having a configuration flag that tells the O/R framework to output the code it generates is a good idea, similar to what you can do with the XmlSerializer.
2/01/2004 4:08:00 AM
JosephCooney
Re: Debugging dynamic assemblies - I agree the ability to optionally output source code as well as a compiled assembly is definitely a step in the right direction (altho maybe if you’re really familiar with reading IL it wouldn’t make too much of a difference - I know my brother Dominic is fairly fluent). The big advantange of CodeDOM is the ability to produce code in different languages - if that is not an important feature then string building is definitely much easier. There are no guarantees with a CodeDOM object graph that you will produce "valid" code or anything.

Dynamic code generation is obviously alluring - since everything is always being regenerated it is always all "in synch". There is the startup performance hit (like ASP.NET, XmlSerializer etc), and it does feel more fragile to me, but it certainly has interested me in the past. It will be interesting to see where your O/R mapper ends up.
2/01/2004 6:04:00 AM
Kenny
I guess custom hooks in generated code (such as in Alachisoft’s TierDeveloper) justifies code "in" the generated layer?
1/06/2004 5:16:00 PM
JosephCooney
I don’t think you have to generate an entire tier. I think custom written code (either hooks into helper classes or subclassing) is a good way to handle "edge cases".
1/06/2004 5:35:00 PM

»

[old news] - Reflector decomplies to Delphi.NET

This is probably old news, but I just noticed that the latest version of reflector (3.4.5.0) which I just downloaded can now decompile to Delphi as well as VB.NET and C#. I know almost no Delphi (so I can’t say how correct the decompiled code looks) but I know of a few people who would be interested in this. Reflector is my favourite .NET tool. »

System.Drawing and Dispose()

I was playing around a bit with some owner drawn controls in winforms a little while ago (in preparation for the winforms exam, and just to see what it was all about). I was pleased to see that owner drawing was not that hard, however I did notice that there are lots of classes in the System.Drawing namespace that need to be disposed to free up the underlying system resources. That is fine, I have no problem calling dispose every now and then, however I came across this weblog entry a couple of days ago that scared me a little http://www. »

Exam 70-316

I passed exam 70-316 (windows forms with C# and VS.NET) today with a score of 929. When I told my mate Darren that I was doing that exam his reaction was “Windows Forms…you may as well be doing an exam on VB4”. Thanks Darren, that really helps me stay motivated. Once I’ve done 70-320 I’ll be an MCSD.NET. Looks like I’d better start reading up on remoting before that becomes obsolete too. To prepare for the exam I read most of the windows forms FAQ over at SyncFusion. »