.NET vScrollBar Questions - c#

Can anyone tell me why the formula for the the actual maximum Value of a vScrollBar control is Maximum + LargeStep -1?
Is there a way to configure the control so that the Value is 0 when the scroll bar is at the bottom of the screen?

LargeChange is the size of the button that slides in a vScrollBar. Since the top part of the slider cannot slide all the way to the bottom, the maximum change is the vScrollBar.Maximum minus the size of the slider, and the size of the slider is set to be equal to the LargeChange.
You can set the minumum to be zero (plus largeCharge plus 1) to get it the be zero at the bottom. However, the other values will be negative. Maybe a better way is to subtract the value from the maximum in the scroll event and assign that to a variable:
scrollValue = VScrollBar1.Maximum - VScrollBar1.Value - VScrollBar1.LargeChange + 1
You may want to add the LargeValue to the vScrollBar1.Maximum.

Related

ZedGraph Legend text Location

I have a problem positioning a legend to accommodate changing graph data values.
The Zedgraph Y axis scale is set to auto - GraphPane.YAxis.Scale.MinAuto = true.
The graph is populated with differing data stes as chosen by a combobox.
This obviously results in fluctuating Scale.Min values.
I have a legend located under the min value line. As I select differing sources, the location of this legend jumps around.
How can I specify the legends position so that it stays in the same place regardless of input?
What I need is to get the axis minimum value and offset it by a negative amount to be just under the graph data.
It would be easy if the scale was zero'd but as it changes, I'm lost...
These pics show how the legend moves with differing data.
This is the code referencing the text placement.
The offset value representing UNKNOWN is what I need to determine each time.
TextObj Qtr1Text = new TextObj("Q" + Qtr1 + " 16", dQtrFirst, myPane.YAxis.Scale.Min - UNKNOWN);
As shown, both the 'Q2 16' offsets are 0.08.
or maybe there is a much better way of doing all this?
Finally figured out a reliable way to do this.
double yOffset = (myPane.YAxis.Scale.Max - myPane.YAxis.Scale.Min) / 36; //magic number
TextObj Qtr1Text = new TextObj("Text Value", xLocation, yOffset);
myPane.GraphObjList.Add(Qtr1Text);
The value 36 is an arbitrary number which should be adjusted to give you the negative spacing you want. 36 gives a spacing like in the top pic, right hand side 'Q3 16'.

Why is the ListBox's DesiredSize.Width always zero?

I am creating a custom control in C#, and want to have a grid cell that contains a ListBox, which can be hidden or shown as desired. Hiding it is easy, I just set the Width to zero, however when I want to show it, I need to know the width that the ListBox would like to use.
I thought that DesiredSize.Width would give me this vale, but it's always zero, even after calling Measure(). Here is the code I'm using to show the ListBox...
_lb.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
_lb.Width = _lb.DesiredSize.Width;
Any ideas how I find the desired width?
If your ListBox is in the cell of a grid, give that grid column a name. Then in code, you can access the .ActualWidth property of that grid column and use that value to set the width of your ListBox.
That assumes of course that the width of your grid column is not set to Auto, because that would still give you a 0 value.
_lb.Width = myGridColumn.ActualWidth
You might need to subtract a little bit from the column width to make your control fit nicely.
EDIT
One thing that I've found is that the ListBox must have items added to it before it will return anything other than 0 when it is measured.
string myItem = "Don't ask for a bath in Athabaska";
_lb.Items.Add(myItem);
_lb.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
double width = _lb.DesiredSize.Width;
As long as the ListBox has already been added to the window/usercontrol/grid, the above code returns a value of 227.53 for the width variable; using my defaults for font family and size.
If the ListBox has not been added to the window, or it doesn't have any items in it, it will return 0 for the .DesiredSize.Width property.
Also, if the .Visibility property is set to Collapsed instead of Hidden, the width will be 0.
Don't set the width to 0 when starting. Leave the width alone initially, set the .Visibility to Hidden. It will render to the needed width, but won't be shown. Then you can measure it and start playing around with the width.

set a form size more than 2128:1860

I need to let a form get bigger than 2128:1860 which seems to be the biggest dimension.
how can I expand it?
I've already tried expanding it via properties
I'm working with Visual Studio, in C#
The maximum value for a form size is based on the resolution of the screen:
From the docs:
The maximum value of this property is limited by the resolution of the
screen on which the form runs. The value cannot be greater than 12
pixels over each screen dimension (horizontal + 12 and vertical + 12).

How to print labels on both sides of a rangebar in WinForms MS Chart using C#

How can i add labels for each and every yvalue in series of a rangebarchart ?
You all know that for plotting rangebartype series ,we need two yvalues as yvalue[0] and yvalue[1] .Here I need to add data labels to each of those yvalues( which means both at yvalue[0] and yvalue[1]).how can i implement that?can anybody suggest me?please!!
The label should look like as below for a rangebar(to be displayed on both sides of a rangebar).
Label1 ███████████████ Label2
Label███████████████████ Label
There is no built-in way to do this in MS Chart. However, there is an ugly little workaround that will give you the display that you want.
For each datapoint (rangebar) that you want to display, you will need to create 2 datapoints that lie on top of one another. As an example:
DataPoint0: X=1 Y=5,10
DataPoint1: X=1 Y=10,5
These two datapoints lie right on top of one another, except one is displayed left-to-right and the other is displayed right-to-left.
For each DataPoint, under CustomProperties, there is the BarLabelStyle property. Set this to 'Outside' for both of the datapoints. Normally, this will display the label to the right of the range bar, but for DataPoint1, with the reversed Y values, the label is now placed to the left of the range bar. So, set your label for DataPoint0 to 10 (max value), and for DataPoint1 set the label to 5 (min value).
This will then look just like one range bar with the min value on the left and the max value on the right.
Caution: If either end of the range bar is too close to the edge of your graph, MS Chart, in its infinite wisdom, will force the label to be displayed inside the range bar. To overcome this, you can actually add a third number to the Y values of the DataPoint object. This third value is not displayed, but if it is larger than the largest Y value in your data series, it will force the chart to rescale to accommodate this larger value, so your labels are not forced inside the range bars. You could probably handle this another way with setting properties of the ChartArea also.

How to manipulate the LargeChange and SmallChange on a scrollbar to work

I have a number of panels in a single window in C# application and I created 2 scrollbars, one for horizontal and one vertical. This is what I currently have:
picture with 2 scroolbars http://www.simnet.is/elinnils52/scrollbar.jpg
I have 1 variable and that is the total height all the items take & need.
Here is my code on scroll change:
for (int i = 0; i < this._splitMainView.Panel2.Controls.Count; i++)
{
this._splitMainView.Panel2.Controls[i].Location = new Point(
3 - _scrollBarX.Value,
3 + (132 + 6) * (i - 2) - _scrollBarY.Value);
this._splitMainView.Panel2.Controls[i].Refresh();
}
The scrollbar maximum is the total amount of all the containers height, the space in between and a few pixels extra.
As you can see from the picture, it doesn't look good. Even if the maximum in this case is a little around 50 - 100 pixels it still looks like it's a thousand pages long. When I change the SmallChange and LargeChange, the scrollbar bar itself lengthens but then it wont reach the maximum pixels. It will be able to get almost at the end (depening on the SmallChange and LargeChange value) and leave around 5 - 29 px left. And as everyone knows, seeing half is not good.
Does anyone know how to overcome this obstacle or a better way to implement it?
Why not just make the maximum value of the scrollbar the overflow (visible area height - panel height)? Then just set the top of the panel to the value of the scrollbar * -1.
Is there a reason not to use the AutoScroll property?

Categories