How to get scrollbar height in scrollviewer in uwp? - c#

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;
}

Related

How to get available area content view xamarin with tabbedpage in navigationpage xamarin form

Image here
I have a ContentPage in TabbedPage and NavigationPage. How to get height value of green area? Thanks.
The green area is the ContentPage.
You can access its Height and Width property directly.
var height = myContentPage.Height;
You can add button in ContentPage, then try the following code in Button.click event.
private void Button_Clicked(object sender, EventArgs e)
{
var height = this.Height;
Console.WriteLine("the contentpage height is {0}", height);
}

What is the difference between the verticall offset of a ScrollViewer itself and that of ScrollChangedEventArgs

I set a ScrollChangedEventHandler for a ScrollViewer as shown in the code below.
private void scrollViewer_ScrollChanged(object sender, ScrollChangedEventArgs e)
{
var scrollViewer = sender as ScrollViewer;
if (scrollViewer == null)
return;
Console.WriteLine(scrollViewer.VerticalOffset);
Console.WriteLine(e.VerticalOffset);
}
Sometimes, the 2 VerticalOffsets result in different values.
Could you tell me what is the actual difference between the verticall offset of a ScrollViewer itself and that of ScrollChangedEventArgs?
As a conclusion from the MSDN Documentation for those two properties :
ScrollViewer.VerticalOffset: represent the original value of the ScrollViewer Vertical offset (before you do the scroll, means the vertical offset before the event is triggered)
e.VerticalOffset: represents the new updated value of the Vertical offset of the ScrollViewer (after you do the scroll, means the value of the vertical offset after the event is triggered)
For general-purpose, you will use the e.VerticalOffset property.
NOTE: the same is applied to the HorizontalOffset property.
here is the Resource 1 and Resource2

Resize Rich _ textBox according to Form size

I need to resize my multiline textbox during runtime and set the width and height according to my main form size so i dont have to use scrollBars when my form is maximised...
already tried the code shown below but the result is nothing any ideas??
private void richTextBox2_TextChanged(object sender, EventArgs e)
{
Size size = TextRenderer.MeasureText(richTextBox2.Text, richTextBox2.Font);
richTextBox2.Width = size.Width;
richTextBox2.Height = size.Height;
}

Datagridview needs to hide Scrollbar, but scroll should be achievable through code

I have 2 Datagrids with same number of columns
Datagrid1 is displaying only headers,
Datagrid2 is just below it displaying all the data.
In essence, the 2 grid's need to be synchronised to appear as 1 grid.
My issue here is I need to hide the horizontal scrollbar of datagrid1, but display only that for the datagrid2.
When the user scroll's the datagrid2, I need to programmatically synchronise the headers on datagrid1.
Can anyone suggest?
Try this..
dataGridViews1.ScrollBars = ScrollBars.None;
private void dataGridViews2_Scroll(object sender, ScrollEventArgs e)
{
int offSetValue = dataGridViews1.HorizontalScrollingOffset;
try
{
dataGridViews1.HorizontalScrollingOffset = offSetValue;
}
catch { }
dataGridViews1.Invalidate();
}
You can set the DataGridViews ScrollBasr property to hide vertical scrollbar
e.g.
dataGridViews1.ScrollBars = ScrollBars.None;
or see other enumeration value at link
http://msdn.microsoft.com/en-us/library/system.windows.forms.scrollbars
You can set the VerticalScrollingOffset value to position the Scrolling bar at the index you want. Handle the Scroll event in the second DGV and set this VerticalScrollingOffset for the first DGv. This should help.
I have same concept like you..I have solved it as per folowing : may it help u.
private void dgvHeader_ColumnWidthChanged(object sender, DataGridViewColumnEventArgs e)
{
//When Header Grid Width Changes automatically Below Grid's COLUMN width will be changes
dgvData.Columns[e.Column.Index].Width = e.Column.Width;
}

C# Winforms - When are scrollbars for a Control initialized?

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.

Categories