2016-05-04 12 views
0

Ich möchte ein geerbtes Textfeld Steuerelement auf die Maus über das Formular zeigen. Aber Text wird nicht angezeigt. Unten ist mein Code.So zeigen Sie Textfeld bei Mausbewegung C#

 private ChartCalloutBox m_calloutbox = null; 
     public Form2() 
     { 
      InitializeComponent(); 
      this.MouseMove += Form2_MouseMove; 

     } 

     void Form2_MouseMove(object sender, MouseEventArgs e) 
     { 
      if (m_calloutbox == null) 
      { 
       m_calloutbox = new ChartCalloutBox(); 
      } 
      m_calloutbox.Location = e.Location; 
      m_calloutbox.Show(); 
     } 

     internal class ChartCalloutBox : TextBox 
     { 

      public ChartCalloutBox() 
      {    
       InitializeComponent(); 
      } 

      private void InitializeComponent() 
      { 
       this.SuspendLayout(); 
       this.Location = new System.Drawing.Point(350, 170); 
       this.ClientSize = new System.Drawing.Size(130, 40); 
       this.Size = new System.Drawing.Size(130, 40); 
       this.BackColor = System.Drawing.Color.Black; 
       this.ForeColor = System.Drawing.Color.Brown; 
       this.Name = "CalloutBox"; 
       this.Text = "Callout Rect"; 
       this.ResumeLayout(false); 
       // 
      } 
     } 

Irgendeine Hilfe zu diesem, wie man das Textfeld über Maus zeigt. und der Textfeldbereich sollte basierend auf der Mausposition geändert werden.

Danke, Bharathi.

Antwort

2

Fügen Sie Ihr Steuerelement zu Steuerelement-Auflistung hinzu.

sollte Code sein wie

 void Form2_MouseMove(object sender, MouseEventArgs e) 
     { 
      if (m_calloutbox == null) 
      { 
       m_calloutbox = new ChartCalloutBox(); 
       this.Controls.Add(m_calloutbox); 
      } 
      m_calloutbox.Location = e.Location; 
     } 
Verwandte Themen