/// <summary> /// recalculate the position of the horizontal scrollbar /// </summary> protected virtual void RecalcHScrollBar() { if (horizontalScroll != null) { int l_WidthVScroll = 0; if (verticalScroll != null) { l_WidthVScroll = verticalScroll.Width; } horizontalScroll.Location = new Point(0, ClientRectangle.Height - horizontalScroll.Height); horizontalScroll.Width = ClientRectangle.Width - l_WidthVScroll; horizontalScroll.Minimum = 0; horizontalScroll.Maximum = customScrollArea.Width > 0 ? customScrollArea.Width : 0; horizontalScroll.LargeChange = Math.Max(5, ClientRectangle.Width - l_WidthVScroll); horizontalScroll.SmallChange = horizontalScroll.LargeChange / 5; if (horizontalScroll.Value > MaximumHScroll) { horizontalScroll.Value = MaximumHScroll; } horizontalScroll.BringToFront(); } }
/// <summary> /// recalculate the position of the horizontal scrollbar /// </summary> protected virtual void RecalcHScrollBar() { if (m_HScroll != null) { int l_WidthVScroll = 0; if (m_VScroll != null) { l_WidthVScroll = m_VScroll.Width; } m_HScroll.Location = new Point(0, ClientRectangle.Height - m_HScroll.Height); m_HScroll.Width = ClientRectangle.Width - l_WidthVScroll; m_HScroll.Minimum = 0; m_HScroll.Maximum = Math.Max(0, m_CustomScrollArea.Width); //Math.Max(0,m_CustomScrollArea.Width - ClientRectangle.Width) + m_VScroll.Width; m_HScroll.LargeChange = Math.Max(5, ClientRectangle.Width - l_WidthVScroll); m_HScroll.SmallChange = m_HScroll.LargeChange / 5; if (m_HScroll.Value > MaximumHScroll) { m_HScroll.Value = MaximumHScroll; } m_HScroll.BringToFront(); } }
private void hScrollBar_Scroll(object sender, ScrollEventArgs e) { if (e.Type == ScrollEventType.EndScroll) { // Offset pianoControl1.Left = pnlLeftPiano.Width - hScrollBar.Value; vPianoRollControl1.OffsetX = -hScrollBar.Value; pnlLeftPiano.BringToFront(); hScrollBar.BringToFront(); pnlRedPianoSep.BringToFront(); } }
//private Graphics canvasGraphics; /// <summary> /// Create component instance. /// </summary> public ReoGridControl() { SuspendLayout(); BackColor = Color.White; DoubleBuffered = true; TabStop = true; #region Scroll bars & panels hScrollBar = new HScrollBar() { Dock = DockStyle.Fill, SmallChange = Worksheet.InitDefaultColumnWidth, }; hScrollBar.Scroll += OnHorScroll; hScrollBar.MouseEnter += (sender, e) => Cursor = Cursors.Default; vScrollBar = new VScrollBar() { Dock = DockStyle.Right, SmallChange = Worksheet.InitDefaultRowHeight, }; vScrollBar.Scroll += OnVerScroll; vScrollBar.MouseEnter += (sender, e) => Cursor = Cursors.Default; vScrollBar.MouseEnter += (s, e) => this.Cursor = Cursors.Default; hScrollBar.MouseEnter += (s, e) => this.Cursor = Cursors.Default; this.Controls.Add(vScrollBar); Controls.Add(vScrollBar); hScrollBar.BringToFront(); #endregion // Scroll bars & panels #region Sheet tabs this.sheetTab = new WinForm.SheetTabControl(this) { Dock = DockStyle.Left, Width = 400, Height = 26, Position = SheetTabControlPosition.Bottom, //ForeColor = SystemColors.WindowText, //BorderColor = SystemColors.Highlight, //SelectedBackColor = Color.White, //SelectedTextColor = SystemColors.WindowText, }; this.sheetTab.MouseMove += (s, e) => this.Cursor = Cursors.Default; this.sheetTab.SplitterMoving += (s, e) => { if (this.sheetTab.Dock != DockStyle.Fill) { var p = this.bottomPanel.PointToClient(Cursor.Position); int newWidth = p.X - this.sheetTab.Left; if (newWidth < 50) { newWidth = 50; } this.sheetTab.Width = newWidth; } }; this.sheetTab.SheetListClick += (s, e) => { if (this.sheetListMenu == null) { this.sheetListMenu = new ContextMenuStrip(); this.sheetListMenu.Items.Clear(); foreach (var sheet in this.Worksheets) { var sheetMenuItem = new ToolStripMenuItem(sheet.Name) { Tag = sheet }; sheetMenuItem.Click += sheetMenuItem_Click; this.sheetListMenu.Items.Add(sheetMenuItem); } } var p = Cursor.Position; p.Y -= this.sheetListMenu.Height / 2; this.sheetListMenu.Show(p); }; this.sheetTab.TabMouseDown += (s, e) => { if (e.MouseButtons == unvell.ReoGrid.Interaction.MouseButtons.Right) { if (this.sheetContextMenu == null) { if (this.SheetTabContextMenuStrip != null) { this.sheetContextMenu = this.SheetTabContextMenuStrip; } else { this.sheetContextMenu = new ContextMenuStrip(); #region Add sheet context menu items var insertSheetMenu = new ToolStripMenuItem(LanguageResource.Menu_InsertSheet); insertSheetMenu.Click += (ss, ee) => { var sheet = this.CreateWorksheet(); if (sheet != null) { this.workbook.InsertWorksheet(this.sheetTab.SelectedIndex, sheet); this.CurrentWorksheet = sheet; } }; var deleteSheetMenu = new ToolStripMenuItem(LanguageResource.Menu_DeleteSheet); deleteSheetMenu.Click += (ss, ee) => { if (this.workbook.WorksheetCount > 1) { this.workbook.RemoveWorksheet(this.sheetTab.SelectedIndex); } }; var renameSheetMenu = new ToolStripMenuItem(LanguageResource.Menu_RenameSheet); renameSheetMenu.Click += (ss, ee) => { var index = this.sheetTab.SelectedIndex; if (index >= 0 && index < this.workbook.worksheets.Count) { var sheet = this.workbook.worksheets[this.sheetTab.SelectedIndex]; if (sheet != null) { using (var rsd = new unvell.ReoGrid.WinForm.RenameSheetDialog()) { var rect = this.sheetTab.GetItemBounds(this.sheetTab.SelectedIndex); var p = this.sheetTab.PointToScreen(rect.Location); p.X -= (rsd.Width - rect.Width) / 2; p.Y -= rsd.Height + 5; rsd.Location = p; rsd.SheetName = sheet.Name; if (rsd.ShowDialog() == DialogResult.OK) { sheet.Name = rsd.SheetName; } } } } }; this.sheetContextMenu.Items.Add(insertSheetMenu); this.sheetContextMenu.Items.Add(deleteSheetMenu); this.sheetContextMenu.Items.Add(renameSheetMenu); #endregion // Add sheet context menu items } } this.sheetContextMenu.Show(this.sheetTab, e.Location); } }; #endregion // Sheet tabs #region Bottom Panel this.bottomPanel = new Panel { Dock = DockStyle.Bottom, Height = this.hScrollBar.Height, BackColor = SystemColors.Control, }; this.bottomPanel.Controls.Add(this.hScrollBar); this.bottomPanel.Controls.Add(this.sheetTab); this.bottomPanel.Controls.Add(new ScrollBarCorner() { Dock = DockStyle.Right, Size = new Size(SystemInformation.HorizontalScrollBarHeight, SystemInformation.HorizontalScrollBarHeight), BackColor = SystemColors.Control, TabStop = false, }); Controls.Add(bottomPanel); #endregion // Bottom Panel this.InitControl(); ResumeLayout(); //TODO: detect clipboard changes // need detect and remove the hightlight range when content has been removed from System Clipboard //ClipboardMonitor.Instance.ClipboardChanged += new EventHandler<ClipboardChangedEventArgs>(ClipboardMonitor_ClipboardChanged); this.adapter = new WinFormControlAdapter(this); this.editTextbox = new InputTextBox(this) { Visible = false, BorderStyle = System.Windows.Forms.BorderStyle.None, Multiline = true }; this.Controls.Add(this.editTextbox); this.adapter.editTextbox = this.editTextbox; this.InitWorkbook(this.adapter); #if WINFORM && DEBUG Logger.RegisterWritter(WinForm.RGDebugLogWritter.Instance); #endif // WINFORM && DEBUG //this.sheetTab.VisibleChanged += canvasElements_VisibleChanged; //this.hScrollBar.VisibleChanged += canvasElements_VisibleChanged; this.bottomPanel.VisibleChanged += canvasElements_VisibleChanged; this.vScrollBar.VisibleChanged += canvasElements_VisibleChanged; var g = System.Drawing.Graphics.FromHwnd(this.Handle); this.renderer = new GDIRenderer(g); }
/// <summary> /// When the DataGridView is visible for the first time a panel is created. /// The DataGridView is then removed from the parent control and added as /// child to the newly created panel /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void changeParent() { if (!DesignMode && Parent != null) { summaryControl.InitialHeight = this.refBox.Height; summaryControl.Height = summaryControl.InitialHeight; summaryControl.BackColor = this.RowHeadersDefaultCellStyle.BackColor; summaryControl.ForeColor = Color.Transparent; summaryControl.RightToLeft = this.RightToLeft; panel.Bounds = this.Bounds; panel.BackColor = this.BackgroundColor; panel.Dock = this.Dock; panel.Anchor = this.Anchor; panel.Padding = this.Padding; panel.Margin = this.Margin; panel.Top = this.Top; panel.Left = this.Left; panel.BorderStyle = this.BorderStyle; Margin = new Padding(0); Padding = new Padding(0); Top = 0; Left = 0; summaryControl.Dock = DockStyle.Bottom; this.Dock = DockStyle.Fill; if (this.Parent is TableLayoutPanel) { int rowSpan, colSpan; TableLayoutPanel tlp = this.Parent as TableLayoutPanel; TableLayoutPanelCellPosition cellPos = tlp.GetCellPosition(this); rowSpan = tlp.GetRowSpan(this); colSpan = tlp.GetColumnSpan(this); tlp.Controls.Remove(this); tlp.Controls.Add(panel, cellPos.Column, cellPos.Row); tlp.SetRowSpan(panel, rowSpan); tlp.SetColumnSpan(panel, colSpan); } else { Control parent = this.Parent; //remove DataGridView from ParentControls parent.Controls.Remove(this); parent.Controls.Add(panel); } this.BorderStyle = BorderStyle.None; panel.BringToFront(); hScrollBar.Top = refBox.Height + 2; hScrollBar.Width = this.Width; hScrollBar.Left = this.Left; summaryControl.Controls.Add(hScrollBar); hScrollBar.BringToFront(); panel.Controls.Add(this); spacePanel = new Panel(); spacePanel.BackColor = panel.BackColor; spacePanel.Height = summaryRowSpace; spacePanel.Dock = DockStyle.Bottom; panel.Controls.Add(spacePanel); panel.Controls.Add(summaryControl); resizeHScrollBar(); adjustSumControlToGrid(); adjustScrollbarToSummaryControl(); resizeHScrollBar(); } }
private void DoResize() { #if REPMAN_COMPACT if (Parent == null) { return; } if ((HBar == null) && (FAutoScale != AutoScaleType.EntirePage)) { HBar = new System.Windows.Forms.HScrollBar(); VBar = new System.Windows.Forms.VScrollBar(); HBar.Top = Height - HBar.Height; HBar.Left = 0; HBar.Width = Width; VBar.Left = Width - VBar.Width; VBar.Top = 0; VBar.Height = Height - HBar.Height; FBarWidth = VBar.Width; FBarHeight = HBar.Height; HBar.Parent = this; VBar.Parent = this; HBar.BringToFront(); VBar.BringToFront(); HBar.ValueChanged += new EventHandler(DoHBarChange); VBar.ValueChanged += new EventHandler(DoVBarChange); HBar.Maximum = image.Width - (Width - VBar.Width); VBar.Maximum = image.Height - (Height - HBar.Height); HBar.Minimum = 0; VBar.Minimum = 0; } #else int hoffset = FBarWidth; int voffset = FBarHeight; if (!HScroll) { voffset = 0; } if (!VScroll) { hoffset = 0; } int imLeft, imTop; imLeft = 0; imTop = 0; if (Parent == null) { return; } if (image.Width < Parent.ClientSize.Width - hoffset) { imLeft = (Parent.ClientSize.Width - image.Width - hoffset) / 2; } if (image.Height < Parent.ClientSize.Height - voffset) { imTop = (Parent.ClientSize.Height - image.Height - voffset) / 2; } int newleft = imLeft - Math.Abs(AutoScrollPosition.X); int newtop = imTop - Math.Abs(AutoScrollPosition.Y); if ((image.Left != newleft) || (image.Top != newtop)) { image.SetBounds(newleft, newtop, image.Width, image.Height); } #endif }
private void DrawControls() { try { #region top // Maximum of horizontal scroll bar is a multiple of measures int dur = sequence1.GetLength(); int lastenoteticks = sequence1.GetLastNoteEndTime(); int nbmeasures = 0; // Conversion to int gives strange results for the number of measures // because it round to the closest integer, so 4.1 measures will gives only 4 measures instead of 5 if (_measurelen > 0) { nbmeasures = Convert.ToInt32(lastenoteticks / _measurelen); } // compares time for all measures with time of last note int totaltimemeasures = nbmeasures * _measurelen; if (lastenoteticks > totaltimemeasures) { nbmeasures++; } totaltimemeasures = nbmeasures * _measurelen; #region positionHscrollBar // Music Cursor position positionHScrollBar.Left = pnlLeftPiano.Width; positionHScrollBar.Width = pnlPiano.Width - positionHScrollBar.Left; positionHScrollBar.Maximum = totaltimemeasures + _measurelen; positionHScrollBar.Minimum = _measurelen; positionHScrollBar.TickStyle = TickStyle.TopLeft; if (nbmeasures < 100) { positionHScrollBar.ScaleDivisions = nbmeasures; } else { int n = 2; while (!(nbmeasures % n == 0 && nbmeasures / n < 100)) { n++; if (n >= nbmeasures) { break; } } if (n < nbmeasures) { positionHScrollBar.ScaleDivisions = nbmeasures / n; } else { positionHScrollBar.ScaleDivisions = nbmeasures; } } positionHScrollBar.TickDivide = _measurelen; // Small change = measurelen divided by resolution positionHScrollBar.SmallChange = (uint)_measurelen / vPianoRollControl1.Resolution; positionHScrollBar.LargeChange = (uint)_measurelen; if (_measurelen > 0) { positionHScrollBar.MouseWheelBarPartitions = _measurelen; } #endregion #region vScrollRoll vScrollBar.Maximum = _totalTicks + 2 * _measurelen; vScrollBar.Minimum = _measurelen; vScrollBar.SmallChange = _measurelen / vPianoRollControl1.Resolution; vScrollBar.LargeChange = _measurelen; vScrollBar.Value = _measurelen; #endregion #endregion #region middle /* * vScrollbar = new VScrollBar() * { * Parent = pnlScrollView, * Top = 0, * Left = pnlScrollView.Width - Width, * Height = 200, * Minimum = 0, * }; * pnlScrollView.Controls.Add(vScrollBar); * vScrollBar.BringToFront(); * vScrollBar.Dock = DockStyle.Right; */ vPianoRollControl1.Dock = DockStyle.Fill; #endregion #region bottom hScrollBar = new HScrollBar() { Parent = pnlPiano, Top = 0, Left = 0, Minimum = 0, }; pnlPiano.Controls.Add(hScrollBar); hScrollBar.BringToFront(); hScrollBar.Dock = DockStyle.Bottom; hScrollBar.Scroll += new ScrollEventHandler(hScrollBar_Scroll); hScrollBar.ValueChanged += new EventHandler(hScrollBar_ValueChanged); hScrollBar.Visible = false; hScrollBar.Maximum = Math.Abs(pnlPiano.Width - pianoControl1.TotalLength); hScrollBar.Minimum = 0; hScrollBar.Value = hScrollBar.Minimum; // Piano pianoControl1.Left = 0; pianoControl1.Top = pnlRedPianoSep.Height; pnlPiano.Height = 167; pianoControl1.Orientation = Orientation.Horizontal; pianoControl1.PianoKeyDown += new EventHandler <PianoKeyEventArgs>(PianoControl1_PianoKeyDown); pianoControl1.PianoKeyUp += new EventHandler <PianoKeyEventArgs>(PianoControl1_PianoKeyUp); // Notes du piano pianoControl1.LowNoteID = vPianoRollControl1.LowNoteID = 21; //23 pianoControl1.HighNoteID = vPianoRollControl1.HighNoteID = 108; vPianoRollControl1.Sequence1 = sequence1; vPianoRollControl1.zoomy = zoomy; pianoControl1.Zoom = zoomx; //pianoControl1.Width = pianoControl1.TotalLength; pianoControl1.Height = pnlPiano.Height; vPianoRollControl1.xScale = pianoControl1.Scale; vPianoRollControl1.OffsetChanged += new Sanford.Multimedia.Midi.VPianoRoll.OffsetChangedEventHandler(vPianoRollControl1_OffsetChanged); #endregion SetScrollBarValues(); } catch (Exception ex) { Console.Write(ex.Message); } }