Scrollbar value not updating when using mousescroll - c#

I am dynamically adding buttons to a FlowLayoutPanel, when I scroll using the mouse wheel on the panel the scrollbar value does not change however it still scrolls. When I click on the small arrow to force a scroll the value changes.
I want an event to trigger whenever the value of the scrollbar changes but can't seem to figure out how to, any help is much appreciated.

Probably an oversight by the authors. Not sure what you are doing with the scroll values, but you can just use the MouseWheel event to get the same scroll value:
void flowLayoutPanel1_MouseWheel(object sender, MouseEventArgs e) {
this.Text = flowLayoutPanel1.VerticalScroll.Value.ToString();
}

Related

Animation is not stop when panning in UWP

I have a two Panel both the Panel are in different ScrollViewer, I need to process the synchronous scrolling without animation, if I scrolled the second Panel the first Panelalso need to scroll with same HorizontalOffset without animation.
I have used the ViewChaning event of 2nd ScrollViewer and update the view of 1st ScrollViewer with the same HorizontalOffset, without animation.
Its works perfectly when I scrolled using mouse, if I scroll using touch(panning) the animation is occurs.
Please refer the code below,
private void ScrollViewer2_ViewChanging(object sender, ScrollViewerViewChangingEventArgs e)
{
this.scrollViewer1.ChangeView(e.NextView.HorizontalOffset, e.NextView.VerticalOffset, null, true);
}
How can I resole this issue, any one suggest on this?

c# scrollbar modify LargeChange onScroll not Value

Is there anyway to keep a scroll bar to stay at its current location (myScrollBar.Value) while Scroll event is firing during scroll box dragging? I can get it to work after I release the scroll box after dragging it, but I am trying to make it happen while I am scrolling it.
// this example doesn't work, but it is what I am trying to do
private void myScrollBar_Scroll(object sender, ScrollEventArgs e)
{
// as I scroll keep resetting NewValue back to 0 -
// this makes the value 0 only after I release the scroll box
e.NewValue = 0;
}
Any suggestion on a way to go about this would be great. Thanks.

Winform: Panel with scroll needs to have their width/height defined?

I've a winform usercontrol, that has a Panel, which is containing some TableLayout(which have also some other user controls).
All my components have a Dock=Fill and Autosize=True properties.
Currently, when I resize the windows, I don't have any scrollbar, the overflow is just no show.
I found that if I set the AutoScrollMinSize of my panel to something, I'm having those scrollbar appearing when I reach the set size.
My problem is that I add/remove elements on runtime, and I've also some things that I display or not depending the configuration. So for me it's very hard to hardcode here a value, either I've scrollbar too soon, or too late.
I'm sure there should be a way to configure my userControl, without having to calculate myself the size, to have the component displaying scrollbar, when the children's content cannot be displayed, do you know how?
Thank you!
You can change the AutoScrollMinSize value on the panel resize event or the form's resize event. That way, it won't be a fixed value and there will be a scrollbar available if the panel's child controls go beyond the panel edges -
private void panel1_Resize(object sender, EventArgs e)
{
panel1.AutoScrollMinSize = new System.Drawing.Size(panel1.Width, panel1.Height);
}

Removing Windows' ugly Selection marker thing from Splitter in SpitContainer Control

I have a SplitContainer control, and the Splitter in the middle is very ugly. By setting the BackColor of the SplitContainer to (insert color here), then setting the BackColor of Panel1 and Panel2 to white, I can have my splitter looking nice. But by default, Windows puts the selection mark over the Splitter, even before it's selected.
How can I make sure that the selection mark never shows on the Splitter?
I think by "Selection Marker Crap", you mean the fuzzy line that indicates the control is selected. If you don't want this showing up, set some other control to be selected at startup. Something like:
Textbox1.Selected = true;
This should solve your issue if it is just one of it not being selected. However, this will come back if you select the item to resize something. In that case, you could put something in the mouse_up event to move the selection off of the control. That way, the user moves the splitter bar and then when they let go, the selection gets cleared off of the splitter.
Another way would be to make the splitter bar narrow enough that the gray fuzzy line doesn't show up. To do this, you could do the following (tested):
splitContainer1.BorderStyle = BorderStyle.FixedSingle;
splitContainer1.SplitterWidth = 1;
I experienced the same problem, and fixed it by setting TabStop to False in the Properties window for SplitContainer1.
This could annoy people who depend or insist on using the keyboard to operate every aspect of your form, but other than that it will work. Controls inside the SplitContainer will remain tab-able, just not the SplitContainer itself.
This code will move the focus from the splitContainer to TreeView shortly after moved.
private void splitContainer1_SplitterMoved(object sender, SplitterEventArgs e) {
if(this.splitContainer1.CanFocus) {
this.splitContainer1.ActiveControl = this.treeView1;
}
}
You could add an event handler to steal the focus from the container on MouseUp's... It's a little messy but it works. :)
I tried a lot to remove splitter but nothing work. I did some different why we need to use splitter for that we can use picture box control make it width (or) height depend upon your project set 5 or 3 .... after picture box mouse move event write code like...
picturebox property-cursor change the cursor type Hsplit its look like splitter
private void picturebox1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)//this for mouse left click its work
{
//write you code here if you use panel set panel height or width it reaches...
Cursor.Position = new Point(e.X, e.Y); // this for mouse cursor position according your //project do some fine tune you will get its work...
}
its work because i tried lot for this and i itself found this method...
I set the TabStop to false and it went away.
Most simple solution i found/made - create a button, select it, and hide it.
All via code. there is not side effects or problems with this, place it in the forms load event.
Button DeSelectButton = new Button();
this.Controls.Add(DeSelectButton);
DeSelectButton.Select();
DeSelectButton.Visible = false;

Anchoring a Windows Forms Tooltip to the mouse

I want to show a tooltip when hovering over a button and as long as the mouse is over the button the tooltip should follow the mouse. What is the correct way to achieve that?
When I add a MouseMove event that calls tooltip.Show(...) with the updated mouse position it flickers extremely, and also redraws the tooltip when the mouse rests. And if it is an OwnerDraw tooltip I can see the default system tooltip style "fighting" with the self-drawn tooltip.
Indeed, with .Net 2.0 the ToolTip object has been altered. Before 2.0, there were some inconsistency problems when the ToolTip text was changed while the ToolTip was active, or with some other situations.
Since 2.0, the Tooltip is hidden each time something happens what could affect the currently active Tooltip.
While this solved some problems, it now causes some events being fired right after e.g. a SetToolTip(), even if this function has been called from within this very event, resulting in an endless loop of ToolTip draw/hide until the mouse moves away from the ToolTip area.
My own workaround is to check whether the ToolTip is already the same and omitting the Set ToolTip() if so. (simply omitting the next event by a static flag as suggested above can cause problems as there is no guarantee that there will be a new event right after, e.g. if the mouse has just touched the ToolTip area and moved away already).
Also, using OnMouseHover just to display a Tooltip disables the internal timer functionality of the ToolTip component as well as causing many many unnecessary events and therefore wastes processor time. The Popup Event of the ToolTip component serves well as point of action.
In this special case, however, OnMouse Hover is necessary to track the mouse movement.
Anyways, altering the ToolTip position causes a complete redraw of the Tooltip and therefore flicker. This can be reduced for a motionless mouse by checking whether the mouse position has changed between two events.
Unfortunately, the ToolTip component has no way to change the position of the ToolTip adn is shown always relative to the current mouse position. So the only way to have it follow the mouse is to close and redraw it.
it MAY help to set the UseFading and/or UseAnimation properties to false so the flicker can be further reduced.
OK, this may be complete overkill, and probably not the best solution, but I think a fun little hack nonthless.
Basically, I'm drawing a ListView at the location of the mouse. Some code:
ListView v = new ListView();
public Form1()
{
InitializeComponent();
v.Items.Add("Foo");
v.Height = 30;
v.Width = 50;
this.button1.Controls.Add(v);
v.MouseMove += new MouseEventHandler(v_MouseMove);
v.BackColor = SystemColors.Info;
this.button1.MouseMove += new MouseEventHandler(button1_MouseMove);
}
void v_MouseMove(object sender, MouseEventArgs e)
{
v.Location = new Point(v.Location.X + e.Location.X, v.Location.Y + e.Location.Y);
}
void button1_MouseMove(object sender, MouseEventArgs e)
{
v.Location = e.Location;
}
I've noticed that when manually showing a tooltip with OnMouseHover, OnMouseMove gets called one more time after the tooltip is shown. As a hack, I've ignored the next OnMouseMove call immediately following the tooltip being shown (using a flag). Perhaps a similar phenomenon is occurring?

Categories

Resources