protected override void OnHandleCreated(EventArgs e) { base.OnHandleCreated(e); if (IsHandleCreated && imageList != null) { NativeMethods.REBARINFO rebarINFO = new NativeMethods.REBARINFO(); rebarINFO.cbSize = Marshal.SizeOf(typeof(NativeMethods.REBARINFO)); rebarINFO.fMask |= NativeMethods.RBIM_IMAGELIST; rebarINFO.himl = imageList.Handle; UnsafeNativeMethods.SendMessage(new HandleRef(this, Handle), NativeMethods.RB_SETBARINFO, 0, ref rebarINFO); } int count = bandsCount; if (bands != null && IsHandleCreated) { for (int i = 0; i < count; i++) { NativeMethods.REBARBANDINFO bandINFO = bands[i].GetREBARBANDINFO(i); if (Marshal.SystemDefaultCharSize == 1) { UnsafeNativeMethods.SendMessage(new HandleRef(this, Handle), NativeMethods.RB_INSERTBANDA, i, ref bandINFO); UnsafeNativeMethods.SendMessage(new HandleRef(this, Handle), NativeMethods.RB_SETBANDINFOA, i, ref bandINFO); } else { UnsafeNativeMethods.SendMessage(new HandleRef(this, Handle), NativeMethods.RB_INSERTBANDW, i, ref bandINFO); UnsafeNativeMethods.SendMessage(new HandleRef(this, Handle), NativeMethods.RB_SETBANDINFOW, i, ref bandINFO); } } UnsafeNativeMethods.UpdateWindow(Handle); } }
public void UpdateRebarBand(RebarBand value, int index) { if (IsHandleCreated) { BeginUpdate(); if (Marshal.SystemDefaultCharSize == 1) { NativeMethods.REBARBANDINFO bandINFO = value.GetREBARBANDINFO(index); UnsafeNativeMethods.SendMessage(new HandleRef(this, Handle), NativeMethods.RB_SETBANDINFOA, index, ref bandINFO); } else { NativeMethods.REBARBANDINFO bandINFO = value.GetREBARBANDINFO(index); UnsafeNativeMethods.SendMessage(new HandleRef(this, Handle), NativeMethods.RB_SETBANDINFOW, index, ref bandINFO); } EndUpdate(); } }
private void Update(int mask) { if (Marshal.SystemDefaultCharSize == 1) { if (owner != null && owner.IsHandleCreated) { int index = FindIndex(this); NativeMethods.REBARBANDINFO bandINFO = GetREBARBANDINFO(index); bandINFO.fMask = mask; UnsafeNativeMethods.SendMessage(new HandleRef(owner, owner.Handle), NativeMethods.RB_SETBANDINFOA, index, ref bandINFO); } } else { if (owner != null && owner.IsHandleCreated) { int index = FindIndex(this); NativeMethods.REBARBANDINFO bandINFO = GetREBARBANDINFO(index); bandINFO.fMask = mask; UnsafeNativeMethods.SendMessage(new HandleRef(owner, owner.Handle), NativeMethods.RB_SETBANDINFOW, index, ref bandINFO); } } }
private NativeMethods.REBARBANDINFO GetBandInfo(int index) { CommandBar commandBar = this.commandBars[index]; NativeMethods.REBARBANDINFO bandInfo = new NativeMethods.REBARBANDINFO(); bandInfo.cbSize = Marshal.SizeOf(typeof(NativeMethods.REBARBANDINFO)); bandInfo.fMask = 0; bandInfo.clrFore = 0; bandInfo.clrBack = 0; bandInfo.iImage = 0; bandInfo.hbmBack = IntPtr.Zero; bandInfo.lParam = 0; bandInfo.cxHeader = 0; bandInfo.fMask |= NativeMethods.RBBIM_ID; bandInfo.wID = 0xEB00 + index; if ((commandBar.Text != null) && (commandBar.Text.Length != 0)) { bandInfo.fMask |= NativeMethods.RBBIM_TEXT; bandInfo.lpText = Marshal.StringToHGlobalUni(commandBar.Text); bandInfo.cch = (commandBar.Text == null) ? 0 : commandBar.Text.Length; } bandInfo.fMask |= NativeMethods.RBBIM_STYLE; bandInfo.fStyle = NativeMethods.RBBS_CHILDEDGE | NativeMethods.RBBS_FIXEDBMP | NativeMethods.RBBS_GRIPPERALWAYS; bandInfo.fStyle |= NativeMethods.RBBS_BREAK; bandInfo.fStyle |= NativeMethods.RBBS_USECHEVRON; bandInfo.fMask |= NativeMethods.RBBIM_CHILD; bandInfo.hwndChild = commandBar.Handle; bandInfo.fMask |= NativeMethods.RBBIM_CHILDSIZE; bandInfo.cyMinChild = commandBar.Height; bandInfo.cxMinChild = 0; bandInfo.cyChild = 0; bandInfo.cyMaxChild = 0; bandInfo.cyIntegral = 0; bandInfo.fMask |= NativeMethods.RBBIM_SIZE; bandInfo.cx = commandBar.Width; bandInfo.fMask |= NativeMethods.RBBIM_IDEALSIZE; bandInfo.cxIdeal = commandBar.Width; return bandInfo; }
private NativeMethods.REBARBANDINFO CreateBandInfo(int index) { CommandBar commandBar = this.commandBars[index]; NativeMethods.REBARBANDINFO rbbi = new NativeMethods.REBARBANDINFO(); rbbi.cbSize = Marshal.SizeOf(typeof(NativeMethods.REBARBANDINFO)); rbbi.fMask = 0; rbbi.clrFore = 0; rbbi.clrBack = 0; rbbi.iImage = 0; rbbi.hbmBack = IntPtr.Zero; rbbi.lParam = 0; rbbi.cxHeader = 0; rbbi.fMask |= NativeMethods.RBBIM_ID; rbbi.wID = 0xEB00 + index; if ((commandBar.Text != null) && (commandBar.Text.Length != 0)) { rbbi.fMask |= NativeMethods.RBBIM_TEXT; rbbi.lpText = Marshal.StringToHGlobalUni(commandBar.Text); rbbi.cch = (commandBar.Text == null) ? 0 : commandBar.Text.Length; } int pad = 0; foreach (CommandBarItem item in commandBar.Items) { if ( item is CommandBarSeparator) pad += 2; } rbbi.fMask |= NativeMethods.RBBIM_STYLE; rbbi.fStyle = NativeMethods.RBBS_CHILDEDGE | NativeMethods.RBBS_FIXEDBMP | NativeMethods.RBBS_GRIPPERALWAYS; if (commandBar.NewLine == true) rbbi.fStyle |= NativeMethods.RBBS_BREAK; if (commandBar.UseChevron == true) rbbi.fStyle |= NativeMethods.RBBS_USECHEVRON; rbbi.fMask |= NativeMethods.RBBIM_CHILD; rbbi.hwndChild = commandBar.Handle; rbbi.fMask |= NativeMethods.RBBIM_CHILDSIZE; rbbi.cyMinChild = commandBar.Height; rbbi.cxMinChild = 0; //commandBar.Width; rbbi.cyChild = 0; rbbi.cyMaxChild = commandBar.Height; rbbi.cyIntegral = commandBar.Height; rbbi.fMask |= NativeMethods.RBBIM_SIZE; rbbi.cx = commandBar.Width + pad + 14; rbbi.fMask |= NativeMethods.RBBIM_IDEALSIZE; rbbi.cxIdeal = commandBar.Width + pad + 14; return rbbi; }
private void UpdateBand(CommandBar commandBar) { if (this.IsHandleCreated) { this.BeginUpdate(); for (int i = 0; i < this.commandBars.Count; i++) { NativeMethods.REBARBANDINFO rbbi = new NativeMethods.REBARBANDINFO(); rbbi.cbSize = Marshal.SizeOf(typeof(NativeMethods.REBARBANDINFO)); rbbi.fMask = NativeMethods.RBBIM_STYLE | NativeMethods.RBBIM_ID | NativeMethods.RBBIM_TEXT | NativeMethods.RBBIM_STYLE | NativeMethods.RBBIM_CHILD | NativeMethods.RBBIM_SIZE | NativeMethods.RBBIM_CHILDSIZE | NativeMethods.RBBIM_IDEALSIZE; NativeMethods.SendMessage(this.Handle, NativeMethods.RB_GETBANDINFO, i, ref rbbi); if (commandBar.Handle == rbbi.hwndChild) { if ((rbbi.cyMinChild != commandBar.Height) || (rbbi.cx != commandBar.Width) || (rbbi.cxIdeal != commandBar.Width)) { rbbi.cyMinChild = commandBar.Height; rbbi.cx = commandBar.Width; rbbi.cxIdeal = commandBar.Width; NativeMethods.SendMessage(this.Handle, NativeMethods.RB_SETBANDINFO, i, ref rbbi); } } } this.UpdateSize(); this.EndUpdate(); } }
internal NativeMethods.REBARBANDINFO BuildBandInfo() { NativeMethods.REBARBANDINFO info = new NativeMethods.REBARBANDINFO { cbSize = Marshal.SizeOf(typeof(NativeMethods.REBARBANDINFO)) }; if (!string.IsNullOrEmpty(Text)) { info.fMask |= NativeMethods.RBBIM_TEXT; info.lpText = Text; } if (GripStyle != RebarGripStyle.Auto || !Visible || !AcceptVertical || UseChevron || TopAlign) { info.fMask |= NativeMethods.RBBIM_STYLE; } if (!MinimumChildSize.IsEmpty || MaximumChildHeight != -1 || ChildHeight != -1 || IntegralHeight != -1) { info.fMask |= NativeMethods.RBBIM_CHILDSIZE; } if (UseBackAndFore) { info.fMask |= NativeMethods.RBBIM_COLORS; info.clrBack = ColorTranslator.ToWin32(BackColor); info.clrFore = ColorTranslator.ToWin32(ForeColor); } if (BackgroundImage != null) { info.fMask |= NativeMethods.RBBIM_BACKGROUND; info.hbmBack = new Bitmap(BackgroundImage).GetHbitmap(); } if (!ChevronLocation.IsEmpty) { info.fMask |= NativeMethods.RBBIM_CHEVRONLOCATION; info.rcChevronLocation = new NativeMethods.RECT(new Rectangle(ChevronLocation, Size.Empty)); } if (Child != null && parent != null) { prevParent = Child.Parent; Child.Parent = parent; info.fMask |= NativeMethods.RBBIM_CHILD; info.hwndChild = Child.Handle; } if (MinimumChildSize.Width != 0) { info.cxMinChild = MinimumChildSize.Width; } if (MinimumChildSize.Height != 0) { info.cyMinChild = MinimumChildSize.Height; } if (ChildHeight != -1) { info.cyChild = ChildHeight; } if (MaximumChildHeight != -1) { info.cyMaxChild = MaximumChildHeight; } if (IntegralHeight != -1) { info.cyIntegral = IntegralHeight; } if (HeaderWidth != -1) { info.fMask |= NativeMethods.RBBIM_HEADERSIZE; info.cxHeader = HeaderWidth; } if (IdealWidth != -1) { info.fMask |= NativeMethods.RBBIM_IDEALSIZE; info.cxIdeal = IdealWidth; } if (Tag != null) { GCHandle handle = GCHandle.Alloc(Tag); info.fMask |= NativeMethods.RBBIM_LPARAM; info.lParam = (IntPtr)handle; handle.Free(); } if (GripStyle == RebarGripStyle.Hidden) { info.fStyle |= NativeMethods.RBBS_NOGRIPPER; } else if (GripStyle == RebarGripStyle.Visible) { info.fStyle |= NativeMethods.RBBS_GRIPPERALWAYS; } if (!Visible) { info.fStyle |= NativeMethods.RBBS_HIDDEN; } if (!AcceptVertical) { info.fStyle |= NativeMethods.RBBS_NOVERT; } if (!TitleVisible) { info.fStyle |= NativeMethods.RBBS_HIDETITLE; } if (UseChevron) { info.fStyle |= NativeMethods.RBBS_USECHEVRON; } if (TopAlign) { info.fStyle |= NativeMethods.RBBS_TOPALIGN; } if (FixedSize) { info.fStyle |= NativeMethods.RBBS_FIXEDSIZE; } if (Break) { info.fStyle |= NativeMethods.RBBS_BREAK; } if (VariantHeight) { info.fStyle |= NativeMethods.RBBS_VARIABLEHEIGHT; } if (parent.ImageList != null) { if (ImageIndex != -1 && parent.ImageList.Images[ImageIndex] != null) { info.fMask |= NativeMethods.RBBIM_IMAGE; info.iImage = ImageIndex; } else if (ImageKey != null && parent.ImageList.Images.IndexOfKey(ImageKey) != -1 && parent != null) { info.fMask |= NativeMethods.RBBIM_IMAGE; info.iImage = parent.ImageList.Images.IndexOfKey(ImageKey); } } if (_Width != -1) { info.fMask |= NativeMethods.RBBIM_SIZE; info.cx = Width; } return(info); }
public NativeMethods.REBARBANDINFO GetREBARBANDINFO(int index) { NativeMethods.REBARBANDINFO bandINFO = new NativeMethods.REBARBANDINFO(); bandINFO.cbSize = Marshal.SizeOf(typeof(NativeMethods.REBARBANDINFO)); bandINFO.fMask = NativeMethods.RBBIM_STYLE | NativeMethods.RBBIM_ID; if ((bandStyle & TRBBStyle.Break) != 0) { bandINFO.fStyle |= NativeMethods.RBBS_BREAK; } if ((bandStyle & TRBBStyle.ChildEdge) != 0) { bandINFO.fStyle |= NativeMethods.RBBS_CHILDEDGE; } if ((bandStyle & TRBBStyle.FixedBitmap) != 0) { bandINFO.fStyle |= NativeMethods.RBBS_FIXEDBMP; } if ((bandStyle & TRBBStyle.FixedSize) != 0) { bandINFO.fStyle |= NativeMethods.RBBS_FIXEDSIZE; } if ((bandStyle & TRBBStyle.GripperAlways) != 0) { bandINFO.fStyle |= NativeMethods.RBBS_GRIPPERALWAYS; } if ((bandStyle & TRBBStyle.Hidden) != 0) { bandINFO.fStyle |= NativeMethods.RBBS_HIDDEN; } if ((bandStyle & TRBBStyle.VariableHeight) != 0) { bandINFO.fStyle |= NativeMethods.RBBS_VARIABLEHEIGHT; } if ((bandStyle & TRBBStyle.UseChevron) != 0) { bandINFO.fStyle |= NativeMethods.RBBS_USECHEVRON; } if ((bandStyle & TRBBStyle.NoGripper) != 0) { bandINFO.fStyle |= NativeMethods.RBBS_NOGRIPPER; } bandINFO.wID = index; if (!string.IsNullOrEmpty(text)) { bandINFO.fMask |= NativeMethods.RBBIM_TEXT; bandINFO.lpText = Marshal.StringToHGlobalAuto(text); bandINFO.cch = text.Length; } if (imageIndex != -1) { bandINFO.fMask |= NativeMethods.RBBIM_IMAGE; bandINFO.iImage = imageIndex; } if (backgroundColor != Color.Empty) { bandINFO.fMask |= NativeMethods.RBBIM_COLORS; bandINFO.clrBack = NativeMethods.RGB(backgroundColor.R, backgroundColor.G, backgroundColor.B); } if (textgroundColor != Color.Empty) { bandINFO.fMask |= NativeMethods.RBBIM_COLORS; bandINFO.clrFore = NativeMethods.RGB(textgroundColor.R, textgroundColor.G, textgroundColor.B); } if (control != null) { childWidth = control.Width; bandINFO.fMask |= NativeMethods.RBBIM_CHILD; bandINFO.hwndChild = control.Handle; if (childWidth != -1) { bandINFO.fMask |= NativeMethods.RBBIM_CHILDSIZE; bandINFO.cxMinChild = control.Width; bandINFO.cyMinChild = control.Height; if ((bandStyle & TRBBStyle.VariableHeight) != 0) { bandINFO.cyChild = control.Width; bandINFO.cyMaxChild = control.Height; bandINFO.cyIntegral = 1; } } if (control is MenuBox || control is ToolBox) { NativeMethods.SIZE size = new NativeMethods.SIZE(); UnsafeNativeMethods.SendMessage(new HandleRef(control, control.Handle), NativeMethods.TB_GETMAXSIZE, IntPtr.Zero, size); bandINFO.fMask |= NativeMethods.RBBIM_IDEALSIZE; bandINFO.cxIdeal = size.cx; idealWidth = size.cx; } } if (headerWidth != -1) { bandINFO.fMask |= NativeMethods.RBBIM_HEADERSIZE; bandINFO.cxHeader = headerWidth; } if (hbmBack != IntPtr.Zero) { bandINFO.fMask |= NativeMethods.RBBIM_BACKGROUND; bandINFO.hbmBack = hbmBack; } if (width != -1) { bandINFO.fMask |= NativeMethods.RBBIM_SIZE; bandINFO.cx = width; } return(bandINFO); }