2009-05-26 5 views
0

Ich habe festgestellt, dass das Click-Ereignis oder ein anderes Steuerelement Verhalten nicht immer ausgelöst wird, wenn auf ein Steuerelement in einem ScrollableControl (Panel usw.) geklickt wird.Windows Forms-Steuerelemente in einem scrollbaren Steuerelement und Ereignisse

Wenn das angeklickte Steuerelement nicht den Fokus hat und nur teilweise sichtbar ist, wird es in den Bildlauf gescrollt. Dies ist, was ich erwarte, aber das Click-Ereignis wird nicht ausgelöst oder anderes Steuerelement Verhalten tritt nicht auf.

Wenn das Steuerelement bereits den Fokus hat und nur teilweise sichtbar ist, werden die Ereignisse ausgelöst.

Kontrollkästchen - Scrollt in Ansicht, der überprüfte Status ändert sich nicht. CheckedListBox - Scrollt in die Ansicht, das angeklickte Objekt wird nicht ausgewählt. TreeView - Scrollt in die Ansicht, der angeklickte Knoten wird nicht ausgewählt. Schaltfläche - Scrollt in Ansicht, Click-Ereignis wird nicht ausgelöst.

Um dies zu reproduzieren können Sie folgendes tun:

  1. zu einem -Panel
  2. hinzu Klicken Sie auf einen Ereignishandler eine der oben genannten Kontrollen hinzufügen, SelectedItemChanged, etc
  3. das Formular Größe ändern, so dass Bildlaufleisten sind auf dem Panel sichtbar
  4. Scrollen Sie das Panel, so dass eine der Bedienelemente teilweise sichtbar ist
  5. Klicken Sie auf das teilweise sichtbare Steuerelement

Gibt es eine Möglichkeit sicherzustellen, dass die Ereignisse ausgelöst werden?

Antwort

0

David,

Es funktionierte für mich.

-Code in 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; 
    } 
} 

-Code in 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"); 
     } 
    } 
} 
Verwandte Themen