本文介绍了DatagridView Cell Paint Graphics DrawLine方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





这是Form1代码

Hi,

This is Form1 Code

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 Datagridview__Cell_Paint
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            dataGridView1.RowCount = 5;
        }


        private void addColorToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form2 f2 = new Form2();
            f2.ShowDialog();
        }

        private void dataGridView1_CellMouseUp(object sender, DataGridViewCellMouseEventArgs e)
        {
             if (e.RowIndex != -1 && e.ColumnIndex != -1)
            {
            if (e.Button == MouseButtons.Right)
                {
                DataGridViewRow clickedRow = (sender as DataGridView).Rows[e.RowIndex];
                if (!clickedRow.Selected)
                    dataGridView1.CurrentCell = clickedRow.Cells[e.ColumnIndex];
                }
            }
        }
    }
}



Form2 code Here


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 Datagridview__Cell_Paint
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }
        private void panel4_Paint(object sender, PaintEventArgs e)
        {
            Pen graphPen = new Pen(Color.White, 20);
            PointF pt1D = new PointF();
            PointF pt2D = new PointF();
            pt1D.X = 5;
            pt1D.Y = 20;
            pt2D.X = 175;
            pt2D.Y = 20;

            e.Graphics.DrawLine(graphPen, pt1D, pt2D);

        }

        private void panel4_Click(object sender, EventArgs e)
        {
            System.Drawing.Graphics graphicsObj;
            graphicsObj = panel2.CreateGraphics();
            Pen graphPen = new Pen(panel1.BackColor, 20);
            graphicsObj.DrawLine(graphPen, 5, 20, 175, 20);

        }

        private void panel1_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                ColorDialog cd = new ColorDialog();
                if (cd.ShowDialog() == DialogResult.OK)
                {
                    this.panel1.BackColor = cd.Color;
                }
            }
        }
    }
}



如果我右键单击datagridview cell form2打开.i选择颜色使用右键单击panel1 eg.red color.then我点击panel2 panel1颜色显示panel2红色(panel2 iam使用油漆和点击事件图形Drawline方法



之后如果我点击添加到form1按钮点击它将显示panel2 DrawLine红色显示到form1 datagridview单元格。



我也附上了我的项目文件.plz ref并帮助我们。

http://www.mediafire.com/download/8bdn8asb82ht12r/Datagridview__Cell_Paint.rar



Rgds


if i right click on datagridview cell form2 is open.i selected color using right click on panel1 eg.red color.then i click on panel2 panel1 color is shown panel2 red color(panel2 iam using paint and click event graphics Drawline method

after this if i click Add to form1 button click it shold be shown panel2 DrawLine red color show to form1 datagridview cell.

also i attached my project file also.plz ref and help us.
http://www.mediafire.com/download/8bdn8asb82ht12r/Datagridview__Cell_Paint.rar

Rgds

推荐答案


这篇关于DatagridView Cell Paint Graphics DrawLine方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 13:24
查看更多