Here is the situation:
I am trying to control flowLayoutControl's scroll bar from devexpress controls VerticalScroll.
Now - flowLayoutControl with autoscroll = true. I added a new verticalscroll control and dock it to Right. So now the Devexpress Vertical Scroll control is right on top of FlowLayout scrollbar.
Also the FlowLayoutPanel vertical scroll does not hide when following code is run:
spotWinFlowLayout1.VerticalScroll.Visible = false
I have setup the following event handlers:
private void spotWinFlowLayout1_Resize(object sender, EventArgs e)
{
SetupVerticalScrollBar();
}
private void SetupVerticalScrollBar()
{
vScrollBar1.Minimum = spotWinFlowLayout1.VerticalScroll.Minimum;
vScrollBar1.Maximum = spotWinFlowLayout1.VerticalScroll.Maximum;
vScrollBar1.LargeChange = spotWinFlowLayout1.VerticalScroll.LargeChange;
vScrollBar1.SmallChange = spotWinFlowLayout1.VerticalScroll.SmallChange;
}
private void vScrollBar1_Scroll(object sender, ScrollEventArgs e)
{
spotWinFlowLayout1.VerticalScroll.Value = e.NewValue;
}
Everything is working fine except when on form Load there is already a scrollbar on flowLayoutControl,
spotWinFlowLayout1.VerticalScroll.XXX properties not set yet. So both the scrollbars are out of Sync. But as soon as I resize the form both get Sync.
So when is scrollbar for the FlowLayoutPanel initialized?
So when is scrollbar for the
FlowLayoutPanel initialized?
This might sound like a smartalec answer: "When the control is drawn or placed on the form" which is the reason when you adjust the size of the form they are in sync.( they are being drawn again )
The solution is to manually add the scrollbars yourself.
Related
how to get scollbar height in scrollviewer in uwp just like shown in this photo.
How to get scrollbar height in scrollviewer in uwp?
Please check ScrollBar style(stored in the general.xaml file), the matched part like above screenshot is VerticalThumb, you could copy the following style in your page resource, and detect VerticalThumb load event, and get the ActualHeight property with following code.
private void VerticalThumb_Loaded(object sender, RoutedEventArgs e)
{
var verticalThumb = sender as Thumb;
var height = verticalThumb.ActualHeight;
}
In my WinForm project I have panel control and it has DataGridview child. Datagridview has 50 columns and this needs scrolling. but i don't want to use Datagridview scroll bar. I want to use panel scroll bar.
But these two scrollbar has different functionalities. Datagridview scrollbar has more capabilities than panel scroll bar.
For example,
1)With DatagirdView scrollbar you can freeze columns easily.
2)Also while entering data in datagridview, with TAB key, scrollbars move automatically.
Is there any solution to add Datagridview scroll bar functions to panel scrollbar's.
Or How to add the above 2 functions to panel scrollbar.
Thanx in advance.
The panel scrollbar can only be used to control the position of the entire datagridview.
Here is a workaround that using external Scrollbar to scroll datagridview.
First, need to add a HScrollBar to the form and set its properties as followed.
hScrollBar1.Maximum = dataGridView1.Columns[0].Width * dataGridView1.ColumnCount + dataGridView1.RowHeadersWidth;
hScrollBar1.Value = 0;
hScrollBar1.Location = new Point(panel1.Location.X, panel1.Location.Y + panel1.Height);
And subscribe to Scroll event
hScrollBar1.Scroll += hScrollBar_Scroll;
private void hScrollBar_Scroll(object sender, ScrollEventArgs e)
{
int rowindex = dataGridView1.CurrentCell.RowIndex;
int columnindex = (hScrollBar1.Value - dataGridView1.RowHeadersWidth) / dataGridView1.Columns[0].Width;
this.dataGridView1.CurrentCell = this.dataGridView1[columnindex, rowindex];
}
If want to change the scrollbar value according to the selected cell, subscribe to DataGridView.SelectionChanged event.
dataGridView1.SelectionChanged += dataGridView_SelectionChanged;
private void dataGridView1_SelectionChanged(object sender, EventArgs e)
{
hScrollBar1.Value = (dataGridView1.CurrentCell.ColumnIndex + 1) * dataGridView1.Columns[0].Width + dataGridView1.RowHeadersWidth;
}
The above columnindex and hScrollBar1.Value are obtained according to the following formula:
I have a UserControl within a WinForms-form where within is a panel that resizes its content by custom code when the parent window is resized:
private void ResizeElements(FlowLayoutPanel panel) {
panel.SuspendLayout();
foreach (Control ctrl in panel.Controls) {
ctrl.Width = panel.ClientSize.Width - 20;
}
panel.ResumeLayout();
}
private void flowPanel_Resize(object sender, EventArgs e) {
ResizeElements((FlowLayoutPanel)sender);
}
This works just fine when I resize the window manually by grabbing it at the lower right corner and resize there:
This does not work however, wenn I maximize the window and after that click onto the restore-controlbox between minimize and maximize.
The controls from that Panel seem to have the right width, but the FlowLayoutPanel that contains them has a horizontal scrollbar:
When I resize the window manually again the horizontal scrollbar disappears and everything is as expected.
The flowpanel has DockingStyle.Fill
Update: I currently do the following to get around this issue:
private void frmMain_Resize(object sender, EventArgs e)
{
var oldWindowState = _previousWindowState;
_previousWindowState = this.WindowState;
if (oldWindowState == FormWindowState.Maximized && this.WindowState == FormWindowState.Normal)
{
this.Width++;
this.Width--;
}
}
So I resize manually when detecting a restore-click forcing the correct events to be fired. I am fully aware that this is an evil hack and still would prefer a more clean solution.
(Update): Parent Controls:
WinForm
->Panel Dock: Fill, AutoSize: false
->UserControl Dock: Fill, AutoSize: false
->TabControl Dock: Fill
->Tab
->FlowLayoutPanel Dock: Fill, AutoSize: false
I am using tab control, and there is one label that showing customer's name that I want to display in all three 3 tabs. However, if I put it on tab 1, then it won't show on tab 2 and 3, even thought that the name of the label is unique. Is there a way to do that ? or do I have to create 3 different labels ? thanks a lot.
This might work for you. When changing tabs. Add the label to the TabPage's Controls collection. When adding the label to the new TabPage it gets removed from the previous TabPage so you have to re-add it every time you change tabs.
public partial class Form1 : Form
{
Label label = new Label() { Text = "Hello World" };
public Form1()
{
InitializeComponent();
tabControl1.TabPages[0].Controls.Add(label);
}
private void tabControl1_Selected(object sender, TabControlEventArgs e)
{
e.TabPage.Controls.Add(label);
e.TabPage.Controls.SetChildIndex(label, 0);
}
}
Position label1 in your desired location in the TabPage at design-time, then switch it to the Form in the Load() event using code like this:
private void Form1_Load(object sender, EventArgs e)
{
Point pt = label1.PointToScreen(new Point(0, 0));
label1.Parent = this;
label1.Location = this.PointToClient(pt);
label1.BringToFront();
}
You should put on form 2 panels.
1st panel should have Docking = Top and with height equal to height of your label. Put your label there (on 1st panel).
2nd panel should have Docking = Fill, put your tab control on 2nd panel.
I have MSChart control within Panel in my form. Panel has AutoScroll property set to True. Once the chart gets too big - user is able to scroll through it.
Once user presses Ctrl+MouseWheel I am enabling zoom in/out to the chart area. Currently on MouseWheel - both Panel and Chart are scrolling. How do I disable Panel scrollbars at the time when Chart is handling scrolling events?
After disabling AutoScroll property Panel is moving scroll to the top and hiding vertical scrollbar - so this is not what I want:
void Chart_KeyDown(object sender, KeyEventArgs e)
{
if (e.Control == true)
{
(Parent as Panel).AutoScroll = false;
}
}
void Chart_KeyUp(object sender, KeyEventArgs e)
{
if (e.Control == false)
{
(Parent as Panel).AutoScroll = true;
}
}
I would like Panel scrollbar to "freeze" when chart is zooming (ctrl+mousewheel) and activate when chart is idle (mousewheel). Any ideas?