日期:2014-05-18  浏览次数:20787 次

Panel的滚动条出现焦点问题[.NET2.0]
Panel里放了一个比较大的控件使Panel出现滚动条。且Panel里的控件可以有输入焦点,如(ListBox)。

问题出现的操作步骤:
1.将Panel的滚动条拖到下面。
2.点一下同Form的其他控件,使Panel里的控件没有焦点。
3.点击Panel里的控件,使其获得焦点。问题出现:这时Panel的滚动条会跳回到初始处。

请问这个问题怎么解决?大家遇到过吗?

C# code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

public partial class TestForm : Form
{

    static public void Main()
    {
        Application.Run(new TestForm());
    }

    public TestForm()
    {
        InitializeComponent();
    }

    private System.Windows.Forms.Panel panel1;
    private System.Windows.Forms.TextBox textBox2;
    private System.Windows.Forms.TextBox textBox1;

    private void InitializeComponent()
    {
        this.panel1 = new System.Windows.Forms.Panel();
        this.textBox1 = new System.Windows.Forms.TextBox();
        this.textBox2 = 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.textBox2);
        this.panel1.Location = new System.Drawing.Point(22, 35);
        this.panel1.Name = "panel1";
        this.panel1.Size = new System.Drawing.Size(138, 193);
        this.panel1.TabIndex = 0;
        // 
        // textBox1
        // 
        this.textBox1.Location = new System.Drawing.Point(180, 62);
        this.textBox1.Name = "textBox1";
        this.textBox1.Size = new System.Drawing.Size(100, 21);
        this.textBox1.TabIndex = 1;
        // 
        // textBox2
        // 
        this.textBox2.Location = new System.Drawing.Point(16, 12);
        this.textBox2.Multiline = true;
        this.textBox2.Name = "textBox2";
        this.textBox2.Size = new System.Drawing.Size(148, 255);
        this.textBox2.TabIndex = 0;
        this.textBox2.Text = "\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n";
        // 
        // TestForm
        // 
        this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.ClientSize = new System.Drawing.Size(292, 266);
        this.Controls.Add(this.textBox1);
        this.Controls.Add(this.panel1);
        this.Name = "TestForm";
        this.Text = "TestForm";
        this.panel1.ResumeLayout(false);
        this.panel1.PerformLayout();
        this.ResumeLayout(false);
        this.PerformLayout();

    }
}


------解决方案--------------------
up
------解决方案--------------------
是这样子的!