Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > บทความจากสมาชิก > การสร้าง Textbox และ Button อยู่รวมกันใน DataGridView (Windows Form App)



 
Clound SSD Virtual Server

การสร้าง Textbox และ Button อยู่รวมกันใน DataGridView (Windows Form App)

การสร้าง Textbox และ Button อยู่รวมกันใน DataGridView (Windows Form App) โดย VB.net การสร้าง Textbox และ Button อยู่รวมกันใน DataGridview โดยสามารถทำการคลิกปุ่ม Button เพื่อทำคำสั่งต่างๆ ที่เราต้องการได้

รายละเอียด

1.สร้าง From ใหม่ขึ้นมา 1 From แล้วน้ำ DataGridview มาวางไว้ Add คอลัมภ์มาซัก 2 อันก็ได้

โดยกำหนด Column Type เป็น DataGridViewTextBoxColumn

qq


2. ทำการสร้าง Folder ไว้ชื่อ pic ไว้ใน Folder bin ของโปรแกรมแล้วนำรูปมาวางไว้

12

ดับเบิลคลิกที่ From

วาง Code ไว้ตรง ล่าง Class ก่อน Public Class Form1

Code (VB.NET)
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Windows.Forms
Public Class Form1
    Private btnSelector As New Button()
    'สร้าง Buttnon
    Private pCase As Integer
    'สำหรับ เก็บส่วนของการเลือก Column

    Private Sub SelectorClick(ByVal sender As Object, ByVal e As EventArgs)
        Select Case pCase
            Case 1
                'value from dataGridView1_CellEnter
                If True Then
                    MessageBox.Show("Show Dialog here!!")
                    Exit Select
                End If
        End Select
    End Sub

    Private Sub CreateButton(ByRef myButton As Button)
        myButton.FlatStyle = FlatStyle.Flat
        myButton.FlatAppearance.BorderSize = 0
        myButton.Size = New Size(30, 19)
        myButton.ImageAlign = ContentAlignment.MiddleCenter
        myButton.FlatAppearance.MouseDownBackColor = Color.Transparent
        myButton.FlatAppearance.MouseOverBackColor = Color.Transparent
        myButton.BackColor = Color.Transparent
        'myButton.Image = Properties.resources.search3
        myButton.Image = Image.FromFile(CurDir() + "\pic\SearchBc.png")

        'กำหนดรูปภาพ
        myButton.Hide()
        AddHandler myButton.Click, New EventHandler(AddressOf Me.SelectorClick)
        '--------------------------------------------
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        CreateButton(btnSelector)
        DataGridView1.Controls.Add(btnSelector)
    End Sub

    Private Sub DataGridView1_CellEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellEnter
        If DataGridView1.Columns(e.ColumnIndex).Name = "Column1" Then
            pCase = 1
            Dim Loc As Rectangle = DataGridView1.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, False)
            Dim Wid As Integer = DataGridView1.CurrentCell.Size.Width
            btnSelector.Location = New Point(Loc.X - 25 + Wid, Loc.Y)
            btnSelector.Show()
        End If
    End Sub

    Private Sub DataGridView1_CellLeave(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellLeave
        If btnSelector.Focused <> True Then
            btnSelector.Hide()
        End If

    End Sub
End Class

Result

wq

ทำการรันโปรแกรมได้เลย

for C#
using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
public class Form1
{
	private Button btnSelector = new Button();
	//สร้าง Buttnon
	private int pCase;
	//สำหรับ เก็บส่วนของการเลือก Column

	private void SelectorClick(object sender, EventArgs e)
	{
		switch (pCase) {
			case 1:
				//value from dataGridView1_CellEnter
				if (true) {
					MessageBox.Show("Show Dialog here!!");
					break; // TODO: might not be correct. Was : Exit Select
				}
				break;
		}
	}

	private void CreateButton(ref Button myButton)
	{
		myButton.FlatStyle = FlatStyle.Flat;
		myButton.FlatAppearance.BorderSize = 0;
		myButton.Size = new Size(30, 19);
		myButton.ImageAlign = ContentAlignment.MiddleCenter;
		myButton.FlatAppearance.MouseDownBackColor = Color.Transparent;
		myButton.FlatAppearance.MouseOverBackColor = Color.Transparent;
		myButton.BackColor = Color.Transparent;
		//myButton.Image = Properties.resources.search3
		myButton.Image = Image.FromFile(FileSystem.CurDir() + "\\pic\\SearchBc.png");

		//กำหนดรูปภาพ
		myButton.Hide();
		myButton.Click += new EventHandler(this.SelectorClick);
		//--------------------------------------------
	}

	private void Form1_Load(System.Object sender, System.EventArgs e)
	{
		CreateButton(ref btnSelector);
		DataGridView1.Controls.Add(btnSelector);
	}

	private void DataGridView1_CellEnter(object sender, System.Windows.Forms.DataGridViewCellEventArgs e)
	{
		if (DataGridView1.Columns(e.ColumnIndex).Name == "Column1") {
			pCase = 1;
			Rectangle Loc = DataGridView1.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, false);
			int Wid = DataGridView1.CurrentCell.Size.Width;
			btnSelector.Location = new Point(Loc.X - 25 + Wid, Loc.Y);
			btnSelector.Show();
		}
	}

	private void DataGridView1_CellLeave(object sender, System.Windows.Forms.DataGridViewCellEventArgs e)
	{
		if (btnSelector.Focused != true) {
			btnSelector.Hide();
		}

	}
}







   
Share
Bookmark.   

  By : QC_C0M
  Article : บทความเป็นการเขียนโดยสมาชิก หากมีปัญหาเรื่องลิขสิทธิ์ กรุณาแจ้งให้ทาง webmaster ทราบด้วยครับ
  Score Rating :
  Create Date : 2015-11-09
  Download : No files
Sponsored Links
ThaiCreate.Com Forum


Comunity Forum Free Web Script
Jobs Freelance Free Uploads
Free Web Hosting Free Tools

สอน PHP ผ่าน Youtube ฟรี
สอน Android การเขียนโปรแกรม Android
สอน Windows Phone การเขียนโปรแกรม Windows Phone 7 และ 8
สอน iOS การเขียนโปรแกรม iPhone, iPad
สอน Java การเขียนโปรแกรม ภาษา Java
สอน Java GUI การเขียนโปรแกรม ภาษา Java GUI
สอน JSP การเขียนโปรแกรม ภาษา Java
สอน jQuery การเขียนโปรแกรม ภาษา jQuery
สอน .Net การเขียนโปรแกรม ภาษา .Net
Free Tutorial
สอน Google Maps Api
สอน Windows Service
สอน Entity Framework
สอน Android
สอน Java เขียน Java
Java GUI Swing
สอน JSP (Web App)
iOS (iPhone,iPad)
Windows Phone
Windows Azure
Windows Store
Laravel Framework
Yii PHP Framework
สอน jQuery
สอน jQuery กับ Ajax
สอน PHP OOP (Vdo)
Ajax Tutorials
SQL Tutorials
สอน SQL (Part 2)
JavaScript Tutorial
Javascript Tips
VBScript Tutorial
VBScript Validation
Microsoft Access
MySQL Tutorials
-- Stored Procedure
MariaDB Database
SQL Server Tutorial
SQL Server 2005
SQL Server 2008
SQL Server 2012
-- Stored Procedure
Oracle Database
-- Stored Procedure
SVN (Subversion)
แนวทางการทำ SEO
ปรับแต่งเว็บให้โหลดเร็ว


Hit Link
   







Load balance : Server 05
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่