private void UpdateBand(int index) { if (this.IsHandleCreated) { this.BeginUpdate(); NativeMethods.REBARBANDINFO rbbi = this.GetBandInfo(index); NativeMethods.SendMessage(this.Handle, NativeMethods.RB_SETBANDINFO, index, ref rbbi); this.UpdateSize(); this.EndUpdate(); } }
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); }
protected override void OnHandleCreated(EventArgs e) { base.OnHandleCreated(e); this.ReleaseBands(); this.BeginUpdate(); for (int i = 0; i < this.commandBars.Count; i++) { NativeMethods.REBARBANDINFO bandInfo = this.GetBandInfo(i); NativeMethods.SendMessage(this.Handle, NativeMethods.RB_INSERTBAND, i, ref bandInfo); } this.UpdateSize(); this.EndUpdate(); this.CaptureBands(); }