C# 检测滚动条高度和当前位置
我想在我的表单中检测滚动条的高度和当前位置 我用的是身高C# 检测滚动条高度和当前位置,c#,winforms,C#,Winforms,我想在我的表单中检测滚动条的高度和当前位置 我用的是身高 systeminformation.horizontalscrollbarheight 如何检测当前位置 编辑 我想从库中检测高度和位置。使用垂直滚动和水平滚动 更多有关 示例代码,显示滚动表单后的滚动信息: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing
systeminformation.horizontalscrollbarheight
如何检测当前位置
编辑
我想从库中检测高度和位置。使用垂直滚动和水平滚动 更多有关 示例代码,显示滚动表单后的滚动信息:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Scroll(object sender, ScrollEventArgs e)
{
this.label1.Text = $"scrollbarHeight: {SystemInformation.HorizontalScrollBarHeight}\n"
+ $"verticalScrollPos: {this.VerticalScroll.Value}\n"
+ $"horizontalScrollPos: {this.HorizontalScroll.Value}";
}
/// <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);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.panel1 = new System.Windows.Forms.Panel();
this.label1 = new System.Windows.Forms.Label();
this.panel1.SuspendLayout();
this.SuspendLayout();
//
// panel1
//
this.panel1.Controls.Add(this.label1);
this.panel1.Location = new System.Drawing.Point(134, 165);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(458, 459);
this.panel1.TabIndex = 0;
this.panel1.Paint += new System.Windows.Forms.PaintEventHandler(this.panel1_Paint);
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(36, 23);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(64, 25);
this.label1.TabIndex = 1;
this.label1.Text = "label1";
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(11F, 24F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.AutoScroll = true;
this.ClientSize = new System.Drawing.Size(505, 421);
this.Controls.Add(this.panel1);
this.Name = "Form1";
this.Text = "Form1";
this.Scroll += new System.Windows.Forms.ScrollEventHandler(this.Form1_Scroll);
this.panel1.ResumeLayout(false);
this.panel1.PerformLayout();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Label label1;
}
}
使用系统;
使用System.Collections.Generic;
使用系统组件模型;
使用系统数据;
使用系统图;
使用System.Linq;
使用系统文本;
使用System.Threading.Tasks;
使用System.Windows.Forms;
命名空间Windows窗体应用程序1
{
公共部分类Form1:Form
{
公共表格1()
{
初始化组件();
}
私有void Form1\u滚动(对象发送方,ScrollEventArgs e)
{
this.label1.Text=$“scrollbarHeight:{SystemInformation.HorizontalScrollBarHeight}\n”
+$“verticalScrollPos:{this.VerticalScroll.Value}\n”
+$“horizontalScrollPos:{this.HorizontalScroll.Value}”;
}
///
///必需的设计器变量。
///
private System.ComponentModel.IContainer components=null;
///
///清理所有正在使用的资源。
///
///如果应释放托管资源,则为true;否则为false。
受保护的覆盖无效处置(布尔处置)
{
if(处理和(组件!=null))
{
组件。Dispose();
}
基地。处置(处置);
}
#区域Windows窗体设计器生成的代码
///
///设计器支持所需的方法-不修改
///此方法的内容与代码编辑器一起使用。
///
私有void InitializeComponent()
{
this.panel1=new System.Windows.Forms.Panel();
this.label1=new System.Windows.Forms.Label();
这个.panel1.SuspendLayout();
这个.SuspendLayout();
//
//小组1
//
this.panel1.Controls.Add(this.label1);
this.panel1.Location=新系统图纸点(134165);
this.panel1.Name=“panel1”;
this.panel1.Size=新系统图纸尺寸(458459);
this.panel1.TabIndex=0;
this.panel1.Paint+=新的System.Windows.Forms.PaintEventHandler(this.panel1_-Paint);
//
//标签1
//
this.label1.AutoSize=true;
this.label1.Location=新系统图纸点(36,23);
this.label1.Name=“label1”;
this.label1.Size=新系统图尺寸(64,25);
this.label1.TabIndex=1;
this.label1.Text=“label1”;
//
//表格1
//
this.AutoScaleDimensions=新系统.Drawing.SizeF(11F,24F);
this.AutoScaleMode=System.Windows.Forms.AutoScaleMode.Font;
this.AutoScroll=true;
this.ClientSize=新系统图尺寸(505421);
this.Controls.Add(this.panel1);
this.Name=“Form1”;
this.Text=“Form1”;
this.Scroll+=new System.Windows.Forms.ScrollEventHandler(this.Form1\u Scroll);
此.panel1.ResumeLayout(错误);
此.panel1.PerformLayout();
此选项为.resume布局(false);
}
#端区
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.label1;
}
}
您在“当前位置”光标位置或窗体位置的意思是什么?滚动条的终点,,,假设用户滚动到窗体的一半并停止,则我需要滚动条的位置Winforms中有许多不同类型的滚动条。如果你谈到专用控件,那就太明显了。通常,当您将AutoScroll属性设置为true时,您将获得它们,然后从AutoScrollPosition获取位置。有些控件根本不允许您查找,ListView就是一个例子。当您谈到“滚动表单的一半”时,您需要自动滚动定位。