|
分類:[C#]
お世話になります。以前同様の質問をしたのですが、
解決に至らなかったため、再度サンプルソースを
掲載して質問させてください。
Panel上にTextBoxを用意します。
このTextBoxはPanelのサイズを越えた大きさです。
PanelのAutoScrollプロパティをTrueにしている為、
自動的に垂直スクロールバーが表示されています。
スクロールバー自体の操作でスクロールは勿論のことですが、
▲▼ボタンでも上下させたいと考えています。
問題は起動直後に下を見るために上にスクロールさせようとして、
「▼ボタン」を押下した際、VerticalScroll.Valueの値に「3」が
入ってしまいます。
また、それ以降ボタンを押すとスクロールバーが無反応→スクロール
→無反応の繰り返しになってしまいます。(但しPanelの中身自体は
スクロールしてる・・・)
原因がわからないのでどなたか知恵をお貸し下さい。
環境はVS2005/C#/.net2.0です。宜しくお願いします。
--------------------------------------------------
public partial class Form9 : Form
{
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.TextBox textBox3;
public Form9()
{
InitializeComponent();
}
// フォームロード
private void Form9_Load(object sender, EventArgs e)
{
this.textBox2.Text += String.Format("Panel-Width:{0}\r\n", this.panel1.Width);
this.textBox2.Text += String.Format("Panel-Height:{0}\r\n", this.panel1.Height);
this.textBox2.Text += String.Format("TextBox-Width:{0}\r\n", this.textBox1.Width);
this.textBox2.Text += String.Format("TextBox-Height:{0}\r\n", this.textBox1.Height);
this.textBox2.Text += String.Format("VerticalScroll-Maximum:{0}\r\n", this.panel1.VerticalScroll.Maximum);
this.textBox2.Text += String.Format("VerticalScroll-Minimum:{0}\r\n", this.panel1.VerticalScroll.Minimum);
this.textBox2.Text += String.Format("VerticalScroll-LargeChange:{0}\r\n", this.panel1.VerticalScroll.LargeChange);
this.textBox2.Text += String.Format("VerticalScroll-SmallChange:{0}\r\n", this.panel1.VerticalScroll.SmallChange);
this.textBox2.Text += String.Format("VerticalScroll-Value:{0}\r\n", this.panel1.VerticalScroll.Value);
}
// ▼キーを押した時
private void button2_Click(object sender, EventArgs e)
{
if (this.panel1.VerticalScroll.Value + 100 <= this.panel1.VerticalScroll.Maximum)
{
this.panel1.VerticalScroll.Value += 100;
}
else
{
this.panel1.VerticalScroll.Value = this.panel1.VerticalScroll.Maximum;
}
this.textBox3.Text = this.panel1.VerticalScroll.Value.ToString();
}
// ▲キーを押した時
private void button1_Click(object sender, EventArgs e)
{
if (this.panel1.VerticalScroll.Minimum <= this.panel1.VerticalScroll.Value - 100)
{
this.panel1.VerticalScroll.Value -= 100;
}
else
{
this.panel1.VerticalScroll.Value = this.panel1.VerticalScroll.Minimum;
}
this.textBox3.Text = this.panel1.VerticalScroll.Value.ToString();
}
// 初期化
private void InitializeComponent()
{
this.panel1 = new System.Windows.Forms.Panel();
this.textBox1 = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.textBox2 = new System.Windows.Forms.TextBox();
this.textBox3 = new System.Windows.Forms.TextBox();
this.panel1.SuspendLayout();
this.SuspendLayout();
//
// panel1
//
this.panel1.AutoScroll = true;
this.panel1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.panel1.Controls.Add(this.textBox1);
this.panel1.Location = new System.Drawing.Point(12, 12);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(281, 308);
this.panel1.TabIndex = 0;
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(3, 3);
this.textBox1.Multiline = true;
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(256, 548);
this.textBox1.TabIndex = 0;
//
// button1
//
this.button1.Location = new System.Drawing.Point(77, 524);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(65, 54);
this.button1.TabIndex = 1;
this.button1.Text = "▲";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(160, 524);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(65, 54);
this.button2.TabIndex = 2;
this.button2.Text = "▼";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(12, 326);
this.textBox2.Multiline = true;
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(281, 116);
this.textBox2.TabIndex = 3;
//
// textBox3
//
this.textBox3.Location = new System.Drawing.Point(12, 461);
this.textBox3.Multiline = true;
this.textBox3.Name = "textBox3";
this.textBox3.Size = new System.Drawing.Size(281, 27);
this.textBox3.TabIndex = 4;
//
// Form9
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(306, 590);
this.Controls.Add(this.textBox3);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.panel1);
this.Name = "Form9";
this.Text = "Form9";
this.Load += new System.EventHandler(this.Form9_Load);
this.panel1.ResumeLayout(false);
this.panel1.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
|