我發現VScrollBar(垂直滾動條可用Visual Studio工具框中)的一個奇怪的行爲。問題是「」如果我向下滑動滾動條,它會向上移動,如果向上滑動,則會向下移動「。微軟VSrollBar行爲或觸摸屏的錯誤 - Windows窗體
步驟來複制錯誤或行爲 - 1
1)添加VScrollBar作爲一個孩子的任何用戶控制。
2)向上或向下滑動用戶控件(不在滾動條上)。在相反的方向上垂直滾動條移動時,即使沒有內容控件和VScrollBar之間任何的程序化連接
步驟來複制錯誤或行爲 - 2
1)添加VScrollBar作爲子任用戶控制。
2)上滑動的滾動條,它將滑動期間滑動時向上移動上下向下(正確的行爲)
3)向上或向下滑動所述用戶控制。垂直滾動條向相反方向移動
4)現在向上或向下滑動垂直滾動條。垂直滾動條開始在相反的方向移動(錯誤行爲,僅發生錯誤沒有之後:1)
簡單的控制與垂直滾動條來複制此行爲
public class QuickViewer : Control
{
public QuickViewer()
{
// Designer generated code
// Copy pasted for illustration alone
this.vScrollBar1 = new System.Windows.Forms.VScrollBar();
this.SuspendLayout();
//
// vScrollBar1
//
this.vScrollBar1.Location = new System.Drawing.Point(420, 4);
this.vScrollBar1.Name = "vScrollBar1";
this.vScrollBar1.Size = new Size(this.vScrollBar1.Width, 292);
//
// QuickViewer
//
this.Controls.Add(this.vScrollBar1);
this.Name = "QuickViewer";
this.Size = new System.Drawing.Size(441, 296);
this.vScrollBar1.Value = 5;
this.ResumeLayout(false);
}
protected override void OnPaint(PaintEventArgs e)
{
//My actual control is different. I prepared a simple control to replicate the buggy behavior of VScrollBar
//Control border
Pen borderPen = new Pen(Color.LawnGreen, 5);
e.Graphics.DrawRectangle(borderPen, ClientRectangle);
borderPen.Dispose();
//View area
Rectangle rect = new Rectangle(ClientRectangle.Location, ClientRectangle.Size);
rect.Inflate(-25, -10);
e.Graphics.FillRectangle(Brushes.White, rect);
e.Graphics.DrawRectangle(Pens.Black, rect);
this.Font = new System.Drawing.Font("Segoe UI", 12, FontStyle.Bold);
StringFormat format = new StringFormat() { Alignment = StringAlignment.Center };
e.Graphics.DrawString("Quick viewer", this.Font, Brushes.Black, rect, format);
string content = "This is a control created to illustrate the bug in VScrollBar." +
"\n Control area refers to the area with white background" +
"\n Control and Vertical Scrollbar are not programatically connected with each other."
+ "But still VScrollBar moves if you swipe on control area";
Font font = new System.Drawing.Font("Segoe UI", 12, FontStyle.Italic);
rect.Y += 20;
e.Graphics.DrawString(content, font, Brushes.Black, rect, format);
font.Dispose();
format.Dispose();
base.OnPaint(e);
}
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
private System.Windows.Forms.VScrollBar vScrollBar1;
}
問題:
有什麼辦法來克服這種行爲或錯誤?我希望滾動條在向下滑動時向下移動,並向上滑動時向上移動。當滑過內容時不應該有任何滾動
酷內部控制
Top = VScroll.Value
(沒有減號需要),給它一個去,讓我知道你如何去: ) –我試過這個應用程序,但仍然沒有運氣。另外,這與系統設置無關。我也在MSDN上發佈了關於這個行爲的問題https://social.msdn.microsoft.com/Forums/en-US/981f8b1c-9f7b-4a6f-9bda-4327703a3492/vertical-scrollbar-behavior-with-touch-screen?論壇=的WinForms。 – Kira
註冊表中的設置是***全局***設置。你的應用程序不應該篡改它。如果用戶喜歡以某種方式讓她的電腦滾動,那麼您應該尊重這一點。 Hans評論的目的是爲了證明這不是Windows中的錯誤,而是一個可配置的設置(因爲它在Mac OS上)。讓用戶決定。 –