开发者

What is the best way to aggregate a library of windows forms utilities?

开发者 https://www.devze.com 2023-02-19 07:03 出处:网络
I am writing a number of windows forms that requir开发者_StackOverflow中文版e shared functionality.

I am writing a number of windows forms that requir开发者_StackOverflow中文版e shared functionality. For example, I want to use the following font-resizing utility in several forms:

static public Font ChangeFontSize( Font font, float fontSize )
{
   if (font != null)
   {
       float currentSize = font.Size;  
       if (currentSize != fontSize)  
       {
           font = new Font( font.Name, fontSize,
                            font.Style, font.Unit,
                            font.GdiCharSet, font.GdiVerticalFont );
       }
   }
   return font;
}

(taken from C# 441, http://www.csharp411.com/change-font-size/)

What is the best way to aggregate functions like this into a common library that can be shared between many forms? I started to put the into a C# class library, but of course these don't expose any drawing/UI functions.

Just so I am clear - I am not asking about the suitability of the above function, but the best way to aggregate such functions in a way they can be shared between many windows forms.

Thanks Andrew


There's nothing special about a class library. There certainly isn't any need to not include drawing or UI helper methods. The only possible speed bump is that the project template doesn't automatically include the assembly references that you'll need.

Project + Add Reference, pick at least System.Drawing and System.Windows.Forms.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号