在文本框單元中添加了一個小的按鈕

        private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
        
{
            
if (e.Control is DataGridViewTextBoxEditingControl)
            
{
                Button btn 
= new Button();
                btn.Height 
= e.Control.Height;
                btn.Width 
= e.Control.Width / 6;
                btn.Top 
= 0;
                btn.Left 
= e.Control.Width - btn.Width;
                btn.Cursor 
= Cursors.Default;
                btn.Click 
+= new EventHandler(btn_Click);
                btn.Dock 
= DockStyle.Right;
                textbox.Controls.Clear();
                textbox.Controls.Add(btn);
            }

        }


        
void btn_Click(object sender, EventArgs e)
        
{
            Form f 
= new Form();
            f.StartPosition 
= FormStartPosition.Manual;
            Button btn 
= sender as Button;
            Rectangle bound 
= btn.Parent.RectangleToScreen(btn.Bounds);
            f.Location 
= new Point(bound.Left, bound.Height + bound.Top);
            f.Show(
this);
        }

 剛纔瀏覽論壇時發現某小強回覆別人問題的答案,感覺不錯 記錄一下 以備不時之需

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章