求赐教 3.5框架下的类怎么改成2.0框架下的

csuftliang 2012-03-10 01:18:25
如题,求大侠赐教,主要用了扩展方法,2.0不支持啊

public static class Helper {
public static void Offset(this RectangleF source, int x, int y) { source.X += x; source.Y += y; }


public static Bitmap GetSS(this Graphics grx, Rectangle bounds) {
var res = new Bitmap(bounds.Width, bounds.Height);
var gxc = Graphics.FromImage(res);
IntPtr hdc = grx.GetHdc();
PlatformAPI.BitBlt(gxc.GetHdc(), 0, 0, bounds.Width, bounds.Height, hdc, bounds.Left, bounds.Top, PlatformAPI.SRCCOPY);
grx.ReleaseHdc(hdc);
return res;
}

public static Bitmap Clip(this Bitmap source, Rectangle bounds) {
var grx = Graphics.FromImage(source);
return grx.GetSS(bounds);
}


public static Color BackgroundImageColor(this Bitmap bmp) {
return bmp.GetPixel(0, 0);
}


public static Bitmap GetBitmap(string name) {
Bitmap bmp = null;
var asm = Assembly.GetExecutingAssembly();
var resNames = asm.GetManifestResourceNames();
foreach (string s in resNames) {
if (s.IndexOf(name) > 0) {
using (var imgStream = asm.GetManifestResourceStream(s)) {
if (!(null == imgStream)) {
bmp = new Bitmap(imgStream);
if (!(null == bmp)) {
return bmp;
}
bmp = null;
imgStream.Close();
}
}
}
}
return null;
}
}

public static class Brushes {
public static Brush White { get { return new SolidBrush(Color.White); } }
public static Brush ControlDark { get { return new SolidBrush(SystemColors.ControlDark); } }
}



[StructLayout(LayoutKind.Sequential)]
internal struct Rect {
public int Left, Top, Right, Bottom;
public static implicit operator Rectangle(Rect value) {
return new Rectangle(value.Left, value.Top, value.Right - value.Left, value.Bottom - value.Top);
}

public static implicit operator Rect(Rectangle value) {
return new Rect() { Top = value.Top, Left = value.Left, Bottom = value.Bottom, Right = value.Right };
}
}

[StructLayout(LayoutKind.Sequential)]
internal struct POINT {
public int X;
public int Y;

public POINT(int x, int y) {
this.X = x;
this.Y = y;
}

public static implicit operator System.Drawing.Point(POINT p) {
return new System.Drawing.Point(p.X, p.Y);
}

public static implicit operator POINT(System.Drawing.Point p) {
return new POINT(p.X, p.Y);
}
}


internal class PlatformAPI {
[DllImport("coredll.dll")]
public static extern int DrawText(IntPtr hDC, string lpString, int nCount, ref Rect lpRect, uint uFormat);

[DllImport("coredll.dll")]
public static extern IntPtr CreateCompatibleDC(IntPtr hDC);

[DllImport("coredll.dll")]
public static extern int BitBlt(IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, uint dwRop);

public const uint SRCCOPY = 0x00CC0020;
}
...全文
73 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
threenewbee 2012-03-10
  • 打赏
  • 举报
回复
除非你还在用Windows 2000,否则没有必要退回到.NET 2.0。
xonln 2012-03-10
  • 打赏
  • 举报
回复
由于NET2.0很普及,性能一般,给你一个方法,转到2.0的方法
一.把Sin文件的如4.0.0.0的所有替换.还有一个Microsoft Visual Studio Solution File, Format Version 8.00,还有一个# Visual Studio 2010改一个...这些用计事本改吧
二.还有一个csproj文件,Project ToolsVersion="4.0" DefaultTargets="Build" 改为2.0
还有一个$(MSBuildToolsPath)...改为$(MSBuildBinPath)
三.整个解决方安的文件里的如4.0.0.0替换为2.0.0.0,大量一点换,没有关系,这时用Vs2005就能打开了
四.一些不是C#2.0的语法,改一下,一个一个地改,
OK........
faoyy 2012-03-10
  • 打赏
  • 举报
回复
2.0不支持扩展方法
  • 打赏
  • 举报
回复
如果只是扩展方法,那么你就把this这个词删掉,然后把所有出错的地方改为直接调用 Helper.XXXX() 这类就行了呗。

不过更好的办法是问一问负责维护服务器的人:今年都那一年了,还守着7年前的系统也不升级更新,难道连老系统的bug都不想借着升级而修复吗?

110,535

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧