2009-05-26 3 views
0

ScrollableControl (Panel 등)에 포함 된 컨트롤을 클릭 할 때 Click 이벤트 또는 기타 컨트롤 동작이 항상 발생하는 것은 아닙니다.ScrollableControl 및 이벤트의 Windows Forms 컨트롤

클릭 한 컨트롤에 포커스가없고 부분적으로 만 보이는 경우보기로 스크롤됩니다. Click 이벤트가 발생하지 않거나 다른 컨트롤 동작이 발생하지 않습니다 그러나 이것은 내가 기대하는 것입니다.

컨트롤에 이미 포커스가 있고 부분적으로 만 보이는 경우 이벤트가 시작됩니다.

체크 상자 -보기로 스크롤하면 선택 상태가 변경되지 않습니다. CheckedListBox -보기로 스크롤하면 클릭 된 항목이 선택되지 않습니다. TreeView -보기로 스크롤하면 클릭 된 노드가 선택되지 않습니다. 버튼 -보기로 스크롤하면 클릭 이벤트가 발생하지 않습니다. 등

  • 가되도록 폼의 크기를 조정,

    1. 는 클릭에 대한 이벤트 처리기를 추가 패널
    2. 에 위의 컨트롤 중 하나를 추가, SelectedItemChanged :

      는 다음을 수행 할 수 있습니다이 문제를 재현하려면 스크롤바가 패널에 표시됩니다.
    3. 컨트롤 중 하나가 부분적으로 표시되도록 패널을 스크롤하십시오.
    4. 부분적으로 보이는 컨트롤
    5. 을 클릭하십시오.

    이벤트가 해지 될 수있는 방법이 있습니까?

  • 답변

    0

    David,

    그것은 나를 위해 일했습니다. Form1.designer.cs입니다에서

    코드 :

    namespace WindowsFormsApplication1 
    { 
        partial class Form1 
        { 
         /// <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.textBox2 = new System.Windows.Forms.TextBox(); 
          this.textBox1 = new System.Windows.Forms.TextBox(); 
          this.panel1.SuspendLayout(); 
          this.SuspendLayout(); 
          // 
          // panel1 
          // 
          this.panel1.AutoScroll = true; 
          this.panel1.Controls.Add(this.textBox2); 
          this.panel1.Controls.Add(this.textBox1); 
          this.panel1.Location = new System.Drawing.Point(86, 75); 
          this.panel1.Name = "panel1"; 
          this.panel1.Size = new System.Drawing.Size(176, 70); 
          this.panel1.TabIndex = 0; 
          // 
          // textBox2 
          // 
          this.textBox2.Location = new System.Drawing.Point(109, 17); 
          this.textBox2.Name = "textBox2"; 
          this.textBox2.Size = new System.Drawing.Size(100, 20); 
          this.textBox2.TabIndex = 1; 
          this.textBox2.Click += new System.EventHandler(this.textBox2_Click); 
          // 
          // textBox1 
          // 
          this.textBox1.Location = new System.Drawing.Point(3, 17); 
          this.textBox1.Name = "textBox1"; 
          this.textBox1.Size = new System.Drawing.Size(100, 20); 
          this.textBox1.TabIndex = 0; 
          this.textBox1.Click += new System.EventHandler(this.textBox1_Click); 
          // 
          // Form1 
          // 
          this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 
          this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 
          this.ClientSize = new System.Drawing.Size(493, 271); 
          this.Controls.Add(this.panel1); 
          this.Name = "Form1"; 
          this.Text = "Form1"; 
          this.panel1.ResumeLayout(false); 
          this.panel1.PerformLayout(); 
          this.ResumeLayout(false); 
    
         } 
    
         #endregion 
    
         private System.Windows.Forms.Panel panel1; 
         private System.Windows.Forms.TextBox textBox2; 
         private System.Windows.Forms.TextBox textBox1; 
        } 
    } 
    

    코드 에서 Form1.cs의 :

    using System; 
    using System.Collections.Generic; 
    using System.ComponentModel; 
    using System.Data; 
    using System.Drawing; 
    using System.Linq; 
    using System.Text; 
    using System.Windows.Forms; 
    
    namespace WindowsFormsApplication1 
    { 
        public partial class Form1 : Form 
        { 
         public Form1() 
         { 
          InitializeComponent(); 
         } 
    
         private void textBox1_Click(object sender, EventArgs e) 
         { 
          MessageBox.Show("Click1"); 
         } 
    
         private void textBox2_Click(object sender, EventArgs e) 
         { 
          MessageBox.Show("Click2"); 
         } 
        } 
    } 
    
    관련 문제