public FormControl(byte[] b) { using (var st = new MemoryStream(b)) using (var r = new FrxReader(st)) { MinorVersion = r.ReadByte(); MajorVersion = r.ReadByte(); var cbForm = r.ReadUInt16(); PropMask = new FormPropMask(r.ReadUInt32()); // DataBlock BackColor = PropMask.HasBackColor ? r.ReadOleColor() : null; ForeColor = PropMask.HasForeColor ? r.ReadOleColor() : null; NextAvailableId = PropMask.HasNextAvailableId ? r.ReadUInt32() : 0; BooleanProperties = new FormFlags(PropMask.HasBooleanProperties ? r.ReadUInt32() : 0); BorderStyle = PropMask.HasBorderStyle ? r.ReadBorderStyle() : BorderStyle.None; MousePointer = PropMask.HasMousePointer ? r.ReadMousePointer() : MousePointer.Default; ScrollBars = new FormScrollBarFlags(PropMask.HasScrollBars ? r.ReadByte() : (byte)0); GroupCount = PropMask.HasGroupCount ? r.ReadInt32() : 0; // captionCcb is possibly here instead of where it's indicated in [MS-OFORMS]? if (PropMask.HasMouseIcon) { r.Skip2Bytes(); } Cycle = PropMask.HasCycle ? r.ReadCycle() : Cycle.AllForms; SpecialEffect = PropMask.HasSpecialEffect ? r.ReadSpecialEffect() : SpecialEffect.Flat; BorderColor = PropMask.HasBorderColor ? r.ReadOleColor() : null; var captionCcb = PropMask.HasCaption ? r.ReadCcb() : Tuple.Create(0, false); if (PropMask.HasFont) { r.Skip2Bytes(); } if (PropMask.HasPicture) { r.Skip2Bytes(); } Zoom = PropMask.HasZoom ? r.ReadUInt32() : 0; PictureAlignment = PropMask.HasPictureAlignment ? r.ReadPictureAlignment() : PictureAlignment.TopLeft; PictureSizeMode = PropMask.HasPictureSizeMode ? r.ReadPictureSizeMode() : PictureSizeMode.Clip; ShapeCookie = PropMask.HasShapeCookie ? r.ReadUInt32() : 0; DrawBuffer = PropMask.HasDrawBuffer ? r.ReadUInt32() : 0; // ExtraDataBlock DisplayedSize = PropMask.HasDisplayedSize ? r.ReadCoords() : Tuple.Create(0, 0); LogicalSize = PropMask.HasLogicalSize ? r.ReadCoords() : Tuple.Create(0, 0); ScrollPosition = PropMask.HasScrollPosition ? r.ReadCoords() : Tuple.Create(0, 0); Caption = r.ReadStringFromCcb(captionCcb); r.AlignTo(4); if (cbForm != r.BaseStream.Position - 4) { throw new ApplicationException(string.Format(VBASyncResources.ErrorFrxStreamSizeMismatch, "f", "cbForm", r.BaseStream.Position - 4, cbForm)); } // StreamData MouseIcon = PropMask.HasMouseIcon ? r.ReadGuidAndPicture() : new byte[0]; if (PropMask.HasFont) { FontIsStdFont = r.GetFontIsStdFont(); if (FontIsStdFont) { FontStdFont = r.ReadStdFont(); } else { FontTextProps = r.ReadTextProps(); } } Picture = PropMask.HasPicture ? r.ReadGuidAndPicture() : new byte[0]; // FormSiteData SiteClassInfos = new List <byte[]>(); ushort siteClassInfoCount = 0; if (!PropMask.HasBooleanProperties || BooleanProperties.ClassTablePersisted) { siteClassInfoCount = r.Unaligned.ReadUInt16(); } for (var i = 0; i < siteClassInfoCount; i++) { st.Seek(2, SeekOrigin.Current); // skip Version SiteClassInfos.Add(r.Unaligned.ReadBytes(r.Unaligned.ReadUInt16())); } var siteCount = r.Unaligned.ReadUInt32(); var cbSites = r.Unaligned.ReadUInt32(); var sitesStartPos = r.BaseStream.Position; var depths = new byte[siteCount]; var types = new byte[siteCount]; var siteDepthsLeft = siteCount; while (siteDepthsLeft > 0) { var thisDepth = r.Unaligned.ReadByte(); var thisType = r.Unaligned.ReadByte(); var thisCount = (byte)1; if ((thisType & 0x80) == 0x80) { thisCount = (byte)(thisType ^ 0x80); thisType = r.Unaligned.ReadByte(); } for (var i = 0; i < thisCount; i++) { var siteIdx = siteCount - siteDepthsLeft; depths[siteIdx] = thisDepth; types[siteIdx] = thisType; siteDepthsLeft--; } } var rem = (r.BaseStream.Position - sitesStartPos) % 4; if (rem != 0) { r.BaseStream.Seek(4 - rem, SeekOrigin.Current); // add ArrayPadding } Sites = new OleSiteConcreteControl[siteCount]; for (var i = 0; i < siteCount; i++) { r.BaseStream.Seek(2, SeekOrigin.Current); // ignore Version var cbSite = r.Unaligned.ReadUInt16(); Sites[i] = new OleSiteConcreteControl(r.Unaligned.ReadBytes(cbSite)); } if (cbSites != r.BaseStream.Position - sitesStartPos) { throw new ApplicationException(string.Format(VBASyncResources.ErrorFrxStreamSizeMismatch, "f", "cbSites", r.BaseStream.Position - sitesStartPos, cbSites)); } Remainder = st.Position < st.Length ? r.Unaligned.ReadBytes((int)(st.Length - st.Position)) : new byte[0]; } }