问题
I have the following code
System.Drawing.Image logo = ... (getting logo)
WorksheetImage worksheetImage = new WorksheetImage(logo);
worksheetImage.PositioningMode = ShapePositioningMode.DontMoveOrSizeWithCells;
// Original code (works with Infragistics 13.1)
Rectangle imageRect = new Rectangle(100, 100, 10 * logo.Width, 10 * logo.Height);
worksheetImage.SetBoundsInTwips(worksheet, imageRect, true); // Breaks here
The following code works with Infragistics 13.1 library. However, when migrating to 15.2, compiler spits out an error:
The best overloaded method match for 'Infragistics.Documents.Excel.WorksheetImage.SetBoundsInTwips(Infragistics.Documents.Excel.Worksheet, System.Windows.Rect, bool)' has some invalid arguments
Argument 2: cannot convert from 'System.Drawing.Rectangle' to 'System.Windows.Rect'
So basically it says that the second argument should be of type System.Windows.Rect and not System.Drawing.Rectangle. The information here indicates that the type I am passing in is correct, but compiler disagrees. Why is that the case?
回答1:
The Infragistics WindowsForms Excel engine's SetBoundsInTwips method indeed uses System.Drawing.Rect as one of its parameters. However the WPF implementation uses System.Windows.Rect. If this call doesn't compile then you are probably using the WPF library. Please check the references of your project and see if they use the WPF Assembly (InfragisticsWPF4.Documents.Excel.v15.2) and substitute it with the WF one (Infragistics4.Documents.Excel.v15.2).
回答2:
So the issue has been resolved - apparently the method SetBoundsInTwips in WPF in Infragistics 15.2 takes Rect as oppose to Rectangle in 13.1, so changing Rectangle to Rect did the job.
来源:https://stackoverflow.com/questions/34143214/infragistics-15-2-worksheetimage-setboundsintwips-compilation-error