/// <summary> /// Get properties from selected objects and fill GraphicsProperties instance /// </summary> /// <returns></returns> private GraphicsProperties GetProperties() { GraphicsProperties properties = new GraphicsProperties(); int n = SelectionCount; if (n < 1) { return(properties); } DrawObject o = GetSelectedObject(0); int firstColor = o.Color.ToArgb(); int firstPenWidth = o.PenWidth; bool allColorsAreEqual = true; bool allWidthAreEqual = true; for (int i = 1; i < n; i++) { if (GetSelectedObject(i).Color.ToArgb() != firstColor) { allColorsAreEqual = false; } if (GetSelectedObject(i).PenWidth != firstPenWidth) { allWidthAreEqual = false; } } if (allColorsAreEqual) { properties.ColorDefined = true; properties.Color = Color.FromArgb(firstColor); } if (allWidthAreEqual) { properties.PenWidthDefined = true; properties.PenWidth = firstPenWidth; } return(properties); }
/// <summary> /// Apply properties for all selected objects //替换所有物件的笔宽和颜色 /// </summary> private void ApplyProperties(GraphicsProperties properties) { foreach (DrawObject o in graphicsList) { if (o.Selected) { if (properties.ColorDefined) { o.Color = properties.Color; DrawObject.LastUsedColor = properties.Color; } if (properties.PenWidthDefined) { o.PenWidth = properties.PenWidth; DrawObject.LastUsedPenWidth = properties.PenWidth; } } } }